-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move logic to effect for login status component
- Loading branch information
Showing
2 changed files
with
42 additions
and
35 deletions.
There are no files selected for viewing
37 changes: 2 additions & 35 deletions
37
libs/dsb-client-gateway/ui/login/src/lib/LoginStatus/LoginStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...b-client-gateway/ui/login/src/lib/LoginStatus/RequestingEnrolment/LoginStatus.effects.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { usePrivateKey } from '../../Login.effects'; | ||
import { AccountStatusEnum } from '../../check-account-status/check-account-status'; | ||
import LoginForm from '../../LoginForm/LoginForm'; | ||
import InsufficientFund from '../InsufficientFund/InsufficientFund'; | ||
import { RoleStatus } from '@dsb-client-gateway/dsb-client-gateway/identity/models'; | ||
import EnrolForRoleContainer from '../EnrolForRoleContainer/EnrolForRoleContainer'; | ||
import RequestingEnrolment from './RequestingEnrolment'; | ||
import AwaitingSyncing from '../AwaitingSyncing/AwaitingSyncing'; | ||
import ResetPrivateKey from '../../ResetPrivateKey/ResetPrivateKey'; | ||
|
||
export const useLoginStatus = () => { | ||
const {isLoading, submit, status} = usePrivateKey(); | ||
|
||
const privateKeyHandler = (privateKey: string) => { | ||
submit(privateKey); | ||
}; | ||
|
||
const statusFactory = () => { | ||
switch (status) { | ||
case AccountStatusEnum.NotSetPrivateKey: | ||
return <LoginForm onPrivateKeySubmit={privateKeyHandler} />; | ||
case AccountStatusEnum.InsufficientFund: | ||
return <InsufficientFund/>; | ||
case RoleStatus.NOT_ENROLLED: | ||
return <EnrolForRoleContainer/>; | ||
case RoleStatus.AWAITING_APPROVAL: | ||
return <RequestingEnrolment/>; | ||
case RoleStatus.APPROVED: | ||
return <AwaitingSyncing/>; | ||
default: | ||
return ( | ||
<> | ||
<div>Ops! Something went wrong!</div> | ||
<ResetPrivateKey/> | ||
</>); | ||
} | ||
}; | ||
|
||
return {statusFactory, isLoading} | ||
} |