improve order analyses cards
This commit is contained in:
@@ -21,7 +21,6 @@ import { formatCurrency } from '@/packages/shared/src/utils';
|
|||||||
export type OrderAnalysisCard = Pick<
|
export type OrderAnalysisCard = Pick<
|
||||||
StoreProduct, 'title' | 'description' | 'subtitle'
|
StoreProduct, 'title' | 'description' | 'subtitle'
|
||||||
> & {
|
> & {
|
||||||
isAvailable: boolean;
|
|
||||||
variant: { id: string };
|
variant: { id: string };
|
||||||
price: number | null;
|
price: number | null;
|
||||||
};
|
};
|
||||||
@@ -64,7 +63,6 @@ export default function OrderAnalysesCards({
|
|||||||
variant,
|
variant,
|
||||||
description,
|
description,
|
||||||
subtitle,
|
subtitle,
|
||||||
isAvailable,
|
|
||||||
price,
|
price,
|
||||||
}) => {
|
}) => {
|
||||||
const formattedPrice = typeof price === 'number'
|
const formattedPrice = typeof price === 'number'
|
||||||
@@ -77,7 +75,7 @@ export default function OrderAnalysesCards({
|
|||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
key={title}
|
key={title}
|
||||||
variant={isAvailable ? "gradient-success" : "gradient-warning"}
|
variant="gradient-success"
|
||||||
className="flex flex-col justify-between"
|
className="flex flex-col justify-between"
|
||||||
>
|
>
|
||||||
<CardHeader className="flex-row">
|
<CardHeader className="flex-row">
|
||||||
@@ -86,46 +84,44 @@ export default function OrderAnalysesCards({
|
|||||||
>
|
>
|
||||||
<HeartPulse className="size-4 fill-green-500" />
|
<HeartPulse className="size-4 fill-green-500" />
|
||||||
</div>
|
</div>
|
||||||
{isAvailable && (
|
<div className='ml-auto flex size-8 items-center-safe justify-center-safe rounded-full text-white bg-warning'>
|
||||||
<div className='ml-auto flex size-8 items-center-safe justify-center-safe rounded-full text-white bg-warning'>
|
<Button
|
||||||
<Button
|
size="icon"
|
||||||
size="icon"
|
variant="outline"
|
||||||
variant="outline"
|
className="px-2 text-black"
|
||||||
className="px-2 text-black"
|
onClick={() => handleSelect(variant.id)}
|
||||||
onClick={() => handleSelect(variant.id)}
|
>
|
||||||
>
|
{variantAddingToCart === variant.id ? <Loader2 className="size-4 stroke-2 animate-spin" /> : <ShoppingCart className="size-4 stroke-2" />}
|
||||||
{variantAddingToCart === variant.id ? <Loader2 className="size-4 stroke-2 animate-spin" /> : <ShoppingCart className="size-4 stroke-2" />}
|
</Button>
|
||||||
</Button>
|
</div>
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardFooter className="flex flex-col items-start gap-2">
|
<CardFooter className="flex gap-2">
|
||||||
<h5>
|
<div className="flex flex-col items-start gap-2 flex-1">
|
||||||
{title}
|
<h5>
|
||||||
{description && (
|
{title}
|
||||||
<>
|
{description && (
|
||||||
{' '}
|
<>
|
||||||
<InfoTooltip
|
{' '}
|
||||||
content={
|
<InfoTooltip
|
||||||
<div className='flex flex-col gap-2'>
|
content={
|
||||||
<span>{formattedPrice}</span>
|
<div className='flex flex-col gap-2'>
|
||||||
<span>{description}</span>
|
<span>{formattedPrice}</span>
|
||||||
</div>
|
<span>{description}</span>
|
||||||
}
|
</div>
|
||||||
/>
|
}
|
||||||
</>
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</h5>
|
||||||
|
{subtitle && (
|
||||||
|
<CardDescription>
|
||||||
|
{subtitle}
|
||||||
|
</CardDescription>
|
||||||
)}
|
)}
|
||||||
</h5>
|
</div>
|
||||||
{isAvailable && subtitle && (
|
<div className="flex flex-col items-end gap-2 self-end text-sm">
|
||||||
<CardDescription>
|
<span>{formattedPrice}</span>
|
||||||
{subtitle}
|
</div>
|
||||||
</CardDescription>
|
|
||||||
)}
|
|
||||||
{!isAvailable && (
|
|
||||||
<CardDescription>
|
|
||||||
<Trans i18nKey={'order-analysis:analysisNotAvailable'} />
|
|
||||||
</CardDescription>
|
|
||||||
)}
|
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ async function analysesLoader() {
|
|||||||
const categoryProducts = category
|
const categoryProducts = category
|
||||||
? await listProducts({
|
? await listProducts({
|
||||||
countryCode,
|
countryCode,
|
||||||
queryParams: { limit: 100, category_id: category.id },
|
queryParams: { limit: 100, category_id: category.id, order: 'title' },
|
||||||
})
|
})
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
@@ -51,8 +51,10 @@ async function analysesLoader() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
analyses:
|
analyses:
|
||||||
categoryProducts?.response.products.map<OrderAnalysisCard>(
|
categoryProducts?.response.products
|
||||||
({ title, description, subtitle, variants, status, metadata }) => {
|
.filter(({ status, metadata }) => status === 'published' && !!metadata?.analysisIdOriginal)
|
||||||
|
.map<OrderAnalysisCard>(
|
||||||
|
({ title, description, subtitle, variants }) => {
|
||||||
const variant = variants![0]!;
|
const variant = variants![0]!;
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
@@ -61,8 +63,6 @@ async function analysesLoader() {
|
|||||||
variant: {
|
variant: {
|
||||||
id: variant.id,
|
id: variant.id,
|
||||||
},
|
},
|
||||||
isAvailable:
|
|
||||||
status === 'published' && !!metadata?.analysisIdOriginal,
|
|
||||||
price: variant.calculated_price?.calculated_amount ?? null,
|
price: variant.calculated_price?.calculated_amount ?? null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"title": "Select analysis",
|
"title": "Select analysis",
|
||||||
"description": "All analysis results will appear within 1-3 days after the blood test.",
|
"description": "All analysis results will appear within 1-3 days after the blood test.",
|
||||||
"analysisNotAvailable": "Analysis is not available currently",
|
|
||||||
"analysisAddedToCart": "Analysis added to cart",
|
"analysisAddedToCart": "Analysis added to cart",
|
||||||
"analysisAddToCartError": "Adding analysis to cart failed"
|
"analysisAddToCartError": "Adding analysis to cart failed"
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"title": "Vali analüüs",
|
"title": "Vali analüüs",
|
||||||
"description": "Kõikide analüüside tulemused ilmuvad 1–3 tööpäeva jooksul peale vere andmist.",
|
"description": "Kõikide analüüside tulemused ilmuvad 1–3 tööpäeva jooksul peale vere andmist.",
|
||||||
"analysisNotAvailable": "Analüüsi tellimine ei ole hetkel saadaval",
|
|
||||||
"analysisAddedToCart": "Analüüs lisatud ostukorvi",
|
"analysisAddedToCart": "Analüüs lisatud ostukorvi",
|
||||||
"analysisAddToCartError": "Analüüsi lisamine ostukorvi ebaõnnestus"
|
"analysisAddToCartError": "Analüüsi lisamine ostukorvi ebaõnnestus"
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"title": "Выберите анализ",
|
"title": "Выберите анализ",
|
||||||
"description": "Результаты всех анализов будут доступны в течение 1–3 рабочих дней после сдачи крови.",
|
"description": "Результаты всех анализов будут доступны в течение 1–3 рабочих дней после сдачи крови.",
|
||||||
"analysisNotAvailable": "Заказ анализа в данный момент недоступен",
|
|
||||||
"analysisAddedToCart": "Анализ добавлен в корзину",
|
"analysisAddedToCart": "Анализ добавлен в корзину",
|
||||||
"analysisAddToCartError": "Не удалось добавить анализ в корзину"
|
"analysisAddToCartError": "Не удалось добавить анализ в корзину"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user