Skip to content

Commit

Permalink
Merge branch 'feat/nric-opt-in-out' into staging-alt2
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin9foong committed Aug 7, 2024
2 parents 6ec94cf + 47d8e7a commit 83f9c05
Show file tree
Hide file tree
Showing 29 changed files with 867 additions and 371 deletions.
13 changes: 3 additions & 10 deletions frontend/src/features/admin-form/common/AdminViewFormService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import {
filterHiddenInputs,
} from '~features/public-form/utils'

import {
PREVIEW_MASKED_MOCK_UINFIN,
PREVIEW_MOCK_UINFIN,
} from '../preview/constants'
import { PREVIEW_MOCK_UINFIN } from '../preview/constants'

// endpoint exported for testing
export const ADMIN_FORM_ENDPOINT = '/admin/forms'
Expand Down Expand Up @@ -62,9 +59,7 @@ export const previewForm = async (
// and if server has not already sent back a mock authenticated state.
if (data.form.authType !== FormAuthType.NIL && !data.spcpSession) {
data.spcpSession = {
userName: data.form.isNricMaskEnabled
? PREVIEW_MASKED_MOCK_UINFIN
: PREVIEW_MOCK_UINFIN,
userName: PREVIEW_MOCK_UINFIN,
}
}

Expand Down Expand Up @@ -95,9 +90,7 @@ export const viewFormTemplate = async (
// and if server has not already sent back a mock authenticated state.
if (data.form.authType !== FormAuthType.NIL && !data.spcpSession) {
data.spcpSession = {
userName: data.form.isNricMaskEnabled
? PREVIEW_MASKED_MOCK_UINFIN
: PREVIEW_MOCK_UINFIN,
userName: PREVIEW_MOCK_UINFIN,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { FormAuthType, FormLogoState, FormStartPage } from '~shared/types'

import { useIsMobile } from '~hooks/useIsMobile'

import {
PREVIEW_MASKED_MOCK_UINFIN as PREVIEW_MASKED_MOCK_UINFIN,
PREVIEW_MOCK_UINFIN,
} from '~features/admin-form/preview/constants'
import { PREVIEW_MOCK_UINFIN } from '~features/admin-form/preview/constants'
import { useEnv } from '~features/env/queries'
import { FormInstructions } from '~features/public-form/components/FormInstructions/FormInstructions'
import {
Expand Down Expand Up @@ -200,9 +197,7 @@ export const StartPageView = () => {
showHeader
loggedInId={
form && form.authType !== FormAuthType.NIL
? form.isNricMaskEnabled
? PREVIEW_MASKED_MOCK_UINFIN
: PREVIEW_MOCK_UINFIN
? PREVIEW_MOCK_UINFIN
: undefined
}
{...formHeaderProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import { PaymentsThankYouSvgr } from '~components/FormEndPage/PaymentsThankYouSv
import { ThankYouSvgr } from '~components/FormEndPage/ThankYouSvgr'

import { useAdminForm } from '~features/admin-form/common/queries'
import {
PREVIEW_MASKED_MOCK_UINFIN,
PREVIEW_MOCK_UINFIN,
} from '~features/admin-form/preview/constants'
import { PREVIEW_MOCK_UINFIN } from '~features/admin-form/preview/constants'
import { useEnv } from '~features/env/queries'
import {
FormBannerLogo,
Expand Down Expand Up @@ -93,9 +90,7 @@ export const EndPageContent = (): JSX.Element => {
onLogout={undefined}
loggedInId={
form && form.authType !== FormAuthType.NIL
? form.isNricMaskEnabled
? PREVIEW_MASKED_MOCK_UINFIN
: PREVIEW_MOCK_UINFIN
? PREVIEW_MOCK_UINFIN
: undefined
}
/>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/features/admin-form/preview/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const PREVIEW_MOCK_UINFIN = 'S1234567A'
export const PREVIEW_MASKED_MOCK_UINFIN = '*****567A'
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ PublicStorageNilAuthForm.parameters = {
}),
}

// purpose: tests that isNricMaskEnabled should not affect setting options available
export const PublicStorageNilAuthFormNricMaskingEnabled = Template.bind({})
PublicStorageNilAuthFormNricMaskingEnabled.parameters = {
export const PublicStorageNilAuthFormSubmitterIdCollectionEnabled =
Template.bind({})
PublicStorageNilAuthFormSubmitterIdCollectionEnabled.parameters = {
msw: buildEncryptModeMswRoutes({
responseMode: FormResponseMode.Encrypt,
status: FormStatus.Public,
isNricMaskEnabled: true,
isSubmitterIdCollectionEnabled: true,
}),
}

Expand Down Expand Up @@ -143,22 +143,25 @@ PublicEmailMyInfoForm.parameters = {
],
}

export const PrivateEmailSingpassFormNricMaskingEnabled = Template.bind({})
PrivateEmailSingpassFormNricMaskingEnabled.parameters = {
export const PrivateEmailSingpassFormSubmitterIdCollectionEnabled =
Template.bind({})
PrivateEmailSingpassFormSubmitterIdCollectionEnabled.parameters = {
msw: buildEmailModeMswRoutes({
status: FormStatus.Private,
authType: FormAuthType.SGID,
isNricMaskEnabled: true,
isSubmitterIdCollectionEnabled: true,
}),
}
export const PrivateEmailMyInfoFormNricMaskingEnabled = Template.bind({})
PrivateEmailMyInfoFormNricMaskingEnabled.parameters = {
export const PrivateEmailMyInfoFormSubmitterIdCollectionEnabled = Template.bind(
{},
)
PrivateEmailMyInfoFormSubmitterIdCollectionEnabled.parameters = {
msw: [
...buildEmailModeMswRoutes({
status: FormStatus.Private,
authType: FormAuthType.MyInfo,
esrvcId: 'STORYBOOK-TEST',
isNricMaskEnabled: true,
isSubmitterIdCollectionEnabled: true,
}),
...createFormBuilderMocks({ form_fields: MOCK_FORM_FIELDS_WITH_MYINFO }),
],
Expand All @@ -180,7 +183,7 @@ PrivateStorageSingpassFormAllTogglesEnabled.parameters = {
status: FormStatus.Private,
authType: FormAuthType.SGID,
isSingleSubmission: true,
isNricMaskEnabled: true,
isSubmitterIdCollectionEnabled: true,
}),
}

Expand All @@ -190,7 +193,7 @@ PublicEmailCorppassAllTogglesEnabledForm.parameters = {
status: FormStatus.Public,
authType: FormAuthType.CP,
isSingleSubmission: true,
isNricMaskEnabled: true,
isSubmitterIdCollectionEnabled: true,
}),
}

Expand Down
9 changes: 4 additions & 5 deletions frontend/src/features/admin-form/settings/SettingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,11 @@ export const updateFormAuthType: UpdateFormFn<'authType'> = async (
return updateFormSettings(formId, { authType: newAuthType })
}

export const updateFormNricMask: UpdateFormFn<'isNricMaskEnabled'> = async (
formId,
newIsNricMaskEnabled,
) => {
export const updateIsSubmitterIdCollectionEnabled: UpdateFormFn<
'isSubmitterIdCollectionEnabled'
> = async (formId, nextIsSubmitterIdCollectionEnabled) => {
return updateFormSettings(formId, {
isNricMaskEnabled: newIsNricMaskEnabled,
isSubmitterIdCollectionEnabled: nextIsSubmitterIdCollectionEnabled,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Divider } from '@chakra-ui/react'

import { FormResponseMode, FormSettings } from '~shared/types/form'

import { FormNricMaskToggle } from './FormNricMaskToggle'
import { FormSubmitterIdCollectionToggle } from './FormNricCollectionToggle'
import { FormSingleSubmissionToggle } from './FormSingleSubmissionToggle'
import { FormWhitelistAttachmentField } from './FormWhitelistAttachmentField'
import { SingpassAuthOptionsRadio } from './SingpassAuthOptionsRadio'
Expand All @@ -29,17 +29,13 @@ export const AuthSettingsSingpassSection = ({
settings={settings}
isDisabled={isSinglepassAuthOptionsDisabled}
/>
{/* Hide the NRIC mask toggle if they have not yet enabled it as part of
PMO circular */}
{settings.isNricMaskEnabled ? (
<>
<Divider my="2.5rem" />
<FormNricMaskToggle
settings={settings}
isDisabled={isSingpassSettingsDisabled}
/>
</>
) : null}
<>
<Divider my="2.5rem" />
<FormSubmitterIdCollectionToggle
settings={settings}
isDisabled={isFormPublic}
/>
</>
{isEncryptMode || settings.isSingleSubmission ? (
<>
<Divider my="2.5rem" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useCallback } from 'react'

import { FormSettings } from '~shared/types/form'

import Toggle from '~components/Toggle'

import { useMutateFormSettings } from '../../mutations'

interface FormSubmitterIdCollectionProps {
settings: FormSettings
isDisabled: boolean
}

export const FormSubmitterIdCollectionToggle = ({
settings,
isDisabled,
}: FormSubmitterIdCollectionProps): JSX.Element => {
const isSubmitterIdCollectionEnabled =
!!settings?.isSubmitterIdCollectionEnabled

const { mutateIsSubmitterIdCollectionEnabled } = useMutateFormSettings()

const handleToggleCollection = useCallback(() => {
if (!settings || mutateIsSubmitterIdCollectionEnabled.isLoading) return
const nextIsNricMaskEnabled = !settings.isSubmitterIdCollectionEnabled
return mutateIsSubmitterIdCollectionEnabled.mutate(nextIsNricMaskEnabled)
}, [mutateIsSubmitterIdCollectionEnabled, settings])

return (
<Toggle
containerStyles={{ opacity: isDisabled ? 0.3 : 1 }}
isDisabled={isDisabled}
isLoading={!settings || mutateIsSubmitterIdCollectionEnabled.isLoading}
isChecked={isSubmitterIdCollectionEnabled}
label="Collect NRIC/FIN/UENs with form submissions"
description="NRIC/FIN/UENs are not collected or stored with form submissions by default"
onChange={handleToggleCollection}
/>
)
}

This file was deleted.

19 changes: 11 additions & 8 deletions frontend/src/features/admin-form/settings/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ import {
updateFormInactiveMessage,
updateFormIssueNotification,
updateFormLimit,
updateFormNricMask,
updateFormStatus,
updateFormTitle,
updateFormWebhookRetries,
updateFormWebhookUrl,
updateFormWhitelistSetting,
updateGstEnabledFlag,
updateIsSingleSubmission,
updateIsSubmitterIdCollectionEnabled,
updateTwilioCredentials,
} from './SettingsService'

Expand Down Expand Up @@ -321,16 +321,19 @@ export const useMutateFormSettings = () => {
},
)

const mutateNricMask = useMutation(
(nextIsNricMaskEnabled: boolean) =>
updateFormNricMask(formId, nextIsNricMaskEnabled),
const mutateIsSubmitterIdCollectionEnabled = useMutation(
(nextIsSubmitterIdCollectionEnabled: boolean) =>
updateIsSubmitterIdCollectionEnabled(
formId,
nextIsSubmitterIdCollectionEnabled,
),
{
onSuccess: (newData) => {
handleSuccess({
newData,
toastDescription: newData.isNricMaskEnabled
? 'NRIC masking is now enabled on your form.'
: 'NRIC masking is now disabled on your form.',
toastDescription: newData.isSubmitterIdCollectionEnabled
? 'NRIC/FIN/UEN collection is now enabled on your form.'
: 'NRIC/FIN/UEN collection is now disabled on your form.',
})
},
onError: handleError,
Expand Down Expand Up @@ -444,7 +447,7 @@ export const useMutateFormSettings = () => {
mutateFormEmails,
mutateFormTitle,
mutateFormAuthType,
mutateNricMask,
mutateIsSubmitterIdCollectionEnabled,
mutateIsSingleSubmission,
mutateFormWhitelistSetting,
mutateFormEsrvcId,
Expand Down
Loading

0 comments on commit 83f9c05

Please sign in to comment.