Skip to content

Commit

Permalink
fix: use enableCaptcha var
Browse files Browse the repository at this point in the history
  • Loading branch information
LinHuiqing committed Jul 26, 2023
1 parent 2c1fcb9 commit 68516b0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions frontend/src/features/public-form/PublicFormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,12 @@ export const PublicFormProvider = ({
}
}, [submissionData])

const enableCaptcha = !!data?.form.hasCaptcha && !data?.isIntranetUser

// Only load catpcha if enabled on form and the user is not on GSIB
const {
data: { captchaPublicKey, turnstileSiteKey, useFetchForSubmissions } = {},
} = useEnv(/* enabled= */ !!data?.form.hasCaptcha && !data?.isIntranetUser)
} = useEnv(/* enabled= */ enableCaptcha)

// Feature flag to control turnstile captcha rollout
// defaults to false
Expand All @@ -157,7 +159,7 @@ export const PublicFormProvider = ({
getTurnstileResponse,
containerID: turnstileContainerID,
} = useTurnstile({
sitekey: data?.form.hasCaptcha ? turnstileSiteKey : undefined,
sitekey: enableCaptcha ? turnstileSiteKey : undefined,
enableUsage: enableTurnstileFeatureFlag,
})

Expand All @@ -166,7 +168,7 @@ export const PublicFormProvider = ({
getCaptchaResponse,
containerId: recaptchaContainerID,
} = useRecaptcha({
sitekey: data?.form.hasCaptcha ? captchaPublicKey : undefined,
sitekey: enableCaptcha ? captchaPublicKey : undefined,
enableUsage: !enableTurnstileFeatureFlag,
})

Expand Down Expand Up @@ -593,7 +595,7 @@ export const PublicFormProvider = ({
isAuthRequired,
captchaContainerId: containerID,
expiryInMs,
isLoading: isLoading || (!!data?.form.hasCaptcha && !hasLoaded),
isLoading: isLoading || (!!enableCaptcha && !hasLoaded),
isPaymentEnabled,
isPreview: false,
setNumVisibleFields,
Expand Down

0 comments on commit 68516b0

Please sign in to comment.