+
-
-
- {lineItem.title}
- {lineItem.subtitle}
-
-
{
- startTransition(() => {
- formAction(formData);
- setOptimisticLineItems(formData);
- });
- }}
- />
+
-
- ))}
-
-
-
- );
-}
-
-function CounterForm({
- lineItem,
- action,
- onSubmit,
- incrementLabel = 'Increase count',
- decrementLabel = 'Decrease count',
- deleteLabel = 'Remove item',
-}: {
- lineItem: CartLineItem;
- incrementLabel?: string;
- decrementLabel?: string;
- deleteLabel?: string;
- action: (payload: FormData) => void;
- onSubmit: (formData: FormData) => void;
-}) {
- const [form, fields] = useForm({
- defaultValue: { id: lineItem.id },
- shouldValidate: 'onBlur',
- shouldRevalidate: 'onInput',
- onValidate({ formData }) {
- return parseWithZod(formData, { schema: cartLineItemActionFormDataSchema });
- },
- onSubmit(event, { formData }) {
- event.preventDefault();
-
- onSubmit(formData);
- },
- });
-
- return (
-
- );
-}
-
-function CheckoutButton({
- action,
- ...rest
-}: { action: Action
} & React.ComponentPropsWithoutRef<
- typeof Button
->) {
- const [lastResult, formAction] = useActionState(action, null);
-
- useEffect(() => {
- if (lastResult?.error) {
- console.log(lastResult.error);
- }
- }, [lastResult?.error]);
-
- return (
-
- );
-}
-
-function SubmitButton(props: React.ComponentPropsWithoutRef) {
- const { pending } = useFormStatus();
-
- return ;
-}
-
-export function CartEmptyState({ title, subtitle, cta }: CartEmptyState) {
- return (
-
-
-
- {title}
-
-
- {subtitle}
-
-
{cta.label}
-
-
- );
-}
-
-export function CartSkeleton({ title = 'Cart' }: { title?: string }) {
- return (
-
- {/* Summary Title */}
-
-
- {/* Subtotal */}
-
-
- {/* Shipping */}
-