-
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): remove quick add button from PLP (#1313)
* feat(core): remove quick add button from PLP * fix: update tests
- Loading branch information
Showing
43 changed files
with
134 additions
and
492 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 | ||
--- | ||
|
||
Remove "Quick add" button in PLP for products that have options. Will now just show a button that links to the product. |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
core/components/product-form/fragment.ts → ...lug]/_components/product-form/fragment.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
7 changes: 3 additions & 4 deletions
7
core/components/product-form/index.tsx → ...[slug]/_components/product-form/index.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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
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,72 @@ | ||
'use client'; | ||
|
||
import { FragmentOf } from 'gql.tada'; | ||
import { AlertCircle, Check } from 'lucide-react'; | ||
import { useTranslations } from 'next-intl'; | ||
import { useFormStatus } from 'react-dom'; | ||
import { toast } from 'react-hot-toast'; | ||
|
||
import { AddToCartButton } from '~/components/add-to-cart-button'; | ||
import { Link } from '~/components/link'; | ||
|
||
import { AddToCartFragment } from '../fragment'; | ||
|
||
import { addToCart } from './_actions/add-to-cart'; | ||
|
||
interface Props { | ||
data: FragmentOf<typeof AddToCartFragment>; | ||
} | ||
|
||
const SubmitButton = ({ data: product }: Props) => { | ||
const { pending } = useFormStatus(); | ||
|
||
return <AddToCartButton className="mt-2" data={product} loading={pending} />; | ||
}; | ||
|
||
export const Form = ({ data: product }: Props) => { | ||
const t = useTranslations('AddToCart'); | ||
|
||
return ( | ||
<form | ||
action={async (formData: FormData) => { | ||
const result = await addToCart(formData); | ||
const quantity = Number(formData.get('quantity')); | ||
|
||
if (result.error) { | ||
toast.error(t('errorAddingProductToCart'), { | ||
icon: <AlertCircle className="text-error-secondary" />, | ||
}); | ||
|
||
return; | ||
} | ||
|
||
toast.success( | ||
() => ( | ||
<div className="flex items-center gap-3"> | ||
<span> | ||
{t.rich('addedProductQuantity', { | ||
cartItems: quantity, | ||
cartLink: (chunks) => ( | ||
<Link | ||
className="font-semibold text-primary" | ||
href="/cart" | ||
prefetch="viewport" | ||
prefetchKind="full" | ||
> | ||
{chunks} | ||
</Link> | ||
), | ||
})} | ||
</span> | ||
</div> | ||
), | ||
{ icon: <Check className="text-success-secondary" /> }, | ||
); | ||
}} | ||
> | ||
<input name="product_id" type="hidden" value={product.entityId} /> | ||
<input name="quantity" type="hidden" value={1} /> | ||
<SubmitButton data={product} /> | ||
</form> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,30 @@ | ||
'use client'; | ||
|
||
import { removeEdgesAndNodes } from '@bigcommerce/catalyst-client'; | ||
import { AlertCircle, Check } from 'lucide-react'; | ||
import { usePathname, useSearchParams } from 'next/navigation'; | ||
import { useTranslations } from 'next-intl'; | ||
import { useFormStatus } from 'react-dom'; | ||
import { toast } from 'react-hot-toast'; | ||
import { getTranslations } from 'next-intl/server'; | ||
|
||
import { FragmentOf } from '~/client/graphql'; | ||
import { AddToCartButton } from '~/components/add-to-cart-button'; | ||
import { Button } from '~/components/ui/button'; | ||
|
||
import { Link } from '../../link'; | ||
import { addToCart } from '../_actions/add-to-cart'; | ||
|
||
import { Form } from './form'; | ||
import { AddToCartFragment } from './fragment'; | ||
|
||
interface Props { | ||
data: FragmentOf<typeof AddToCartFragment>; | ||
} | ||
|
||
const Submit = ({ data: product }: Props) => { | ||
const { pending } = useFormStatus(); | ||
|
||
return <AddToCartButton className="mt-2" data={product} loading={pending} />; | ||
}; | ||
|
||
export const AddToCart = ({ data: product }: Props) => { | ||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
|
||
const t = useTranslations('AddToCart'); | ||
|
||
const newSearchParams = new URLSearchParams(searchParams); | ||
|
||
newSearchParams.set('showQuickAdd', String(product.entityId)); | ||
export const AddToCart = async ({ data: product }: Props) => { | ||
const t = await getTranslations('AddToCart'); | ||
|
||
const productOptions = removeEdgesAndNodes(product.productOptions); | ||
|
||
return Array.isArray(productOptions) && productOptions.length > 0 ? ( | ||
<Button asChild> | ||
<Link | ||
className="mt-2 hover:text-white" | ||
href={`${pathname}?${newSearchParams.toString()}`} | ||
scroll={false} | ||
> | ||
{t('quickAdd')} | ||
<Link className="mt-2 hover:text-white" href={product.path}> | ||
{t('viewOptions')} | ||
</Link> | ||
</Button> | ||
) : ( | ||
<form | ||
action={async (formData: FormData) => { | ||
const result = await addToCart(formData); | ||
const quantity = Number(formData.get('quantity')); | ||
|
||
if (result.error) { | ||
toast.error(t('errorAddingProductToCart'), { | ||
icon: <AlertCircle className="text-error-secondary" />, | ||
}); | ||
|
||
return; | ||
} | ||
|
||
toast.success( | ||
() => ( | ||
<div className="flex items-center gap-3"> | ||
<span> | ||
{t.rich('addedProductQuantity', { | ||
cartItems: quantity, | ||
cartLink: (chunks) => ( | ||
<Link | ||
className="font-semibold text-primary" | ||
href="/cart" | ||
prefetch="viewport" | ||
prefetchKind="full" | ||
> | ||
{chunks} | ||
</Link> | ||
), | ||
})} | ||
</span> | ||
</div> | ||
), | ||
{ icon: <Check className="text-success-secondary" /> }, | ||
); | ||
}} | ||
> | ||
<input name="product_id" type="hidden" value={product.entityId} /> | ||
<input name="quantity" type="hidden" value={1} /> | ||
<Submit data={product} /> | ||
</form> | ||
<Form data={product} /> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.