-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add delete address functionality for account
- Loading branch information
1 parent
53428a9
commit 3ff572e
Showing
8 changed files
with
178 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
Add delete address functionality for account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
apps/core/app/[locale]/(default)/account/[tab]/_actions/delete-address.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use server'; | ||
|
||
import { revalidatePath } from 'next/cache'; | ||
|
||
import { deleteCustomerAddress } from '~/client/mutations/delete-customer-address'; | ||
|
||
export const deleteAddress = async (addressId: number) => { | ||
try { | ||
const response = await deleteCustomerAddress(addressId); | ||
|
||
revalidatePath('/account/addresses', 'page'); | ||
|
||
if (response.errors.length === 0) { | ||
return { status: 'success', message: 'The address has been deleted' }; | ||
} | ||
|
||
return { | ||
status: 'error', | ||
message: response.errors.map((error) => error.message).join('\n'), | ||
}; | ||
} catch (error: unknown) { | ||
if (error instanceof Error) { | ||
return { | ||
status: 'error', | ||
message: error.message, | ||
}; | ||
} | ||
|
||
return { status: 'error', message: 'Unknown error' }; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
apps/core/app/[locale]/(default)/account/[tab]/_components/modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'use client'; | ||
|
||
import { Button } from '@bigcommerce/components/button'; | ||
import { | ||
Dialog, | ||
DialogAction, | ||
DialogCancel, | ||
DialogContent, | ||
DialogDescription, | ||
DialogOverlay, | ||
DialogPortal, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from '@bigcommerce/components/dialog'; | ||
import { X } from 'lucide-react'; | ||
import { MouseEventHandler, PropsWithChildren } from 'react'; | ||
|
||
interface Props extends PropsWithChildren { | ||
actionHandler?: MouseEventHandler<HTMLButtonElement>; | ||
title: string; | ||
descriptionText?: string; | ||
confirmationText?: string; | ||
abortText?: string; | ||
} | ||
|
||
export const Modal = ({ | ||
abortText = 'Cancel', | ||
actionHandler, | ||
confirmationText = 'OK', | ||
descriptionText, | ||
title, | ||
children, | ||
}: Props) => { | ||
return ( | ||
<Dialog> | ||
<DialogTrigger aria-controls="modal-content" asChild> | ||
{children} | ||
</DialogTrigger> | ||
<DialogPortal> | ||
<DialogOverlay /> | ||
<DialogContent id="modal-content"> | ||
<div className="flex justify-between gap-4 p-6"> | ||
<DialogTitle>{title}</DialogTitle> | ||
<DialogCancel asChild> | ||
<Button className="ms-auto w-min p-2" type="button" variant="subtle"> | ||
<X> | ||
<title>{abortText}</title> | ||
</X> | ||
</Button> | ||
</DialogCancel> | ||
</div> | ||
{Boolean(descriptionText) && <DialogDescription>{descriptionText}</DialogDescription>} | ||
<div className="flex flex-col gap-2 p-6 lg:flex-row"> | ||
<DialogAction asChild> | ||
<Button className="w-full lg:w-fit" onClick={actionHandler} variant="primary"> | ||
{confirmationText} | ||
</Button> | ||
</DialogAction> | ||
<DialogCancel asChild> | ||
<Button className="w-full lg:w-fit" variant="subtle"> | ||
{abortText} | ||
</Button> | ||
</DialogCancel> | ||
</div> | ||
</DialogContent> | ||
</DialogPortal> | ||
</Dialog> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters