-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-address-mutation
- Loading branch information
Showing
40 changed files
with
957 additions
and
203 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 | ||
--- | ||
|
||
Apply the edge runtime to missing routes. |
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 update customer mutation |
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/create-catalyst": minor | ||
--- | ||
|
||
Adds the `.vscode/settings.json` file pointing to the correct typescript sdk for gql-tada support. |
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 | ||
--- | ||
|
||
use LRU cache for DevKvAdapter |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
add loading state on item quantity update and remove when quantity equals 0 |
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,6 @@ | ||
--- | ||
"@bigcommerce/components": minor | ||
"@bigcommerce/docs": minor | ||
--- | ||
|
||
Add dialog component |
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 |
---|---|---|
|
@@ -12,3 +12,4 @@ test-results/ | |
playwright-report/ | ||
playwright/.cache/ | ||
graphql-env.d.ts | ||
.DS_Store |
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
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('addNewAddress')} asChild className="w-fit hover:text-white"> | ||
<Link href="/account/add-new-address">{t('addNewAddress')}</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
45 changes: 45 additions & 0 deletions
45
apps/core/app/[locale]/(default)/cart/_actions/remove-item.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,45 @@ | ||
'use server'; | ||
|
||
import { revalidateTag } from 'next/cache'; | ||
import { cookies } from 'next/headers'; | ||
|
||
import { graphql } from '~/client/graphql'; | ||
import { deleteCartLineItem } from '~/client/mutations/delete-cart-line-item'; | ||
|
||
type DeleteCartLineItemInput = ReturnType<typeof graphql.scalar<'DeleteCartLineItemInput'>>; | ||
|
||
export async function removeItem({ | ||
lineItemEntityId, | ||
}: Omit<DeleteCartLineItemInput, 'cartEntityId'>) { | ||
try { | ||
const cartId = cookies().get('cartId')?.value; | ||
|
||
if (!cartId) { | ||
return { status: 'error', error: 'No cartId cookie found' }; | ||
} | ||
|
||
if (!lineItemEntityId) { | ||
return { status: 'error', error: 'No lineItemEntityId found' }; | ||
} | ||
|
||
const updatedCart = await deleteCartLineItem(cartId, lineItemEntityId); | ||
|
||
// If we remove the last item in a cart the cart is deleted | ||
// so we need to remove the cartId cookie and clear shipping data | ||
if (!updatedCart) { | ||
cookies().delete('cartId'); | ||
cookies().delete('shippingCosts'); | ||
revalidateTag('cart'); | ||
} | ||
|
||
revalidateTag('cart'); | ||
|
||
return { status: 'success', data: updatedCart }; | ||
} catch (e: unknown) { | ||
if (e instanceof Error) { | ||
return { status: 'error', error: e.message }; | ||
} | ||
|
||
return { status: 'error' }; | ||
} | ||
} |
32 changes: 0 additions & 32 deletions
32
apps/core/app/[locale]/(default)/cart/_actions/remove-products.ts
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
apps/core/app/[locale]/(default)/cart/_actions/update-item-quantity.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,66 @@ | ||
'use server'; | ||
|
||
import { revalidatePath } from 'next/cache'; | ||
import { cookies } from 'next/headers'; | ||
|
||
import { graphql } from '~/client/graphql'; | ||
import { updateCartLineItem } from '~/client/mutations/update-cart-line-item'; | ||
|
||
import { removeItem } from './remove-item'; | ||
|
||
type CartLineItemInput = ReturnType<typeof graphql.scalar<'CartLineItemInput'>>; | ||
type UpdateCartLineItemInput = ReturnType<typeof graphql.scalar<'UpdateCartLineItemInput'>>; | ||
|
||
interface UpdateProductQuantityParams extends CartLineItemInput { | ||
lineItemEntityId: UpdateCartLineItemInput['lineItemEntityId']; | ||
} | ||
|
||
export async function updateItemQuantity({ | ||
lineItemEntityId, | ||
productEntityId, | ||
quantity, | ||
variantEntityId, | ||
selectedOptions, | ||
}: UpdateProductQuantityParams) { | ||
try { | ||
const cartId = cookies().get('cartId')?.value; | ||
|
||
if (!cartId) { | ||
return { status: 'error', error: 'No cartId cookie found' }; | ||
} | ||
|
||
if (!lineItemEntityId) { | ||
return { status: 'error', error: 'No lineItemEntityId found' }; | ||
} | ||
|
||
if (quantity === 0) { | ||
const result = await removeItem({ lineItemEntityId }); | ||
|
||
return result; | ||
} | ||
|
||
const cartLineItemData = Object.assign( | ||
{ quantity, productEntityId }, | ||
variantEntityId && { variantEntityId }, | ||
selectedOptions && { selectedOptions }, | ||
); | ||
|
||
const updatedCart = await updateCartLineItem(cartId, lineItemEntityId, { | ||
lineItem: cartLineItemData, | ||
}); | ||
|
||
if (!updatedCart) { | ||
return { status: 'error', error: 'Failed to change product quantity in Cart' }; | ||
} | ||
|
||
revalidatePath('/cart'); | ||
|
||
return { status: 'success', data: updatedCart }; | ||
} catch (e: unknown) { | ||
if (e instanceof Error) { | ||
return { status: 'error', error: e.message }; | ||
} | ||
|
||
return { status: 'error' }; | ||
} | ||
} |
Oops, something went wrong.