Skip to content

Commit

Permalink
Merge pull request #6909 from opengovsg/fix/revert-eb-shift-frontend
Browse files Browse the repository at this point in the history
chore: Revert remove eb shift frontend feature flags (#6869)
  • Loading branch information
tshuli committed Nov 17, 2023
2 parents 9767656 + 1f4e9f7 commit 67cfa78
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 124 deletions.
19 changes: 10 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v6.89.1](https://github.com/opengovsg/FormSG/compare/v6.89.0...v6.89.1)
#### [v6.89.2](https://github.com/opengovsg/FormSG/compare/v6.89.0...v6.89.2)

- fix: hotfix v6.89.1 for proper error handling in encrypt-submission middleware [`#6903`](https://github.com/opengovsg/FormSG/pull/6903)
- build: release v6.89.0 [`#6898`](https://github.com/opengovsg/FormSG/pull/6898)
- fix: remove myinfo child from storage mode [`#6901`](https://github.com/opengovsg/FormSG/pull/6901)
- fix: add error handling [`d6c4985`](https://github.com/opengovsg/FormSG/commit/d6c4985aa8e35dd2278af9b70d00d4e86a48bde1)
- fix: remove email mode from myinfo limit message [`5a45c98`](https://github.com/opengovsg/FormSG/commit/5a45c980dbe3fc8c15eacb3ff1827f3003fcbfc4)
- fix: add learn more link [`#6897`](https://github.com/opengovsg/FormSG/pull/6897)
- chore: security upgrade axios to 1.6.2 [`#6893`](https://github.com/opengovsg/FormSG/pull/6893)
- chore: revert commit 6869 [`efab3cf`](https://github.com/opengovsg/FormSG/commit/efab3cf844113573d758b1b2c57147d5d0656a28)
- chore: bump version to v6.89.0 [`1665a48`](https://github.com/opengovsg/FormSG/commit/1665a48b0ff133378c7126d3fedf8f1145f67111)
- fix: remove error block [`fb415fc`](https://github.com/opengovsg/FormSG/commit/fb415fcd7189a90056557c242ed98f1dc10e757e)

#### [v6.89.0](https://github.com/opengovsg/FormSG/compare/v6.88.0...v6.89.0)

> 15 November 2023

- fix: add learn more link [`#6897`](https://github.com/opengovsg/FormSG/pull/6897)
- chore: security upgrade axios to 1.6.2 [`#6893`](https://github.com/opengovsg/FormSG/pull/6893)
- feat: myinfo for storage-mode [`#6870`](https://github.com/opengovsg/FormSG/pull/6870)
- feat: announcement modal and what's new for myinfo storage-mode [`#6892`](https://github.com/opengovsg/FormSG/pull/6892)
- chore: remove eb shift frontend feature flags [`#6869`](https://github.com/opengovsg/FormSG/pull/6869)
Expand All @@ -26,7 +28,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- fix(deps): bump type-fest from 4.5.0 to 4.7.1 in /shared [`#6883`](https://github.com/opengovsg/FormSG/pull/6883)
- build: merge release 6.88.0 into develop [`#6882`](https://github.com/opengovsg/FormSG/pull/6882)
- build: release v6.88.0 [`#6881`](https://github.com/opengovsg/FormSG/pull/6881)
- chore: bump version to v6.89.0 [`1665a48`](https://github.com/opengovsg/FormSG/commit/1665a48b0ff133378c7126d3fedf8f1145f67111)
- chore: bump version to v6.89.0 [`3a15ceb`](https://github.com/opengovsg/FormSG/commit/3a15ceb52806aae4a0aaa91c0e2c49d4bcae8606)

#### [v6.88.0](https://github.com/opengovsg/FormSG/compare/v6.87.0...v6.88.0)

Expand All @@ -47,22 +49,21 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- fix: add case for SGID MyInfo when field value is missing [`#6874`](https://github.com/opengovsg/FormSG/pull/6874)
- build: merge release v6.86.0 into develop [`#6873`](https://github.com/opengovsg/FormSG/pull/6873)
- build: release v6.86.0 [`#6866`](https://github.com/opengovsg/FormSG/pull/6866)
- chore: use non-testing branch for font-wqy-zenhei [`#6867`](https://github.com/opengovsg/FormSG/pull/6867)
- chore: bump version to v6.86.0 [`1eec9b6`](https://github.com/opengovsg/FormSG/commit/1eec9b63c914b56b7b10adffd03554e07fde0f3a)
- chore: bump version to v6.87.0 [`5054803`](https://github.com/opengovsg/FormSG/commit/50548038804b03f30ce6d23b4d43b7a8cf7d9620)

#### [v6.86.0](https://github.com/opengovsg/FormSG/compare/v6.85.1...v6.86.0)

> 6 November 2023

- chore: use non-testing branch for font-wqy-zenhei [`#6867`](https://github.com/opengovsg/FormSG/pull/6867)
- chore: update credits and terms of use [`#6865`](https://github.com/opengovsg/FormSG/pull/6865)
- fix: add cloudflareinsights as allowable csp [`#6864`](https://github.com/opengovsg/FormSG/pull/6864)
- feat: optimise submission query [`#6863`](https://github.com/opengovsg/FormSG/pull/6863)
- chore(dockerfile): update mocktwilio to start asap [`#6862`](https://github.com/opengovsg/FormSG/pull/6862)
- fix: only render delete button if owner [`#6837`](https://github.com/opengovsg/FormSG/pull/6837)
- build: merge release v6.85.1 into develop [`#6861`](https://github.com/opengovsg/FormSG/pull/6861)
- fix: hotfix v6.85.1 to prevent creation of SGID_MyInfo storage mode forms [`#6860`](https://github.com/opengovsg/FormSG/pull/6860)
- chore: bump version to v6.86.0 [`1c827cd`](https://github.com/opengovsg/FormSG/commit/1c827cd11844649ca303bb5dc9987db5367637c9)
- chore: bump version to v6.86.0 [`1eec9b6`](https://github.com/opengovsg/FormSG/commit/1eec9b63c914b56b7b10adffd03554e07fde0f3a)

#### [v6.85.1](https://github.com/opengovsg/FormSG/compare/v6.85.0...v6.85.1)

Expand Down
145 changes: 123 additions & 22 deletions frontend/src/features/public-form/PublicFormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { SubmitHandler } from 'react-hook-form'
import { useNavigate } from 'react-router-dom'
import { useDisclosure } from '@chakra-ui/react'
import { datadogLogs } from '@datadog/browser-logs'
import {
useFeatureIsOn,
useFeatureValue,
useGrowthBook,
} from '@growthbook/growthbook-react'
import { differenceInMilliseconds, isPast } from 'date-fns'
import get from 'lodash/get'
import simplur from 'simplur'
Expand Down Expand Up @@ -130,6 +135,23 @@ export const PublicFormProvider = ({
/* enabled= */ !submissionData,
)

const growthbook = useGrowthBook()

useEffect(() => {
if (growthbook) {
growthbook.setAttributes({
// Only update the `formId` attribute, keep the rest the same
...growthbook.getAttributes(),
formId,
})
}
}, [growthbook, formId])

const enableEncryptionBoundaryShift = useFeatureValue(
featureFlags.encryptionBoundaryShift,
true,
)

// Scroll to top of page when user has finished their submission.
useLayoutEffect(() => {
if (submissionData) {
Expand Down Expand Up @@ -247,11 +269,18 @@ export const PublicFormProvider = ({
}
}, [data?.form.form_fields, toast, vfnToastIdRef])

const enableVirusScanner = useFeatureIsOn(
featureFlags.encryptionBoundaryShiftVirusScanner,
)

const {
submitEmailModeFormMutation,
submitStorageModeFormMutation,
submitEmailModeFormFetchMutation,
submitStorageModeFormWithVirusScanningFetchMutation,
submitStorageModeFormWithVirusScanningMutation,
submitStorageModeFormFetchMutation,
submitStorageModeClearFormMutation,
submitStorageModeClearFormFetchMutation,
submitStorageModeClearFormWithVirusScanningMutation,
} = usePublicFormMutations(formId, submissionData?.id ?? '')

const { handleLogoutMutation } = usePublicAuthMutations(formId)
Expand Down Expand Up @@ -455,7 +484,9 @@ export const PublicFormProvider = ({
: {}),
}

const submitStorageFormWithFetch = function () {
const submitStorageFormWithFetch = function (
routeToNewStorageModeSubmission: boolean,
) {
datadogLogs.logger.info(`handleSubmitForm: submitting via fetch`, {
meta: {
...logMeta,
Expand All @@ -464,11 +495,16 @@ export const PublicFormProvider = ({
},
})

return submitStorageModeFormWithVirusScanningFetchMutation
return (
routeToNewStorageModeSubmission
? submitStorageModeClearFormFetchMutation
: submitStorageModeFormFetchMutation
)
.mutateAsync(
{
...formData,
...formPaymentData,
publicKey: form.publicKey,
},
{
onSuccess: ({
Expand Down Expand Up @@ -510,7 +546,7 @@ export const PublicFormProvider = ({

// TODO (#5826): Toggle to use fetch for submissions instead of axios. If enabled, this is used for testing and to use fetch instead of axios by default if testing shows fetch is more stable. Remove once network error is resolved
if (useFetchForSubmissions) {
return submitStorageFormWithFetch()
return submitStorageFormWithFetch(enableEncryptionBoundaryShift)
}
datadogLogs.logger.info(`handleSubmitForm: submitting via axios`, {
meta: {
Expand All @@ -520,8 +556,9 @@ export const PublicFormProvider = ({
},
})

return submitStorageModeFormWithVirusScanningMutation
.mutateAsync(
// TODO (FRM-1413): Move to main return statement once virus scanner has been fully rolled out
if (enableEncryptionBoundaryShift && enableVirusScanner) {
return submitStorageModeClearFormWithVirusScanningMutation.mutateAsync(
{
...formData,
...formPaymentData,
Expand All @@ -545,27 +582,86 @@ export const PublicFormProvider = ({
timestamp,
})
},
onError: (error) => {
// TODO(#5826): Remove when we have resolved the Network Error
datadogLogs.logger.warn(
`handleSubmitForm: submit with virus scan`,
{
meta: {
...logMeta,
responseMode: 'storage',
method: 'axios',
error,
},
},
)

// defaults to the safest option of storage submission without virus scanning
return submitStorageFormWithFetch(
enableEncryptionBoundaryShift,
)
},
},
)
.catch(async (error) => {
datadogLogs.logger.warn(
`handleSubmitForm: submit with virus scan`,
}

return (
(
enableEncryptionBoundaryShift
? submitStorageModeClearFormMutation
: submitStorageModeFormMutation
)
.mutateAsync(
{
...formData,
...formPaymentData,
publicKey: form.publicKey,
},
{
onSuccess: ({
submissionId,
timestamp,
// payment forms will have non-empty paymentData field
paymentData,
}) => {
trackSubmitForm(form)

if (paymentData) {
navigate(getPaymentPageUrl(formId, paymentData.paymentId))
storePaymentMemory(paymentData.paymentId)
return
}
setSubmissionData({
id: submissionId,
timestamp,
})
},
},
)
// Using catch since we are using mutateAsync and react-hook-form will continue bubbling this up.
.catch(async (error) => {
// TODO(#5826): Remove when we have resolved the Network Error
datadogLogs.logger.warn(`handleSubmitForm: ${error.message}`, {
meta: {
...logMeta,
responseMode: 'storage',
method: 'axios',
error,
error: {
message: error.message,
stack: error.stack,
},
},
},
)
if (/Network Error/i.test(error.message)) {
axiosDebugFlow()
// fallback to fetch
return submitStorageFormWithFetch()
}
showErrorToast(error, form)
})
})

if (/Network Error/i.test(error.message)) {
axiosDebugFlow()
return submitStorageFormWithFetch(
enableEncryptionBoundaryShift,
)
}
showErrorToast(error, form)
})
)
}
}
},
Expand All @@ -582,11 +678,16 @@ export const PublicFormProvider = ({
getCaptchaResponse,
submitEmailModeFormFetchMutation,
submitEmailModeFormMutation,
submitStorageModeFormWithVirusScanningMutation,
submitStorageModeFormWithVirusScanningFetchMutation,
enableEncryptionBoundaryShift,
enableVirusScanner,
submitStorageModeClearFormMutation,
submitStorageModeFormMutation,
submitStorageModeClearFormFetchMutation,
submitStorageModeFormFetchMutation,
navigate,
formId,
storePaymentMemory,
submitStorageModeClearFormWithVirusScanningMutation,
],
)

Expand Down
Loading

0 comments on commit 67cfa78

Please sign in to comment.