Skip to content

Commit

Permalink
fix(core): improve redirect behavior after creating new address
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-yevhenii-buliuk committed Jul 23, 2024
1 parent 0812027 commit 7d9b34e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,8 @@ export const AddAddress = ({
const submit = await addAddress({ formData, reCaptchaToken });

if (submit.status === 'success') {
form.current?.reset();
setFormStatus({
status: 'success',
message: t('successMessage'),
});

setTimeout(() => {
router.replace('/account/addresses');
}, 3000);
router.push('/account/addresses?newaddress=true');
return;
}

if (submit.status === 'error') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { AddressBook } from './address-book';
import { CustomerEditAddress } from './customer-edit-address';
import { CustomerNewAddress } from './customer-new-address';

import { Message } from '~/components/ui/message';

type CustomerAddresses = NonNullable<Awaited<ReturnType<typeof getCustomerAddresses>>>;

interface Props {
Expand All @@ -17,6 +19,7 @@ interface Props {
addressesCount: number;
customerAction?: 'add-new-address' | 'edit-address';
pageInfo: CustomerAddresses['pageInfo'];
isNewAddress?: boolean;
}

export const AddressesContent = async ({
Expand All @@ -25,9 +28,11 @@ export const AddressesContent = async ({
activeAddressId,
customerAction,
pageInfo,
isNewAddress,
}: Props) => {
const locale = await getLocale();
const t = await getTranslations({ locale, namespace: 'Account.Home' });
const t2 = await getTranslations({ locale, namespace: 'Account.Addresses' });
const tPagination = await getTranslations({ locale, namespace: 'Pagination' });
const { hasNextPage, hasPreviousPage, startCursor, endCursor } = pageInfo;

Expand Down Expand Up @@ -58,6 +63,13 @@ export const AddressesContent = async ({
return (
<>
<TabHeading heading="addresses" />

{isNewAddress && (
<Message className="col-span-full mb-8 w-full text-gray-500" variant="success">
<p>{t2('addNewAddressSuccessMessage')}</p>
</Message>
)}

<AddressBook addressesCount={addressesCount} customerAddresses={addresses} key={endCursor}>
<Pagination
className="my-0 flex inline-flex justify-center text-center"
Expand Down
3 changes: 3 additions & 0 deletions core/app/[locale]/(default)/account/[tab]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface Props {
action?: 'add-new-address' | 'edit-address';
before?: string;
after?: string;
newaddress?: string;
};
}

Expand All @@ -42,6 +43,7 @@ export default async function AccountTabPage({ params: { tab }, searchParams }:

case 'addresses': {
const { before, after, action } = searchParams;
const isNewAddress = searchParams?.newaddress?.toLowerCase() === 'true';
const customerAddressesDetails = await getCustomerAddresses({
...(after && { after }),
...(before && { before }),
Expand All @@ -61,6 +63,7 @@ export default async function AccountTabPage({ params: { tab }, searchParams }:
addressesCount={addressesCount}
customerAction={action}
pageInfo={pageInfo}
isNewAddress={isNewAddress}
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions core/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
"defaultAddress": "Default",
"alternativeAddress": "Alternative",
"addNewAddress": "Add new address",
"addNewAddressSuccessMessage": "Address added to your account",
"editButton": "Edit",
"deleteButton": "Delete",
"confirmDeleteAddress": "Delete address",
Expand Down

0 comments on commit 7d9b34e

Please sign in to comment.