mirror of
https://git.meshkee.com/BaloutPastry/dashboards.git
synced 2026-08-11 22:30:59 +04:30
90 lines
1.8 KiB
TypeScript
90 lines
1.8 KiB
TypeScript
export type SellUnit = 'unit' | 'kilo'
|
|
|
|
export type ProductCategoryRef = {
|
|
id: string
|
|
nameFa: string
|
|
nameEn: string
|
|
parentId?: string | null
|
|
}
|
|
|
|
export type ProductOptionValue = {
|
|
id: string
|
|
flavorId: string
|
|
amount: string
|
|
price: number
|
|
flavor?: {
|
|
id: string
|
|
nameFa: string
|
|
nameEn: string
|
|
}
|
|
}
|
|
|
|
export type ProductGalleryImage = {
|
|
id?: string
|
|
url: string
|
|
storageKey: string
|
|
sortOrder?: number
|
|
}
|
|
|
|
export type Product = {
|
|
id: string
|
|
nameFa: string
|
|
nameEn: string
|
|
price: number
|
|
sellUnit: SellUnit
|
|
categoryId: string
|
|
category: ProductCategoryRef
|
|
intro?: string
|
|
description?: string
|
|
tags?: string[]
|
|
mainImageUrl: string | null
|
|
mainImageKey?: string | null
|
|
gallery?: ProductGalleryImage[]
|
|
options: ProductOptionValue[]
|
|
}
|
|
|
|
export const productImagePlaceholder =
|
|
'data:image/svg+xml,' +
|
|
encodeURIComponent(
|
|
`<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400" viewBox="0 0 400 400">
|
|
<rect width="400" height="400" fill="#f3ebe3"/>
|
|
<text x="200" y="210" text-anchor="middle" fill="#b08a6a" font-family="sans-serif" font-size="28">محصول</text>
|
|
</svg>`,
|
|
)
|
|
|
|
function optionId() {
|
|
return `${Date.now()}-${Math.random().toString(36).slice(2, 7)}`
|
|
}
|
|
|
|
export function createProductOptionValue(
|
|
flavorId: string,
|
|
amount: string,
|
|
price: number,
|
|
): ProductOptionValue {
|
|
return {
|
|
id: optionId(),
|
|
flavorId,
|
|
amount,
|
|
price,
|
|
}
|
|
}
|
|
|
|
const sellUnitLabel: Record<SellUnit, string> = {
|
|
unit: 'واحد',
|
|
kilo: 'کیلو',
|
|
}
|
|
|
|
export function formatPriceParts(product: Product): {
|
|
amount: string
|
|
label: string
|
|
} {
|
|
return {
|
|
amount: product.price.toLocaleString('fa-IR'),
|
|
label: `تومان - ${sellUnitLabel[product.sellUnit]}`,
|
|
}
|
|
}
|
|
|
|
export function productImageSrc(product: Product) {
|
|
return product.mainImageUrl || productImagePlaceholder
|
|
}
|