Skip to content

Commit 4483e5c

Browse files
authored
Merge pull request #181 from Weaverse/fix/ui
fix(ui): refine product controls and card layouts
2 parents 0cf6d6e + fdad906 commit 4483e5c

18 files changed

Lines changed: 454 additions & 65 deletions

File tree

‎app/components/cart/cart-summary-actions.tsx‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useEffect, useId, useRef, useState } from "react";
66
import { useFetcher } from "react-router";
77
import type { CartApiQueryFragment } from "storefront-api.generated";
88
import { Button } from "~/components/button";
9+
import { CART_CODE_APPLY_ACTION } from "~/utils/cart-code";
910
import { getCartMutationError } from "~/utils/cart-error";
1011
import { cn } from "~/utils/cn";
1112
import { usePrefixPathWithLocale } from "~/utils/locale";
@@ -180,36 +181,30 @@ export function NoteDialog({
180181
);
181182
}
182183

183-
export function DiscountDialog({
184-
discountCodes = [],
185-
layout = "aside",
186-
}: {
187-
discountCodes: CartApiQueryFragment["discountCodes"];
188-
layout?: CartLayout;
189-
}) {
184+
export function DiscountDialog({ layout = "aside" }: { layout?: CartLayout }) {
190185
const { t } = useTranslation();
191186
const [code, setCode] = useState("");
192-
const fetcher = useFetcher();
187+
const fetcher = useFetcher<{ codeApplied?: boolean }>();
193188
const discountCodeId = useId();
194189
const cartRoute = usePrefixPathWithLocale("/cart");
195190
const submitted = Boolean(code && fetcher.state === "idle" && fetcher.data);
196-
const success = Boolean(
197-
submitted && discountCodes?.find((d) => d.code === code && d.applicable),
198-
);
191+
const success = Boolean(submitted && fetcher.data?.codeApplied);
199192
const error = submitted && !success;
200193

201194
function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
202195
event.preventDefault();
203196
const formData = new FormData(event.currentTarget);
204197
const discountCode = formData.get("discountCode") as string;
205198
if (discountCode) {
206-
const existingCodes = discountCodes.map((d) => d.code);
207-
const updatedCodes = [...existingCodes, discountCode];
208199
fetcher.submit(
209200
{
210201
[CartForm.INPUT_NAME]: JSON.stringify({
211-
action: CartForm.ACTIONS.DiscountCodesUpdate,
212-
inputs: { discountCodes: updatedCodes },
202+
action: CART_CODE_APPLY_ACTION,
203+
inputs: {
204+
code: discountCode,
205+
allowDiscountCode: true,
206+
allowGiftCard: false,
207+
},
213208
}),
214209
},
215210
{ method: "POST", action: cartRoute },

‎app/components/cart/cart-summary.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ function CartAsideSummary({ cart }: { cart: CartWithOptimistic }) {
473473
{discountCodeButtonText || t("cart.discountCode")}
474474
</button>
475475
</Dialog.Trigger>
476-
<DiscountDialog discountCodes={discountCodes} layout="aside" />
476+
<DiscountDialog layout="aside" />
477477
</Dialog.Root>
478478
)}
479479
{enableDiscountCode && enableGiftCard && (
@@ -694,7 +694,7 @@ function PageCartCodeForm({
694694
<button
695695
type="submit"
696696
disabled={!code.trim() || isSubmitting}
697-
className="rounded-xl bg-text-primary px-6 py-3 font-body text-base leading-[160%] font-semibold tracking-[-0.16px] text-text-inverse disabled:cursor-not-allowed disabled:opacity-50"
697+
className="h-13.5 rounded-xl bg-text-primary px-6 py-3.5 font-body text-base leading-[160%] font-semibold tracking-[-0.16px] text-text-inverse disabled:cursor-not-allowed disabled:opacity-50"
698698
>
699699
{t("cart.apply")}
700700
</button>

‎app/components/cart/cart-types.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export type CartWithOptimistic = CartApiQueryFragment & {
1313
export type CartMutationResponse = {
1414
cart?: CartApiQueryFragment | null;
1515
errors?: Array<{ message?: string }>;
16-
userErrors?: Array<{ message?: string }>;
16+
userErrors?: Array<{
17+
code?: string | null;
18+
field?: string[] | null;
19+
message?: string;
20+
}>;
1721
warnings?: Array<{ code?: string; message?: string; target?: string }>;
1822
};

‎app/components/cart/cart.tsx‎

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Link } from "~/components/link";
77
import {
88
getCartMutationError,
99
getCartMutationWarning,
10+
getCartQuantityError,
1011
getCartQuantityWarning,
1112
} from "~/utils/cart-error";
1213
import { cn } from "~/utils/cn";
@@ -315,7 +316,7 @@ function CartLineItem({
315316
to={lineItemUrl}
316317
prefetch="intent"
317318
onClick={onClose}
318-
className="size-26 shrink-0 overflow-hidden rounded-sm"
319+
className="size-26 shrink-0 self-start overflow-hidden rounded-sm"
319320
>
320321
<Image
321322
alt={merchandise.product.title}
@@ -462,7 +463,7 @@ function CartLineQuantity({
462463
const updateWarning = useCartStore((state) =>
463464
state.lineUpdateWarnings.get(lineId),
464465
);
465-
const errorMessage = getCartMutationError(updateError);
466+
const errorMessage = getCartQuantityError(updateError);
466467
const warningMessage = getCartQuantityWarning(
467468
updateWarning,
468469
t("cart.outOfPurchaseLimit"),
@@ -538,16 +539,13 @@ function CartLineQuantity({
538539
<fieldset
539540
aria-label={`${t("product.quantity")}, ${optimisticQuantity}`}
540541
className={cn(
541-
"flex w-fit items-center border border-border rounded-2xl h-10",
542-
layout === "page" && "gap-2 bg-background-basic md:row-start-2",
542+
"flex h-10 w-fit items-center gap-1 rounded-2xl border border-border bg-background-basic",
543+
layout === "page" && "md:row-start-2",
543544
)}
544545
>
545546
<button
546547
type="button"
547-
className={cn(
548-
"flex items-center justify-center disabled:cursor-not-allowed disabled:opacity-50",
549-
layout === "aside" ? "size-10" : "h-10 w-11",
550-
)}
548+
className="flex h-10 shrink-0 items-center justify-center px-3.5 py-2.5 disabled:cursor-not-allowed disabled:opacity-50"
551549
aria-label={t("product.decreaseQuantity")}
552550
disabled={
553551
getValidInputQuantity() <= 1 || isOptimistic || isQuantityUpdating
@@ -556,17 +554,16 @@ function CartLineQuantity({
556554
onMouseDown={(event) => event.preventDefault()}
557555
onClick={() => stepQuantity(-1)}
558556
>
559-
<span className="translate-y-px">&#8722;</span>
557+
<span className="flex size-4 items-center justify-center leading-none">
558+
&#8722;
559+
</span>
560560
</button>
561561
<input
562562
type="text"
563563
inputMode="numeric"
564564
pattern="[0-9]*"
565565
aria-label={t("product.quantity")}
566-
className={cn(
567-
"translate-y-px appearance-none border-0 bg-transparent p-0 text-center font-body text-sm leading-none font-normal tracking-[-0.14px] text-text outline-none focus:ring-0 disabled:cursor-not-allowed",
568-
layout === "aside" ? "w-8 min-w-8" : "w-[26px] min-w-[26px]",
569-
)}
566+
className="field-sizing-content h-10 min-w-7 max-w-12 appearance-none border-0 bg-transparent p-0 text-center font-body !text-[14px] leading-none font-normal tracking-[-0.14px] text-text outline-none focus:ring-0 disabled:cursor-not-allowed"
570567
value={quantityInput}
571568
disabled={isOptimistic || isQuantityUpdating}
572569
onChange={(event) => {
@@ -587,17 +584,16 @@ function CartLineQuantity({
587584
/>
588585
<button
589586
type="button"
590-
className={cn(
591-
"flex items-center justify-center disabled:cursor-not-allowed disabled:opacity-50",
592-
layout === "aside" ? "size-10" : "h-10 w-11",
593-
)}
587+
className="flex h-10 shrink-0 items-center justify-center px-3.5 py-2.5 disabled:cursor-not-allowed disabled:opacity-50"
594588
aria-label={t("product.increaseQuantity")}
595589
disabled={isOptimistic || isQuantityUpdating}
596590
name="increase-quantity"
597591
onMouseDown={(event) => event.preventDefault()}
598592
onClick={() => stepQuantity(1)}
599593
>
600-
<span className="translate-y-px">&#43;</span>
594+
<span className="flex size-4 items-center justify-center leading-none">
595+
&#43;
596+
</span>
601597
</button>
602598
</fieldset>
603599
{quantityMessage && (

‎app/components/layout/predictive-search/PredictiveSearch/SearchDrawer/search-type-drawer-results.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function SearchTypeDrawerResults() {
7777
to={`/search?q=${encodeURIComponent(term)}`}
7878
size="sm"
7979
variant="primary"
80-
className="px-5 text-sm"
80+
className="h-13.5 px-5 text-sm"
8181
>
8282
{t("search.viewAll")} ({totalResults})
8383
</Button>

‎app/components/product-form/pdp-form.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function ProductQuantityInput({
107107
return (
108108
<div
109109
className={cn(
110-
"flex h-12 items-center overflow-hidden rounded-xl border border-border bg-background-basic",
110+
"flex h-13.5 items-center overflow-hidden rounded-xl border border-border bg-background-basic",
111111
className,
112112
)}
113113
>

‎app/components/product/add-to-cart-button.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function AddToCartContent({
140140
as="button"
141141
type="submit"
142142
size="lg"
143-
className={cn("h-14 px-6 py-3.5 text-base", className)}
143+
className={cn("h-13.5 px-6 py-3.5 text-base", className)}
144144
disabled={Boolean(disabled || isAdding || !hasValidLines)}
145145
loading={fetcher.state === "submitting"}
146146
variant={variant}

‎app/components/product/quick-view.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export function QuickView({
209209
}
210210
onAdded={onClose}
211211
data-test="add-to-cart"
212-
className="h-12 w-full rounded-xl"
212+
className="w-full rounded-xl"
213213
>
214214
<span>{atcText}</span>
215215
</AddToCartButton>

‎app/sections/blogs/index.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ const Blogs = ({
170170
/>
171171
</div>
172172
)}
173-
<div className="flex w-full flex-col gap-4 px-5 py-6">
173+
<div className="flex w-full flex-1 flex-col gap-4 px-5 py-6">
174174
<div className="flex min-h-5 items-center">
175175
{idx.tags[0] && (
176176
<span className="line-clamp-1 w-fit max-w-full rounded-full bg-background-subtle-2 px-3 py-1 text-xs leading-none text-text-subtle">
@@ -181,7 +181,7 @@ const Blogs = ({
181181

182182
<Tag
183183
className={cn(
184-
"line-clamp-2 min-h-[2lh]",
184+
"line-clamp-3 flex-1",
185185
size === "custom" &&
186186
fontSizeVariants({ mobileSize, desktopSize }),
187187
variants({ size, weight }),

‎app/sections/collection-list/collection-card.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ export function CollectionCard({
5454
</div>
5555
</div>
5656
<div className="absolute inset-0 z-10 flex items-center justify-center rounded-md">
57-
<h3 className="group-hover:underline text-white font-medium">
57+
<h6 className="text-center font-heading text-[26px] leading-[110%] font-normal text-text-inverse group-hover:underline">
5858
{collection.title}
59-
</h3>
59+
</h6>
6060
</div>
6161
<div className="absolute inset-0 rounded-md bg-[var(--calculate-color)] opacity-30 transition-opacity duration-500 group-hover:opacity-50" />
6262
</Link>

0 commit comments

Comments
 (0)