Skip to content

Commit

Permalink
chore: remove eb shift frontend feature flags (#6869)
Browse files Browse the repository at this point in the history
* chore: remove virus scanner feature flag

* chore: remove enable encryption boundary shift feature flag

* chore: remove growthbook in public form provider

* chore: remove unused storage submission modes

* chore: fetch fallback should also use virus scanning

* chore: update mutation

* chore: move fallback to catch block

* chore: add back network error check

* chore: remove unused import and const

* chore: remove clear word
  • Loading branch information
tshuli committed Nov 14, 2023
1 parent 7baacef commit d5bbb4d
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 303 deletions.
145 changes: 22 additions & 123 deletions frontend/src/features/public-form/PublicFormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ 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 @@ -135,23 +130,6 @@ 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 @@ -269,18 +247,11 @@ export const PublicFormProvider = ({
}
}, [data?.form.form_fields, toast, vfnToastIdRef])

const enableVirusScanner = useFeatureIsOn(
featureFlags.encryptionBoundaryShiftVirusScanner,
)

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

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

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

return (
routeToNewStorageModeSubmission
? submitStorageModeClearFormFetchMutation
: submitStorageModeFormFetchMutation
)
return submitStorageModeFormWithVirusScanningFetchMutation
.mutateAsync(
{
...formData,
...formPaymentData,
publicKey: form.publicKey,
},
{
onSuccess: ({
Expand Down Expand Up @@ -546,7 +510,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(enableEncryptionBoundaryShift)
return submitStorageFormWithFetch()
}
datadogLogs.logger.info(`handleSubmitForm: submitting via axios`, {
meta: {
Expand All @@ -556,9 +520,8 @@ export const PublicFormProvider = ({
},
})

// TODO (FRM-1413): Move to main return statement once virus scanner has been fully rolled out
if (enableEncryptionBoundaryShift && enableVirusScanner) {
return submitStorageModeClearFormWithVirusScanningMutation.mutateAsync(
return submitStorageModeFormWithVirusScanningMutation
.mutateAsync(
{
...formData,
...formPaymentData,
Expand All @@ -582,86 +545,27 @@ 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,
)
},
},
)
}

return (
(
enableEncryptionBoundaryShift
? submitStorageModeClearFormMutation
: submitStorageModeFormMutation
)
.mutateAsync(
{
...formData,
...formPaymentData,
publicKey: form.publicKey,
},
.catch(async (error) => {
datadogLogs.logger.warn(
`handleSubmitForm: submit with virus scan`,
{
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: {
message: error.message,
stack: error.stack,
},
error,
},
})

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

Expand Down
Loading

0 comments on commit d5bbb4d

Please sign in to comment.