diff --git a/src/App/index.tsx b/src/App/index.tsx index e703de75..5e8a641f 100644 --- a/src/App/index.tsx +++ b/src/App/index.tsx @@ -115,18 +115,22 @@ function App() { setCurrentLanguage(language ?? 'en'); }, []); - const { - loading: meLoading, - } = useQuery( + const [ready, setReady] = useState(false); + + useQuery( ME, { onCompleted: (response) => { + setReady(true); if (response.public.me) { setUserAuth(response.public.me); } else { removeUserAuth(); } }, + onError: () => { + setReady(true); + }, }, ); @@ -251,7 +255,7 @@ function App() { removeAlert, }), [alerts, addAlert, updateAlert, removeAlert]); - if (meLoading) { + if (!ready) { return ( // FIXME: Use translation
diff --git a/src/App/redirects/ActivationRedirect.tsx b/src/App/redirects/ActivationRedirect.tsx index aaa7f7a0..d9a56c48 100644 --- a/src/App/redirects/ActivationRedirect.tsx +++ b/src/App/redirects/ActivationRedirect.tsx @@ -17,8 +17,8 @@ export function Component() { const { userId, token } = useParams(); const navigate = useNavigate(); - const activationLink = (userId && token && routes.activation.path) ? ({ - pathname: (generatePath(routes.activation.path, { userId, token })), + const activationLink = (userId && token) ? ({ + pathname: (generatePath(routes.activation.absolutePath, { userId, token })), }) : routes.pageNotFound.path; diff --git a/src/App/redirects/RecoverAccountRedirect.tsx b/src/App/redirects/RecoverAccountRedirect.tsx index b7471d96..67ddfed8 100644 --- a/src/App/redirects/RecoverAccountRedirect.tsx +++ b/src/App/redirects/RecoverAccountRedirect.tsx @@ -17,8 +17,11 @@ export function Component() { const { userId, resetToken } = useParams(); const navigate = useNavigate(); - const resetPasswordLink = (userId && resetToken && routes.recoverAccountConfirm.path) ? ({ - pathname: (generatePath(routes.recoverAccountConfirm.path, { userId, resetToken })), + const resetPasswordLink = (userId && resetToken) ? ({ + pathname: (generatePath( + routes.recoverAccountConfirm.absolutePath, + { userId, resetToken }, + )), }) : routes.pageNotFound.path; diff --git a/src/components/Captcha/index.tsx b/src/components/Captcha/index.tsx index f895d056..8021fb26 100644 --- a/src/components/Captcha/index.tsx +++ b/src/components/Captcha/index.tsx @@ -10,6 +10,7 @@ import { hCaptchaKey } from '#config'; export type HCaptchaProps = Omit & { name: T, onChange: (value: string | undefined, name: T) => void; + onError: (errorString: string) => void; elementRef?: React.RefObject; }; @@ -28,6 +29,7 @@ function HCaptchaInput(props: HCaptchaProps) { inputSectionClassName, label, readOnly, + onError, name, onChange, elementRef, @@ -43,9 +45,14 @@ function HCaptchaInput(props: HCaptchaProps) { (err: string) => { // eslint-disable-next-line no-console console.error(err); + onError(err); onChange(undefined, name); }, - [onChange, name], + [ + onChange, + name, + onError, + ], ); const handleExpire = useCallback( () => { diff --git a/src/views/NewSubscriptionModal/i18n.json b/src/views/NewSubscriptionModal/i18n.json index a6e3ad5d..4d51f82d 100644 --- a/src/views/NewSubscriptionModal/i18n.json +++ b/src/views/NewSubscriptionModal/i18n.json @@ -18,6 +18,7 @@ "filterRegionsLabel": "Regions", "filterRegionsPlaceholder": "All Regions", "newSubscriptionHeading": "New Subscription", + "editSubscriptionHeading": "Edit Subscription", "newSubscriptionTitle": "Title", "newSubscriptionCreatedSuccessfully": "Subscription created successfully.", "newSubscriptionFailed": "Failed to create subscription", diff --git a/src/views/NewSubscriptionModal/index.tsx b/src/views/NewSubscriptionModal/index.tsx index 3e3c833c..3716358a 100644 --- a/src/views/NewSubscriptionModal/index.tsx +++ b/src/views/NewSubscriptionModal/index.tsx @@ -17,7 +17,10 @@ import { TextInput, } from '@ifrc-go/ui'; import { useTranslation } from '@ifrc-go/ui/hooks'; -import { isNotDefined } from '@togglecorp/fujs'; +import { + isDefined, + isNotDefined, +} from '@togglecorp/fujs'; import { createSubmitHandler, getErrorObject, @@ -456,7 +459,9 @@ function NewSubscriptionModal(props: Props) { return ( { + setError((oldErrors) => { + const fieldErrors = getErrorObject(oldErrors); + return ({ + ...fieldErrors, + captcha: errorString, + }); + }); + }, [setError]); + if (isSubmitted) { return ( @@ -171,6 +182,7 @@ export function Component() {