Skip to content

Commit 895f793

Browse files
committed
refactor to utils function
1 parent e4f26e9 commit 895f793

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

frontend/src/features/admin-form/settings/components/AuthSettingsSection/SingpassAuthOptionsRadio.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useMutateFormSettings } from '../../mutations'
1818
import { FORM_SINGPASS_AUTHTYPES } from './constants'
1919
import { EsrvcIdBox } from './EsrvcIdBox'
2020
import { pickBy } from 'lodash'
21+
import { isEsrvcidRequired } from '../utils'
2122

2223
export interface SingpassAuthOptionsRadioProps {
2324
settings: FormSettings
@@ -26,21 +27,6 @@ export interface SingpassAuthOptionsRadioProps {
2627

2728
type RadioOptionsType = [FormAuthType, string][]
2829

29-
/**
30-
* Only CorpPass requires esrvcid as other options will use FormSG's
31-
* supplied value to increase Singpass Myinfo adoption
32-
* @param authType
33-
* @returns
34-
*/
35-
const isEsrvcidRequired = (authType: FormAuthType) => {
36-
switch (authType) {
37-
case FormAuthType.CP:
38-
return true
39-
default:
40-
return false
41-
}
42-
}
43-
4430
const COLLAPSED_FORM_SINGPASS_AUTHTYPES = pickBy(
4531
FORM_SINGPASS_AUTHTYPES,
4632
(_, key) =>

frontend/src/features/admin-form/settings/components/FormStatusToggle.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { useAdminFormSettings } from '../queries'
2020

2121
import { EmailModeConvertModal } from './EmailModeConvertModal'
2222
import { SecretKeyActivationModal } from './SecretKeyActivationModal'
23+
import { isEsrvcidRequired } from './utils'
2324

2425
export const FormStatusToggle = (): JSX.Element => {
2526
const { t } = useTranslation()
@@ -41,7 +42,7 @@ export const FormStatusToggle = (): JSX.Element => {
4142
if (status === FormStatus.Public) return
4243

4344
// Prevent form activation if form has authType but no esrvcId.
44-
if (authType && [FormAuthType.CP].includes(authType) && !esrvcId) {
45+
if (authType && isEsrvcidRequired(authType) && !esrvcId) {
4546
return t(
4647
'features.adminForm.settings.general.status.supplySingpassEServiceId',
4748
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { FormAuthType } from '~shared/types'
2+
3+
/**
4+
* Only CorpPass requires esrvcid as other options will use FormSG's
5+
* supplied value to increase Singpass Myinfo adoption
6+
* @param authType
7+
* @returns
8+
*/
9+
10+
export const isEsrvcidRequired = (authType: FormAuthType) => {
11+
switch (authType) {
12+
case FormAuthType.CP:
13+
return true
14+
default:
15+
return false
16+
}
17+
}

0 commit comments

Comments
 (0)