Skip to content

Commit

Permalink
fix(core): improve redirect behavior after creating new address with …
Browse files Browse the repository at this point in the history
…browser nav buttons
  • Loading branch information
bc-yevhenii-buliuk committed Aug 21, 2024
1 parent a4610ed commit 053bca9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useRouter } from 'next/navigation';
import { useTranslations } from 'next-intl';
import { useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useFormStatus } from 'react-dom';
import ReCaptcha from 'react-google-recaptcha';

Expand Down Expand Up @@ -97,6 +97,10 @@ export const AddAddress = ({

const { setAccountState } = useAccountStatusContext();

useEffect(() => {
setAccountState({ status: 'idle' });
}, [setAccountState]);

const handleTextInputValidation = createTextInputValidationHandler(
setTextInputValid,
textInputValid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useRouter } from 'next/navigation';
import { useTranslations } from 'next-intl';
import { useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useFormStatus } from 'react-dom';
import ReCaptcha from 'react-google-recaptcha';

Expand Down Expand Up @@ -101,6 +101,10 @@ export const EditAddress = ({
const [isReCaptchaValid, setReCaptchaValid] = useState(true);
const { setAccountState } = useAccountStatusContext();

useEffect(() => {
setAccountState({ status: 'idle' });
}, [setAccountState]);

const [textInputValid, setTextInputValid] = useState<Record<string, boolean>>({});

const defaultStates = countries
Expand Down Expand Up @@ -170,10 +174,6 @@ export const EditAddress = ({
router.push('/account/addresses');
};

const onCancelChange = () => {
setAccountState({ status: 'idle' });
};

return (
<>
{formStatus && (
Expand Down Expand Up @@ -273,12 +273,7 @@ export const EditAddress = ({
<FormSubmit asChild>
<SubmitButton messages={{ submit: t('submit'), submitting: t('submitting') }} />
</FormSubmit>
<Button
asChild
className="items-center px-8 md:ms-6 md:w-fit"
onClick={onCancelChange}
variant="secondary"
>
<Button asChild className="items-center px-8 md:ms-6 md:w-fit" variant="secondary">
<Link href="/account/addresses">{t('cancel')}</Link>
</Button>
<Modal
Expand Down

0 comments on commit 053bca9

Please sign in to comment.