update main dashboard ai insight view to show its loading instead of still showing old insight and data

This commit is contained in:
Alberto-Audrix committed 2026-10-13 10:47:19 +07:00
1 parent 0d34aa8557
commit fbf1b6261f
1 file changed
+61 -11
+61 -11
View File
@@ -663,6 +663,41 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
]);
const renderVisualBlock = () => {
if (loading) {
if (page !== 'dashboard') return null;
return (
<div className="mb-5 space-y-3 rounded-xl border border-gray-100 bg-white p-4 shadow-sm animate-pulse">
<div className="grid grid-cols-1 gap-3 md:grid-cols-2">
<div className="h-28 bg-gray-50 border border-gray-100 rounded-xl p-4 flex flex-col justify-between">
<div className="h-4 bg-gray-200 rounded w-1/3" />
<div className="h-8 bg-gray-200 rounded w-1/2" />
<div className="h-3 bg-gray-200 rounded w-2/3" />
</div>
<div className="h-28 bg-gray-50 border border-gray-100 rounded-xl p-4 flex flex-col justify-between">
<div className="h-4 bg-gray-200 rounded w-1/3" />
<div className="h-8 bg-gray-200 rounded w-1/2" />
<div className="h-3 bg-gray-200 rounded w-2/3" />
</div>
</div>
<div className="grid grid-cols-2 gap-3 lg:grid-cols-3">
<div className="h-20 bg-gray-50 border border-gray-100 rounded-lg p-3 flex flex-col justify-between">
<div className="h-3 bg-gray-200 rounded w-1/2" />
<div className="h-6 bg-gray-200 rounded w-3/4" />
</div>
<div className="h-20 bg-gray-50 border border-gray-100 rounded-lg p-3 flex flex-col justify-between">
<div className="h-3 bg-gray-200 rounded w-1/2" />
<div className="h-6 bg-gray-200 rounded w-3/4" />
</div>
<div className="h-20 bg-gray-50 border border-gray-100 rounded-lg p-3 flex flex-col justify-between">
<div className="h-3 bg-gray-200 rounded w-1/2" />
<div className="h-6 bg-gray-200 rounded w-3/4" />
</div>
</div>
</div>
);
}
if (!hasInsight || !scopedMetrics || page !== 'dashboard') return null;
const fcrVal = scopedMetrics.fcr;
@@ -830,7 +865,12 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
<h2 className="text-lg font-bold text-gray-900 group-hover:text-red-700 transition-colors">
AI Insight
</h2>
{hasInsight && (
{loading ? (
<span className="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-xs font-medium bg-amber-50 text-amber-700 border border-amber-200 animate-pulse">
<span className="w-1.5 h-1.5 rounded-full bg-amber-500 animate-ping" />
Memproses...
</span>
) : hasInsight ? (
<InsightStatusBadge
status={overallStatus}
customLabel={
@@ -839,7 +879,7 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
: undefined
}
/>
)}
) : null}
</div>
<p className="text-xs text-gray-400 truncate">
{selectedKandang?.kandang_name ?? `Kandang ${effectiveKandangId}`}
@@ -909,16 +949,21 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
Pilih satu kandang untuk menghasilkan AI Insight. Generate untuk semua kandang
tidak diizinkan.
</div>
) : loading && !insightText ? (
<div className="flex items-center justify-center py-8">
) : loading ? (
<div className="flex items-center justify-center py-10 rounded-xl border border-gray-100 bg-white shadow-xs">
<div className="flex flex-col items-center gap-3">
<div className="animate-spin rounded-full h-10 w-10 border-b-2 border-red-600" />
<p className="text-sm text-gray-600 text-center max-w-sm">
Menganalisis data peternakan… proses ini bisa memakan waktu beberapa menit.
</p>
<div className="w-10 h-10 rounded-full border-4 border-red-100 border-t-red-600 animate-spin" />
<div className="text-center space-y-1">
<p className="text-sm font-semibold text-gray-800">
Menganalisis data peternakan & menyusun insight…
</p>
<p className="text-xs text-gray-500 max-w-sm">
Proses kalkulasi CP 707 dan AI sedang berjalan. Mohon tunggu beberapa saat.
</p>
</div>
</div>
</div>
) : error && !insightText ? (
) : error ? (
<div className="bg-red-50 border border-red-200 rounded-lg p-4">
<p className="text-red-700 text-sm font-semibold mb-2">Error</p>
<p className="text-red-600 text-sm">{error}</p>
@@ -1179,12 +1224,17 @@ export const AiInsightCard: React.FC<AiInsightCardProps> = ({
<div className="mt-6 pt-4 border-t border-gray-100 flex items-center justify-between">
<div className="text-xs text-gray-400">
{hasInsight && (
{loading ? (
<span className="inline-flex items-center gap-1.5 text-amber-600">
<i className="fa-solid fa-spinner fa-spin text-xs" />
<span>Sedang memperbarui analisis AI...</span>
</span>
) : hasInsight ? (
<span className="inline-flex items-center gap-1.5">
<span>Status AI Insight:</span>
<InsightStatusBadge status={overallStatus} size="xs" />
</span>
)}
) : null}
</div>
<button
type="button"