-
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 customer addresses tab content
- Loading branch information
1 parent
ba44a5b
commit 0a002c7
Showing
6 changed files
with
148 additions
and
5 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": minor | ||
--- | ||
|
||
Add customer addresses tab content |
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
38 changes: 38 additions & 0 deletions
38
apps/core/app/[locale]/(default)/account/[tab]/_components/addresses-content.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,38 @@ | ||
import { getLocale, getTranslations } from 'next-intl/server'; | ||
|
||
import { getCustomerAddresses } from '~/client/queries/get-customer-addresses'; | ||
|
||
import { Pagination } from '../../../(faceted)/_components/pagination'; | ||
import { TabType } from '../layout'; | ||
import { tabHeading } from '../page'; | ||
|
||
import { AddressesList } from './addresses-list'; | ||
|
||
type CustomerAddresses = NonNullable<Awaited<ReturnType<typeof getCustomerAddresses>>>; | ||
|
||
interface Props { | ||
addresses: CustomerAddresses['addresses']; | ||
pageInfo: CustomerAddresses['pageInfo']; | ||
title: TabType; | ||
} | ||
|
||
export const AddressesContent = async ({ addresses, pageInfo, title }: Props) => { | ||
const locale = await getLocale(); | ||
const tPagination = await getTranslations({ locale, namespace: 'Pagination' }); | ||
const { hasNextPage, hasPreviousPage, startCursor, endCursor } = pageInfo; | ||
|
||
return ( | ||
<> | ||
{tabHeading(title, locale)} | ||
<AddressesList customerAddressBook={addresses} /> | ||
<Pagination | ||
endCursor={endCursor} | ||
hasNextPage={hasNextPage} | ||
hasPreviousPage={hasPreviousPage} | ||
nextLabel={tPagination('next')} | ||
prevLabel={tPagination('prev')} | ||
startCursor={startCursor} | ||
/> | ||
</> | ||
); | ||
}; |
71 changes: 71 additions & 0 deletions
71
apps/core/app/[locale]/(default)/account/[tab]/_components/addresses-list.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,71 @@ | ||
import { Button } from '@bigcommerce/components/button'; | ||
import { useTranslations } from 'next-intl'; | ||
|
||
import { getCustomerAddresses } from '~/client/queries/get-customer-addresses'; | ||
import { Link } from '~/components/link'; | ||
|
||
type Addresses = NonNullable<Awaited<ReturnType<typeof getCustomerAddresses>>>['addresses']; | ||
|
||
interface Props { | ||
customerAddressBook: Addresses; | ||
} | ||
|
||
const AddressChangeButtons = () => { | ||
const t = useTranslations('Account.Addresses'); | ||
|
||
return ( | ||
<div className="my-2 flex w-fit gap-x-2 divide-y-0"> | ||
<Button aria-label={t('editButton')} variant="secondary"> | ||
{t('editButton')} | ||
</Button> | ||
<Button aria-label={t('deleteButton')} variant="subtle"> | ||
{t('deleteButton')} | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export const AddressesList = ({ customerAddressBook }: Props) => { | ||
const t = useTranslations('Account.Addresses'); | ||
|
||
return ( | ||
<ul className="mb-12"> | ||
{customerAddressBook.map( | ||
({ | ||
entityId, | ||
firstName, | ||
lastName, | ||
address1, | ||
address2, | ||
city, | ||
stateOrProvince, | ||
postalCode, | ||
countryCode, | ||
}) => ( | ||
<li | ||
className="flex w-full border-collapse flex-col justify-start gap-2 border-t border-gray-200 pb-3 pt-5" | ||
key={entityId} | ||
> | ||
<div className="inline-flex flex-col justify-start text-base"> | ||
<p> | ||
{firstName} {lastName} | ||
</p> | ||
<p>{address1}</p> | ||
{Boolean(address2) && <p>{address2}</p>} | ||
<p> | ||
{city}, {stateOrProvince} {postalCode} | ||
</p> | ||
<p>{countryCode}</p> | ||
</div> | ||
<AddressChangeButtons /> | ||
</li> | ||
), | ||
)} | ||
<li className="flex w-full border-collapse flex-col justify-start gap-2 border-t border-gray-200 pt-8"> | ||
<Button aria-label={t('addNewAddressButton')} asChild className="w-fit hover:text-white"> | ||
<Link href="/account/add-new-address">{t('addNewAddressButton')}</Link> | ||
</Button> | ||
</li> | ||
</ul> | ||
); | ||
}; |
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