Skip to content

Commit

Permalink
Fixes currency code not showing on product detail page and in cart (v…
Browse files Browse the repository at this point in the history
  • Loading branch information
manovotny authored Jul 25, 2023
1 parent 59fc2bc commit 37d7522
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions components/cart/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ export default function CartModal({ cart }: { cart: Cart | undefined }) {
{item.merchandise.product.title}
</span>
{item.merchandise.title !== DEFAULT_OPTION ? (
<p className="text-sm text-neutral-800">
<p className="text-sm text-neutral-400 dark:text-neutral-600">
{item.merchandise.title}
</p>
) : null}
</div>
</Link>
<div className="flex h-16 flex-col justify-between">
<Price
className="flex flex-col justify-between space-y-2 text-sm"
className="flex justify-end space-y-2 text-right text-sm"
amount={item.cost.totalAmount.amount}
currencyCode={item.cost.totalAmount.currencyCode}
/>
Expand Down
1 change: 1 addition & 0 deletions components/label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Label = ({
className="flex-none rounded-full bg-blue-600 p-2 text-white"
amount={amount}
currencyCode={currencyCode}
currencyCodeClassName="hidden @[275px]/label:inline"
/>
</div>
</div>
Expand Down
11 changes: 8 additions & 3 deletions components/price.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import clsx from 'clsx';

const Price = ({
amount,
className,
currencyCode = 'USD',
...props
currencyCodeClassName
}: {
amount: string;
className?: string;
currencyCode: string;
currencyCodeClassName?: string;
} & React.ComponentProps<'p'>) => (
<p suppressHydrationWarning={true} {...props}>
<p suppressHydrationWarning={true} className={className}>
{`${new Intl.NumberFormat(undefined, {
style: 'currency',
currency: currencyCode,
currencyDisplay: 'narrowSymbol'
}).format(parseFloat(amount))}`}
<span className="hidden @[275px]/label:inline">{` ${currencyCode}`}</span>
<span className={clsx('ml-1 inline', currencyCodeClassName)}>{`${currencyCode}`}</span>
</p>
);

Expand Down

0 comments on commit 37d7522

Please sign in to comment.