TorbatYar/frontend/modules/commercial/components/RecommendationsPanel.tsx
2026-07-28 20:39:10 +03:30

63 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import type { TenantRecommendationFeed } from "../adapters/tenant-recommendations";
import type { AdapterResult } from "../types";
import { CommercialEmptyState } from "./CommercialEmptyState";
function RecList({
title,
items,
}: {
title: string;
items?: Array<{ code: string; score?: number; reason?: string }>;
}) {
if (!items?.length) return null;
return (
<div>
<p className="text-xs font-semibold text-gray-500">{title}</p>
<ul className="mt-2 space-y-1">
{items.map((i) => (
<li
key={`${title}-${i.code}`}
className="rounded-lg border border-gray-100 bg-white px-3 py-2 text-sm"
>
<span className="font-mono text-xs text-secondary" dir="ltr">
{i.code}
</span>
{typeof i.score === "number" ? (
<span className="ms-2 text-[10px] text-primary">امتیاز {i.score}</span>
) : null}
{i.reason ? <p className="mt-0.5 text-xs text-gray-500">{i.reason}</p> : null}
</li>
))}
</ul>
</div>
);
}
export function RecommendationsPanel({
result,
}: {
result: AdapterResult<TenantRecommendationFeed> | null;
}) {
if (!result || result.availability !== "ready") {
return (
<CommercialEmptyState
title="پیشنهادها"
description={result?.message || "از recommendation API بارگذاری می‌شود."}
/>
);
}
const d = result.data;
return (
<div className="grid gap-4 sm:grid-cols-2">
<RecList title="محصولات پیشنهادی" items={d.recommended_products} />
<RecList title="باندل‌های پیشنهادی" items={d.recommended_bundles} />
<RecList title="سرویس‌های پیشنهادی" items={d.recommended_services} />
<RecList title="ارتقاهای پیشنهادی" items={d.recommended_upgrades} />
<RecList title="اتوماسیون پیشنهادی" items={d.recommended_automation_packs} />
<RecList title="افزونه‌های پیشنهادی" items={d.recommended_extensions} />
</div>
);
}