From ba5fa484484427fea6c6ddb0225c2e46bbc7b728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Tue, 20 Dec 2022 08:50:41 +0100 Subject: [PATCH] reset captcha --- .../AddNewPaymentMethodModal.tsx | 12 ++++++++---- .../interfaces/Billing/EnterpriseUpdate.tsx | 9 +++++++-- .../interfaces/Billing/ExitSurvey/ExitSurvey.tsx | 9 +++++++-- studio/components/interfaces/Billing/ProUpgrade.tsx | 12 +++++++++--- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/studio/components/interfaces/Billing/AddNewPaymentMethodModal/AddNewPaymentMethodModal.tsx b/studio/components/interfaces/Billing/AddNewPaymentMethodModal/AddNewPaymentMethodModal.tsx index cb355ba8f29..edda104deb6 100644 --- a/studio/components/interfaces/Billing/AddNewPaymentMethodModal/AddNewPaymentMethodModal.tsx +++ b/studio/components/interfaces/Billing/AddNewPaymentMethodModal/AddNewPaymentMethodModal.tsx @@ -46,6 +46,11 @@ const AddNewPaymentMethodModal: FC = ({ visible, returnUrl, onCancel }) = setCaptchaLoaded(true) } + const resetCaptcha = () => { + setCaptchaToken(null) + captchaRef.current?.resetCaptcha() + } + const setupIntent = async (hcaptchaToken: string | undefined) => { setIntent(undefined) @@ -54,10 +59,9 @@ const AddNewPaymentMethodModal: FC = ({ visible, returnUrl, onCancel }) = hcaptchaToken, }) - if (intent.error) { - setCaptchaToken(null) - captchaRef.current?.resetCaptcha() + resetCaptcha() + if (intent.error) { return ui.setNotification({ category: 'error', message: intent.error.message, @@ -65,7 +69,7 @@ const AddNewPaymentMethodModal: FC = ({ visible, returnUrl, onCancel }) = }) } - setIntent(intent) + captchaRef.current?.resetCaptcha() } const options = { diff --git a/studio/components/interfaces/Billing/EnterpriseUpdate.tsx b/studio/components/interfaces/Billing/EnterpriseUpdate.tsx index 8ea5ff543da..77b10ab0809 100644 --- a/studio/components/interfaces/Billing/EnterpriseUpdate.tsx +++ b/studio/components/interfaces/Billing/EnterpriseUpdate.tsx @@ -132,6 +132,11 @@ const EnterpriseUpdate: FC = ({ setIsRefreshingPreview(false) } + const resetCaptcha = () => { + setCaptchaToken(null) + captchaRef.current?.resetCaptcha() + } + // Last todo to support enterprise billing on dashboard + E2E test const onConfirmPayment = async () => { let token = captchaToken @@ -155,9 +160,9 @@ const EnterpriseUpdate: FC = ({ setIsSubmitting(true) const res = await patch(`${API_URL}/projects/${projectRef}/subscription`, payload) + resetCaptcha() + if (res?.error) { - setCaptchaToken(null) - captchaRef.current?.resetCaptcha() ui.setNotification({ category: 'error', message: `Failed to update subscription: ${res?.error?.message}`, diff --git a/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx b/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx index 7144a13c948..52ad8ea889e 100644 --- a/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx +++ b/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx @@ -100,6 +100,11 @@ const ExitSurvey: FC = ({ freeTier, subscription, onSelectBack }) => { } } + const resetCaptcha = () => { + setCaptchaToken(null) + captchaRef.current?.resetCaptcha() + } + const downgradeProject = async (values?: any) => { const downgradeMessage = values?.message ?? message @@ -123,9 +128,9 @@ const ExitSurvey: FC = ({ freeTier, subscription, onSelectBack }) => { hcaptchaToken: token ?? undefined, }) + resetCaptcha() + if (res?.error) { - setCaptchaToken(null) - captchaRef.current?.resetCaptcha() return ui.setNotification({ category: 'error', message: `Failed to cancel subscription: ${res?.error?.message}`, diff --git a/studio/components/interfaces/Billing/ProUpgrade.tsx b/studio/components/interfaces/Billing/ProUpgrade.tsx index 68ff40f839e..f299c2308ce 100644 --- a/studio/components/interfaces/Billing/ProUpgrade.tsx +++ b/studio/components/interfaces/Billing/ProUpgrade.tsx @@ -153,6 +153,11 @@ const ProUpgrade: FC = ({ setIsRefreshingPreview(false) } + const resetCaptcha = () => { + setCaptchaToken(null) + captchaRef.current?.resetCaptcha() + } + const onConfirmPayment = async () => { let token = captchaToken if (!token) { @@ -166,18 +171,19 @@ const ProUpgrade: FC = ({ nonChangeableAddons, selectedPaymentMethodId, projectRegion, - token ?? undefined, + token ?? undefined ) setIsSubmitting(true) const res = await patch(`${API_URL}/projects/${projectRef}/subscription`, payload) + + resetCaptcha() + if (res?.error) { ui.setNotification({ category: 'error', message: `Failed to update subscription: ${res?.error?.message}`, }) - setCaptchaToken(null) - captchaRef.current?.resetCaptcha() } else { if (isChangingComputeSize) { app.onProjectStatusUpdated(projectId, PROJECT_STATUS.RESTORING)