Skip to content

Commit ba29416

Browse files
committed
MP-40 account security init
1 parent 95d9e4a commit ba29416

File tree

20 files changed

+460
-20
lines changed

20 files changed

+460
-20
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { ReactComponent as MFAImage } from './mfa.svg'
2+
import { ReactComponent as AppleStore } from './apple-store.svg'
23
import diceIdLogo from './dicelogo.png'
4+
import diceIdLogoBig from './dicelogobig.png'
5+
import googlePlay from './google-play.png'
36

47
export {
8+
AppleStore,
59
diceIdLogo,
10+
diceIdLogoBig,
11+
googlePlay,
612
MFAImage,
713
}

src/apps/accounts/src/settings/tabs/account/AccountTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const AccountTab: FC<AccountTabProps> = (props: AccountTabProps) => (
1919

2020
<UserAndPassword profile={props.profile} />
2121

22-
<SecuritySection />
22+
<SecuritySection profile={props.profile} />
2323
</div>
2424
)
2525

src/apps/accounts/src/settings/tabs/account/security/Security.tsx

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
1-
import { Dispatch, FC, SetStateAction, useState } from 'react'
1+
import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react'
2+
import { toast } from 'react-toastify'
23

34
import { Button, Collapsible, FormToggleSwitch } from '~/libs/ui'
45
import { diceIdLogo, MFAImage, SettingSection } from '~/apps/accounts/src/lib'
6+
import { MemberMFAStatus, updateMemberMFAStatusAsync, useMemberMFAStatus, UserProfile } from '~/libs/core'
57

68
import { DiceSetupModal } from './dice-setup-modal'
79
import styles from './Security.module.scss'
810

9-
const Security: FC<{}> = () => {
10-
const [mfaStatus, setMFAStatus]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)
11+
interface SecurityProps {
12+
profile: UserProfile
13+
}
14+
15+
const Security: FC<SecurityProps> = (props: SecurityProps) => {
1116
const [setupDiceModalOpen, setSetupDiceModalOpen]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)
1217

13-
function handleUserMFAChange(event: any): void {
14-
console.log('handleUserMFAChange', event)
15-
setMFAStatus(!mfaStatus)
18+
const mfaStatusData: MemberMFAStatus | undefined = useMemberMFAStatus(props.profile.userId)
19+
20+
const [mfaEnabled, setMFAEnabled]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)
21+
22+
useEffect(() => {
23+
if (mfaStatusData) {
24+
setMFAEnabled(mfaStatusData.mfaEnabled)
25+
}
26+
}, [mfaStatusData])
27+
28+
function handleUserMFAChange(): void {
29+
updateMemberMFAStatusAsync(props.profile.userId, {
30+
param: {
31+
mfaEnabled: !mfaEnabled,
32+
},
33+
})
34+
.then(() => {
35+
setMFAEnabled(!mfaEnabled)
36+
toast.success('Your Multi Factor Authentication (MFA) status was updated.')
37+
})
38+
.catch(() => {
39+
toast.error('Something went wrong. Please try again later.')
40+
})
1641
}
1742

1843
function handleDiceModalStatus(): void {
@@ -38,7 +63,8 @@ const Security: FC<{}> = () => {
3863
<FormToggleSwitch
3964
name='mfaStatus'
4065
onChange={handleUserMFAChange}
41-
value={mfaStatus}
66+
value={mfaEnabled}
67+
disabled={mfaStatusData?.diceEnabled}
4268
/>
4369
)}
4470
/>
@@ -58,13 +84,15 @@ const Security: FC<{}> = () => {
5884
size='lg'
5985
className={styles.diceIdButton}
6086
onClick={handleDiceModalStatus}
87+
disabled={!mfaEnabled || mfaStatusData?.diceEnabled}
6188
/>
6289
)}
6390
/>
6491

6592
{setupDiceModalOpen && (
6693
<DiceSetupModal
6794
onClose={handleDiceModalStatus}
95+
profile={props.profile}
6896
/>
6997
)}
7098
</Collapsible>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@import '@libs/ui/styles/includes';
2+
3+
.diceModal {
4+
:global(.react-responsive-modal-closeButton) {
5+
display: flex;
6+
}
7+
8+
.appSoresWrap {
9+
display: flex;
10+
justify-content: space-evenly;
11+
margin: $sp-4 0;
12+
13+
.appStoreCard {
14+
display: flex;
15+
flex-direction: column;
16+
align-items: center;
17+
}
18+
}
19+
20+
.qrCode {
21+
margin: auto;
22+
}
23+
24+
.ctaButtons {
25+
display: flex;
26+
justify-content: space-between;
27+
width: 100%;
28+
flex: 1;
29+
}
30+
}

0 commit comments

Comments
 (0)