From f481da378035ead628a4e75709699a6b23594049 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 28 Jan 2025 11:59:25 -0600 Subject: [PATCH] Make the onboarding modal show up again (during Nostr login flow) --- src/api/hooks/captcha/useCaptcha.ts | 13 +++++-------- .../modals/nostr-signup-modal/steps/keygen-step.tsx | 2 ++ src/init/soapbox-mount.tsx | 8 +++++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/api/hooks/captcha/useCaptcha.ts b/src/api/hooks/captcha/useCaptcha.ts index 2463b869f..29cae3b9b 100644 --- a/src/api/hooks/captcha/useCaptcha.ts +++ b/src/api/hooks/captcha/useCaptcha.ts @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; +import { fetchMe } from 'soapbox/actions/me.ts'; import { closeModal } from 'soapbox/actions/modals.ts'; import { HTTPError } from 'soapbox/api/HTTPError.ts'; import { useApi } from 'soapbox/hooks/useApi.ts'; @@ -9,8 +10,6 @@ import { useInstance } from 'soapbox/hooks/useInstance.ts'; import { captchaSchema, type CaptchaData } from 'soapbox/schemas/captcha.ts'; import toast from 'soapbox/toast.tsx'; - - const messages = defineMessages({ sucessMessage: { id: 'nostr_signup.captcha_message.sucess', defaultMessage: 'Incredible! You\'ve successfully completed the captcha.' }, wrongMessage: { id: 'nostr_signup.captcha_message.wrong', defaultMessage: 'Oops! It looks like your captcha response was incorrect. Please try again.' }, @@ -66,12 +65,10 @@ const useCaptcha = () => { }; try { - await api.post(`/api/v1/ditto/captcha/${captcha.id}/verify`, result).then(() => { - setTryAgain(true); - - dispatch(closeModal('CAPTCHA')); - toast.success(messages.sucessMessage); - }); + await api.post(`/api/v1/ditto/captcha/${captcha.id}/verify`, result); + dispatch(closeModal('CAPTCHA')); + await dispatch(fetchMe()); // refetch account so `captcha_solved` changes. + toast.success(messages.sucessMessage); } catch (error) { setTryAgain(true); diff --git a/src/features/ui/components/modals/nostr-signup-modal/steps/keygen-step.tsx b/src/features/ui/components/modals/nostr-signup-modal/steps/keygen-step.tsx index 407faf92c..c0ef3cf63 100644 --- a/src/features/ui/components/modals/nostr-signup-modal/steps/keygen-step.tsx +++ b/src/features/ui/components/modals/nostr-signup-modal/steps/keygen-step.tsx @@ -6,6 +6,7 @@ import { FormattedMessage } from 'react-intl'; import { fetchAccount } from 'soapbox/actions/accounts.ts'; import { logInNostr } from 'soapbox/actions/nostr.ts'; +import { startOnboarding } from 'soapbox/actions/onboarding.ts'; import { closeSidebar } from 'soapbox/actions/sidebar.ts'; import EmojiGraphic from 'soapbox/components/emoji-graphic.tsx'; import Button from 'soapbox/components/ui/button.tsx'; @@ -79,6 +80,7 @@ const KeygenStep: React.FC = ({ onClose }) => { dispatch(closeSidebar()); } + dispatch(startOnboarding()); }; return ( diff --git a/src/init/soapbox-mount.tsx b/src/init/soapbox-mount.tsx index eafccacae..680aa71d6 100644 --- a/src/init/soapbox-mount.tsx +++ b/src/init/soapbox-mount.tsx @@ -39,9 +39,11 @@ const SoapboxMount = () => { } }, [showCaptcha]); - if (showOnboarding) { - dispatch(openModal('ONBOARDING_FLOW')); - } + useEffect(() => { + if (showOnboarding && !showCaptcha) { + dispatch(openModal('ONBOARDING_FLOW')); + } + }, [showOnboarding, showCaptcha]); const { redirectRootNoLogin, gdpr } = soapboxConfig;