Skip to content

Commit 10e7a66

Browse files
authored
Merge pull request #940 from topcoder-platform/qa
New DICE
2 parents ebf0f7f + 0802669 commit 10e7a66

File tree

12 files changed

+130
-186
lines changed

12 files changed

+130
-186
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,5 +246,9 @@
246246
}
247247
}
248248
]
249+
},
250+
"volta": {
251+
"node": "16.15.0",
252+
"yarn": "1.22.19"
249253
}
250254
}
46.1 KB
Loading
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { ReactComponent as MFAImage } from './mfa.svg'
22
import { ReactComponent as AppleStore } from './apple-store.svg'
3-
import { ReactComponent as UnSuccessfullDiceVerificationIcon } from './unsuccessful.svg'
3+
import credentialImage from './credential.png'
44
import diceIdLogo from './dicelogo.png'
55
import diceIdLogoBig from './dicelogobig.png'
66
import diceIdLogoSmall from './dicelogosmall.png'
77
import googlePlay from './google-play.png'
88

99
export {
1010
AppleStore,
11+
credentialImage,
1112
diceIdLogo,
1213
diceIdLogoBig,
1314
diceIdLogoSmall,
1415
googlePlay,
1516
MFAImage,
16-
UnSuccessfullDiceVerificationIcon,
1717
}

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

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react'
22
import { toast } from 'react-toastify'
33
import { KeyedMutator } from 'swr'
4-
import { noop } from 'lodash'
54

6-
import { Button, Collapsible, FormToggleSwitch, IconSolid, Tooltip } from '~/libs/ui'
5+
import { Button, Collapsible, FormToggleSwitch } from '~/libs/ui'
76
import { diceIdLogo, MFAImage, SettingSection, triggerSurvey } from '~/apps/accounts/src/lib'
87
import { MemberMFAStatus, updateMemberMFAStatusAsync, useMemberMFAStatus, UserProfile } from '~/libs/core'
98

@@ -23,10 +22,12 @@ const Security: FC<SecurityProps> = (props: SecurityProps) => {
2322
} = useMemberMFAStatus(props.profile.userId)
2423

2524
const [mfaEnabled, setMFAEnabled]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)
25+
const [diceEnabled, setDiceEnabled]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)
2626

2727
useEffect(() => {
2828
if (mfaStatusData) {
2929
setMFAEnabled(mfaStatusData.mfaEnabled)
30+
setDiceEnabled(mfaStatusData.diceEnabled)
3031
}
3132
}, [mfaStatusData])
3233

@@ -36,8 +37,9 @@ const Security: FC<SecurityProps> = (props: SecurityProps) => {
3637
mfaEnabled: !mfaEnabled,
3738
},
3839
})
39-
.then(() => {
40-
setMFAEnabled(!mfaEnabled)
40+
.then(response => {
41+
setMFAEnabled(response.result.content.mfaEnabled)
42+
setDiceEnabled(response.result.content.diceEnabled)
4143
toast.success('Your Multi Factor Authentication (MFA) status was updated.')
4244
triggerSurvey()
4345
})
@@ -46,6 +48,27 @@ const Security: FC<SecurityProps> = (props: SecurityProps) => {
4648
})
4749
}
4850

51+
function handleUserDiceChange(): void {
52+
if (!diceEnabled) {
53+
return
54+
}
55+
56+
updateMemberMFAStatusAsync(props.profile.userId, {
57+
param: {
58+
diceEnabled: !diceEnabled,
59+
},
60+
})
61+
.then(response => {
62+
setMFAEnabled(response.result.content.mfaEnabled)
63+
setDiceEnabled(response.result.content.diceEnabled)
64+
toast.success('Your DICE credential was disabled.')
65+
triggerSurvey()
66+
})
67+
.catch(() => {
68+
toast.error('Something went wrong. Please try again later.')
69+
})
70+
}
71+
4972
function handleDiceModalStatus(): void {
5073
setSetupDiceModalOpen(!setupDiceModalOpen)
5174
}
@@ -70,7 +93,6 @@ const Security: FC<SecurityProps> = (props: SecurityProps) => {
7093
name='mfaStatus'
7194
onChange={handleUserMFAChange}
7295
value={mfaEnabled}
73-
disabled={mfaStatusData?.diceEnabled}
7496
/>
7597
)}
7698
/>
@@ -86,12 +108,11 @@ const Security: FC<SecurityProps> = (props: SecurityProps) => {
86108
actionElement={(
87109
<div className={styles.diceBtnWrap}>
88110
{
89-
mfaStatusData?.diceEnabled ? (
111+
diceEnabled ? (
90112
<FormToggleSwitch
91113
name='diceEnabled'
92-
onChange={noop}
114+
onChange={handleUserDiceChange}
93115
value={mfaStatusData?.diceEnabled as boolean}
94-
disabled={mfaStatusData?.diceEnabled}
95116
/>
96117
) : (
97118
<Button
@@ -104,15 +125,6 @@ const Security: FC<SecurityProps> = (props: SecurityProps) => {
104125
/>
105126
)
106127
}
107-
{
108-
mfaStatusData?.diceEnabled && (
109-
<Tooltip
110-
content='Please reach out to support@topcoder.com for deactivating Dice ID.'
111-
>
112-
<IconSolid.InformationCircleIcon />
113-
</Tooltip>
114-
)
115-
}
116128
</div>
117129
)}
118130
/>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { FC, useEffect } from 'react'
2+
3+
import { DiceConnectionStatus, useDiceIdConnection } from '~/libs/core'
4+
5+
interface ConnectionHandlerProps {
6+
onChange: (newStatus: DiceConnectionStatus) => void;
7+
userId: number;
8+
}
9+
10+
export const ConnectionHandler: FC<ConnectionHandlerProps> = (
11+
props: ConnectionHandlerProps,
12+
) => {
13+
const diceConnection: DiceConnectionStatus | undefined = useDiceIdConnection(props.userId)
14+
15+
useEffect(() => {
16+
if (diceConnection) {
17+
props.onChange(diceConnection)
18+
}
19+
}, [diceConnection, props])
20+
21+
return (
22+
<></>
23+
)
24+
}

src/apps/accounts/src/settings/tabs/account/security/dice-setup-modal/DiceSetupModal.module.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
margin: auto;
3535
}
3636

37+
.credentialImage {
38+
height: 280px;
39+
width: 400px;
40+
align-self: center;
41+
}
42+
3743
.diceBigLogo {
3844
margin: $sp-4 0;
3945
}

0 commit comments

Comments
 (0)