mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 22:26:27 +00:00
3f0ed29f0c
This commit adds reusable client and end-user fallback assets and updates profile cards, lists, and assignment views to render graceful placeholders when images are missing or fail to load. It also hardens the shared LazyImage component with fallback handling and improves BadgeStatus so it accepts object-like status values and still renders clean labels. Minor UX fixes include dismissing upload toasts after completion and clarifying end-user form labels/copy.
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { Badge, STATUS_BADGE_MAP } from "@/components/ui/badge"
|
|
import { cn } from "@/lib/utils"
|
|
|
|
function extractStatusString(status?: any): string {
|
|
if (!status) return "";
|
|
if (typeof status === "string") return status;
|
|
if (typeof status === "object") {
|
|
return status.name || status.status || status.title || "";
|
|
}
|
|
return String(status);
|
|
}
|
|
|
|
export function formatStatusText(status?: any): string {
|
|
const raw = extractStatusString(status);
|
|
const trimmed = raw.trim();
|
|
if (!trimmed) return "";
|
|
|
|
// Tetap UPPERCASE jika seluruh teks status hanya 3 huruf (SIT, UAT, PTR, dll) atau akronim BAST
|
|
const upperAcronyms = new Set(["SIT", "UAT", "PTR", "BAST", "POC", "WIP", "WO", "IM"]);
|
|
if (trimmed.length === 3 || upperAcronyms.has(trimmed.toUpperCase())) {
|
|
return trimmed.toUpperCase();
|
|
}
|
|
|
|
// Capitalize setiap kata untuk teks status lainnya
|
|
return trimmed
|
|
.split(/\s+/)
|
|
.map(word => {
|
|
if (!word) return "";
|
|
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
})
|
|
.join(" ");
|
|
}
|
|
|
|
export default function BadgeStatus({ status, className }: { status: any, className?: string }) { // e.g. status = "UAT"
|
|
const raw = extractStatusString(status);
|
|
const formatted = formatStatusText(raw);
|
|
if (!formatted) return null;
|
|
|
|
const lookupKey = raw.toLowerCase().trim();
|
|
|
|
return (
|
|
<Badge
|
|
variant={STATUS_BADGE_MAP[lookupKey] || "default"}
|
|
className={cn("text-[10px] font-semibold tracking-wide px-2 py-0.5", className)}
|
|
>
|
|
{formatted}
|
|
</Badge>
|
|
);
|
|
}
|