Files
Suman/apps/suman-bosna/src/modules/common/components/line-item-price/index.tsx
Nermin Karic ada6fd857c design upgrade
2026-11-23 00:59:47 +01:00

65 lines
1.8 KiB
TypeScript

import { getPercentageDiff } from "@lib/util/get-percentage-diff"
import { convertToLocale } from "@lib/util/money"
import { HttpTypes } from "@medusajs/types"
import { clx } from "@modules/common/components/ui"
type LineItemPriceProps = {
item: HttpTypes.StoreCartLineItem | HttpTypes.StoreOrderLineItem
style?: "default" | "tight"
currencyCode: string
}
const LineItemPrice = ({
item,
style = "default",
currencyCode,
}: LineItemPriceProps) => {
const { total, original_total } = item
const originalPrice = original_total ?? 0
const currentPrice = total ?? 0
const hasReducedPrice = currentPrice < originalPrice
return (
<div className="flex flex-col gap-x-2 text-muted-foreground items-end">
<div className="text-left">
{hasReducedPrice && (
<>
<p>
{style === "default" && (
<span className="text-muted-foreground">Original: </span>
)}
<span
className="line-through text-muted-foreground"
data-testid="product-original-price"
>
{convertToLocale({
amount: originalPrice,
currency_code: currencyCode,
})}
</span>
</p>
{style === "default" && (
<span className="text-primary">
-{getPercentageDiff(originalPrice, currentPrice || 0)}%
</span>
)}
</>
)}
<span
className={clx("text-base", {
"text-primary": hasReducedPrice,
})}
data-testid="product-price"
>
{convertToLocale({
amount: currentPrice,
currency_code: currencyCode,
})}
</span>
</div>
</div>
)
}
export default LineItemPrice