Skip to content

Commit f6948b7

Browse files
authored
fix: formsg connection url (#990)
## Problem Right now, users can name their form `[UAT]` or `[STAGING]` and the form link gets broken ## Solution Add an env to the auth so that the frontend can process whether it is prod, staging or UAT. ## Tests - [ ] Staging form shows correct URL and display - [ ] Prod form shows correct URL and display - [ ] Prod form with `[UAT]` or `[STAGING]` still shows prod url
1 parent a5d4f6d commit f6948b7

File tree

7 files changed

+15
-14
lines changed

7 files changed

+15
-14
lines changed

packages/backend/src/apps/formsg/__tests__/auth/verify-credentials.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ describe('verify credentials', () => {
115115
).resolves.toBeUndefined()
116116
expect($.auth.set).toHaveBeenCalledWith({
117117
screenName: '6443b3ce39eb170011772f98 - Test Form',
118+
env: 'prod',
118119
})
119120
})
120121

packages/backend/src/apps/formsg/auth/verify-credentials.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const verifyFormCreds = async (
6161
const prefix = env !== 'prod' ? `[${env.toUpperCase()}] ` : ''
6262
await $.auth.set({
6363
screenName: `${prefix}${formId} - ${formTitle}`,
64+
env,
6465
})
6566
}
6667

packages/backend/src/graphql/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ type Connection {
306306

307307
type ConnectionData {
308308
screenName: String
309+
env: String
309310
}
310311

311312
type ExecutionStep {

packages/frontend/src/components/ChooseConnectionSubstep/index.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,8 @@ interface ConnectionStatus {
3838
}
3939

4040
const formLinkGenerator = (connectionOption: ConnectionDropdownOption) => {
41-
const { label, description: formId } = connectionOption
42-
if (label.startsWith('[')) {
43-
const endIndex = label.indexOf(']')
44-
const env = label.substring(1, endIndex)
45-
// Only add subodmain for STAGING and UAT
46-
if (env === 'STAGING' || env === 'UAT') {
47-
return `https://${env}.form.gov.sg/${formId}`
48-
}
49-
}
50-
return `https://form.gov.sg/${formId}`
41+
const { description: formId, env } = connectionOption
42+
return `https://${env === 'prod' ? '' : `${env}.`}form.gov.sg/${formId}`
5143
}
5244

5345
const excelFolderLinkGenerator = (userEmail: string) => {

packages/frontend/src/components/FlowStepConfigurationModal/ChooseAndAddConnection/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type ConnectionDropdownOption = {
2222
label: string
2323
value: string
2424
description?: string
25+
env?: string // only used for FormSG now
2526
}
2627

2728
// For FormSG, it will generate a label with the form title and the description with the form id
@@ -33,20 +34,23 @@ export const optionGenerator = (
3334
): ConnectionDropdownOption => {
3435
const screenName = connection?.formattedData?.screenName as string
3536
if (appKey === 'formsg') {
37+
// old form connections will have env as undefined and be treated as prod
38+
const env = (connection?.formattedData?.env as string) ?? 'prod'
39+
3640
// parse the screenName to get the env, formId, and formTitle
3741
const [envWithFormId, formTitle] = screenName.split(' - ')
38-
let env = ''
3942
let formId = envWithFormId
40-
if (envWithFormId.startsWith('[')) {
43+
// only if the env is not prod, we need to parse the env from the screenName
44+
if (env !== 'prod') {
4145
const endIndex = envWithFormId.indexOf(']')
42-
env = envWithFormId.substring(0, endIndex + 1) + ' '
4346
formId = envWithFormId.substring(endIndex + 2) // skip "]"
4447
}
4548

4649
return {
47-
label: `${env}${formTitle}`,
50+
label: `${env === 'prod' ? '' : `[${env.toUpperCase()}] `}${formTitle}`,
4851
value: connection?.id as string,
4952
description: formId,
53+
env,
5054
}
5155
}
5256

packages/frontend/src/graphql/queries/get-app-connections.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const GET_APP_CONNECTIONS = gql`
1111
flowCount
1212
formattedData {
1313
screenName
14+
env
1415
}
1516
createdAt
1617
}

packages/frontend/src/graphql/queries/get-flow.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const GET_FLOW = gql`
2222
createdAt
2323
formattedData {
2424
screenName
25+
env
2526
}
2627
}
2728
parameters

0 commit comments

Comments
 (0)