Skip to content

Commit c3a6a27

Browse files
committed
add survey for pipe publishing
1 parent 232cece commit c3a6a27

File tree

10 files changed

+182
-80
lines changed

10 files changed

+182
-80
lines changed

package-lock.json

Lines changed: 138 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend/src/graphql/mutations/update-flow-status.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ const updateFlowStatus: MutationResolvers['updateFlowStatus'] = async (
4141
await flow.$query().patch({
4242
active: params.input.active,
4343
publishedAt: params.input.active ? new Date().toISOString() : null,
44+
config: {
45+
...flow.config,
46+
// When publishing: set to true if undefined else false
47+
// When unpublishing: keep existing value
48+
showSurvey: params.input.active
49+
? flow.config?.showSurvey === undefined
50+
? true
51+
: false
52+
: flow.config?.showSurvey,
53+
},
4454
})
4555

4656
const triggerStep = await flow.getTriggerStep()

packages/backend/src/graphql/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ type FlowConfig {
359359
duplicateCount: Int
360360
demoConfig: FlowDemoConfig
361361
templateConfig: FlowTemplateConfig
362+
showSurvey: Boolean
362363
}
363364

364365
type FlowErrorConfig {

packages/backend/src/helpers/csp.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const helmetOptions: HelmetOptions = {
1717
'https://*.launchdarkly.com',
1818
// For proxying datadog rum
1919
'https://rum-proxy.plumber.gov.sg',
20+
// For Lens Survey
21+
'https://lens.hack2025.com.sg',
2022
appConfig.baseUrl,
2123
],
2224
// for google fonts

packages/frontend/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"@dnd-kit/core": "6.1.0",
1717
"@dnd-kit/modifiers": "7.0.0",
1818
"@dnd-kit/sortable": "8.0.0",
19-
"@emotion/react": "11.10.5",
20-
"@emotion/styled": "11.10.5",
19+
"@emotion/react": "^11.14.0",
20+
"@emotion/styled": "^11.14.0",
2121
"@fontsource/space-grotesk": "4.5.13",
2222
"@hookform/resolvers": "^2.8.8",
2323
"@mui/icons-material": "5.11.0",
@@ -41,6 +41,7 @@
4141
"dedent": "1.5.1",
4242
"escape-html": "1.0.3",
4343
"file-saver": "2.0.5",
44+
"lens-widget": "1.35.0",
4445
"lodash": "^4.17.21",
4546
"lodash.get": "4.4.2",
4647
"lottie-web": "5.12.2",
@@ -49,7 +50,7 @@
4950
"notistack": "2.0.8",
5051
"papaparse": "5.4.1",
5152
"react-hook-form": "^7.17.2",
52-
"react-icons": "4.10.1",
53+
"react-icons": "^4.12.0",
5354
"react-intl": "6.2.7",
5455
"react-json-tree": "^0.18.0",
5556
"react-markdown": "8.0.7",

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import {
1212
Flex,
1313
} from '@chakra-ui/react'
1414
import { IconButton } from '@opengovsg/design-system-react'
15+
import { Rating } from 'lens-widget'
1516

1617
import FlowStep from '@/components/FlowStep'
1718
import FlowStepGroup from '@/components/FlowStepGroup'
19+
import appConfig from '@/config/app'
1820
import { EditorContext } from '@/contexts/Editor'
1921
import {
2022
StepExecutionsToIncludeContext,
@@ -24,6 +26,7 @@ import { CREATE_STEP } from '@/graphql/mutations/create-step'
2426
import { UPDATE_STEP } from '@/graphql/mutations/update-step'
2527
import { GET_APPS } from '@/graphql/queries/get-apps'
2628
import { GET_FLOW } from '@/graphql/queries/get-flow'
29+
import useAuthentication from '@/hooks/useAuthentication'
2730

2831
interface AddStepButtonProps {
2932
onClick: () => void
@@ -97,6 +100,9 @@ export default function Editor(props: EditorProps): React.ReactElement {
97100
)
98101

99102
const { flow, steps: rawSteps } = props
103+
const showSurvey = flow.active && flow.config?.showSurvey
104+
const { currentUser } = useAuthentication()
105+
100106
const steps = useMemo(
101107
// Populate each step's flowId so that IStep isn't LYING about flowId being
102108
// non-undefined. We do it here instead of fetching in GraphQL since all
@@ -294,6 +300,18 @@ export default function Editor(props: EditorProps): React.ReactElement {
294300
)}
295301
</StepExecutionsToIncludeProvider>
296302
</Flex>
303+
304+
{showSurvey && (
305+
<Rating
306+
clientKey={appConfig.lensSurveyClientKey}
307+
brandColour="#cf1a68"
308+
attributes={[
309+
`FlowId: ${flow.id}`,
310+
`UserEmail: ${currentUser?.email}`,
311+
...(appConfig.env !== 'prod' ? [`Env: ${appConfig.env}`] : []),
312+
]}
313+
/>
314+
)}
297315
</Flex>
298316
)
299317
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export default function EditorLayout() {
3737
const { flowId } = useParams()
3838
const [searchParams, setSearchParams] = useSearchParams()
3939
const [updateFlow] = useMutation(UPDATE_FLOW)
40-
const [updateFlowStatus] = useMutation(UPDATE_FLOW_STATUS)
40+
const [updateFlowStatus] = useMutation(UPDATE_FLOW_STATUS, {
41+
refetchQueries: [GET_FLOW],
42+
})
4143
const { data, loading, error } = useQuery(GET_FLOW, {
4244
variables: { id: flowId },
4345
})

packages/frontend/src/config/app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ interface AppConfig {
44
isDev: boolean
55
env: string
66
version: string
7+
lensSurveyClientKey: string
78
}
89

910
function getAppConfig(): AppConfig {
@@ -22,6 +23,7 @@ function getAppConfig(): AppConfig {
2223
launchDarklyClientId: '64bf4b539077f112ef24e4ae',
2324
sgidClientId: 'PLUMBER-c24255a5',
2425
isDev: false,
26+
lensSurveyClientKey: 'cm85ca2f300053ooz4vydrmyw',
2527
...commonEnv,
2628
}
2729
case 'uat':
@@ -30,13 +32,15 @@ function getAppConfig(): AppConfig {
3032
launchDarklyClientId: '65016ca0b45b7712e6c95703',
3133
sgidClientId: 'PLUMBERSTAGING-776896b1',
3234
isDev: false,
35+
lensSurveyClientKey: 'cm86psst900052orfqetz3gz5',
3336
...commonEnv,
3437
}
3538
default:
3639
return {
3740
launchDarklyClientId: '64bf4b539077f112ef24e4ad',
3841
sgidClientId: 'PLUMBERLOCALDEV-dc1a72f7',
3942
isDev: true,
43+
lensSurveyClientKey: 'cm86psst900052orfqetz3gz5', // same as staging
4044
...commonEnv,
4145
}
4246
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const GET_FLOW = gql`
4040
formId
4141
tileId
4242
}
43+
showSurvey
4344
}
4445
pendingTransfer {
4546
id

packages/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export interface IFlowConfig {
174174
duplicateCount?: number
175175
demoConfig?: IFlowDemoConfig
176176
templateConfig?: IFlowTemplateConfig
177+
showSurvey?: boolean
177178
}
178179

179180
export interface IFlowErrorConfig {

0 commit comments

Comments
 (0)