mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
f9e4f3de87
Adds a dedicated administration-status workflow across client, assignment, and project views, including a new UpdateAdministrationStatus modal and action entries in assignment menus. It also improves modal layout consistency, prioritizes project-assignment status badges in list/grid views, and expands badge variants for administration and technical lifecycle states.
90 lines
3.5 KiB
TypeScript
90 lines
3.5 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",
|
|
"(SIT)", "(UAT)", "(PTR)", "(BAST)"
|
|
]);
|
|
if (trimmed.length === 3 || upperAcronyms.has(trimmed.toUpperCase())) {
|
|
return trimmed.toUpperCase();
|
|
}
|
|
|
|
// Capitalize setiap kata untuk teks status lainnya dengan memperhatikan akronim teknis
|
|
return trimmed
|
|
.split(/\s+/)
|
|
.map(word => {
|
|
if (!word) return "";
|
|
if (word.toUpperCase() === "GO-LIVE" || word.toLowerCase() === "go-live") return "Go-Live";
|
|
if (word === "&") return "&";
|
|
const stripped = word.replace(/[^a-zA-Z]/g, '').toUpperCase();
|
|
if (upperAcronyms.has(stripped) || upperAcronyms.has(word.toUpperCase())) {
|
|
return word.toUpperCase();
|
|
}
|
|
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
})
|
|
.join(" ");
|
|
}
|
|
|
|
function getAdministrationBadgeVariant(rawText: string) {
|
|
const key = rawText.toLowerCase().trim();
|
|
if (key.includes("not started") || key.includes("not-started")) return "adminNotStarted";
|
|
if (key === "active" || key.includes("on progress") || key.includes("on going") || key.includes("in progress")) return "adminActive";
|
|
if (key.includes("on hold") || key.includes("hold") || key.includes("halted")) return "adminOnHold";
|
|
if (key.includes("cancel")) return "adminCancelled";
|
|
if (key.includes("complete") || key.includes("done")) return "adminCompleted";
|
|
|
|
return undefined;
|
|
}
|
|
|
|
function getTechnicalBadgeVariant(rawText: string) {
|
|
const key = rawText.toLowerCase().trim();
|
|
if (STATUS_BADGE_MAP[key]) return STATUS_BADGE_MAP[key];
|
|
|
|
if (key.includes("development") || key === "dev") return "techDevelopment";
|
|
if (key.includes("sit") || key.includes("system integration")) return "techSIT";
|
|
if (key.includes("uat") || key.includes("user acceptance")) return "techUAT";
|
|
if (key.includes("ptr") || key.includes("production trial")) return "techPTR";
|
|
if (key.includes("go-live") || key.includes("go live") || key.includes("golive")) return "techGoLive";
|
|
if (key.includes("bast") || key.includes("handover")) return "techBAST";
|
|
if (key.includes("warranty")) return "techWarranty";
|
|
|
|
return undefined;
|
|
}
|
|
|
|
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();
|
|
const variant =
|
|
STATUS_BADGE_MAP[lookupKey] ||
|
|
getAdministrationBadgeVariant(raw) ||
|
|
getTechnicalBadgeVariant(raw) ||
|
|
"default";
|
|
|
|
return (
|
|
<Badge
|
|
variant={variant}
|
|
className={cn("text-[10px] font-semibold tracking-wide px-2 py-0.5", className)}
|
|
>
|
|
{formatted}
|
|
</Badge>
|
|
);
|
|
}
|