Skip to content

Commit

Permalink
feat: add minimumAddressCount to address list
Browse files Browse the repository at this point in the history
  • Loading branch information
chanceaclark committed Dec 18, 2024
1 parent fd05ea8 commit 7e4ffb7
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions apps/web/vibes/soul/sections/address-list-section/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface State<A extends Address> {
interface Props<A extends Address> {
title?: string;
addresses: A[];
minimumAddressCount?: number;
defaultAddress?: DefaultAddressConfiguration;
addressAction: Action<State<A>, FormData>;
editLabel?: string;
Expand All @@ -54,6 +55,7 @@ interface Props<A extends Address> {
export function AddressListSection<A extends Address>({
title = 'Addresses',
addresses,
minimumAddressCount = 1,
defaultAddress,
addressAction,
editLabel = 'Edit',
Expand Down Expand Up @@ -226,20 +228,23 @@ export function AddressListSection<A extends Address>({
>
{editLabel}
</Button>
<AddressActionButton
action={formAction}
address={address}
aria-label={`${deleteLabel}: ${address.firstName} ${address.lastName}`}
intent="delete"
onSubmit={(formData) => {
startTransition(() => {
formAction(formData);
setOptimisticState(formData);
});
}}
>
{deleteLabel}
</AddressActionButton>
{optimisticState.addresses.length > minimumAddressCount && (
<AddressActionButton
action={formAction}
address={address}
aria-label={`${deleteLabel}: ${address.firstName} ${address.lastName}`}
intent="delete"
onSubmit={(formData) => {
startTransition(() => {
formAction(formData);
setOptimisticState(formData);
});
}}
>
{deleteLabel}
</AddressActionButton>
)}

{optimisticState.defaultAddress &&
optimisticState.defaultAddress.id !== address.id && (
<AddressActionButton
Expand Down

0 comments on commit 7e4ffb7

Please sign in to comment.