Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove eb shift frontend feature flags #6869

Merged
merged 10 commits into from
Nov 14, 2023
139 changes: 18 additions & 121 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,17 +247,10 @@ export const PublicFormProvider = ({
}
}, [data?.form.form_fields, toast, vfnToastIdRef])

const enableVirusScanner = useFeatureIsOn(
featureFlags.encryptionBoundaryShiftVirusScanner,
)

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

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 submitStorageModeClearFormWithVirusScanningFetchMutation
.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 submitStorageModeClearFormWithVirusScanningMutation
.mutateAsync(
{
...formData,
...formPaymentData,
Expand All @@ -582,86 +545,25 @@ 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,
},
})
},
)
showErrorToast(error, form)
tshuli marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
Loading
Loading