mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
Add technical badges and delete confirmation
This update adds dedicated badge variants for technical progression states (Development, SIT, UAT, PTR, Go-live, BAST, Warranty) and improves status text matching for those stages. It also adds a confirmation dialog when deleting a schedule interval, including cleanup for the final remaining interval so the status description is cleared when appropriate and users are told when notes are being removed.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
BASE_PATH = ""
|
||||
NEXT_PUBLIC_APP_URL="https://dev-hats.hisnutech.my.id"
|
||||
|
||||
BASE_URL_API = https://api-hats-dev.hisnutech.my.id/api/v1
|
||||
BASE_URL_IMG = https://api-hats.hisnutech.my.id/
|
||||
|
||||
NEXTAUTH_URL = https://dev-hats.hisnutech.my.id
|
||||
NEXTAUTH_URL_INTERNAL = http://36.66.3.44:7005
|
||||
|
||||
NEXTAUTH_SECRET = 4339d50684523526005c1fcb34be0bb1
|
||||
|
||||
FIREBASE_API_KEY = AIzaSyAEkZCHhnyatsNiZ2dpjeaz6JqXYknKKHk
|
||||
FIREBASE_APP_ID = "1:422528660020:web:db16e1cba4d357e32f1061"
|
||||
|
||||
DEVICE_CODE = "40001"
|
||||
NEXT_PUBLIC_HATS_SUPPORT_NAME = "Amalia"
|
||||
NEXT_PUBLIC_HATS_SUPPORT_PHONE = "6285214074002"
|
||||
NEXT_PUBLIC_APP_VERSION = "v1.2.0"
|
||||
NEXT_PUBLIC_MANAGER_USER_ID = '2'
|
||||
|
||||
NEXT_PUBLIC_S3_IMAGE_URL = https://cdn.hisnutech.my.id/public
|
||||
@@ -10,6 +10,16 @@ import { Textarea } from '@/components/ui/textarea';
|
||||
import {
|
||||
Table, TableBody, TableCell, TableHead, TableHeader, TableRow
|
||||
} from "@/components/ui/table";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import {
|
||||
AlertCircle, Calendar, Edit2, History, Loader2, Plus, Save, Trash2
|
||||
} from 'lucide-react';
|
||||
@@ -301,9 +311,16 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
|
||||
);
|
||||
}
|
||||
|
||||
const UpdateTimelineStatus: FC<Props> = ({ assignmentId, onClose }) => {
|
||||
interface DeleteTarget {
|
||||
item: StatusItem;
|
||||
index: number;
|
||||
dateEntry: IDateInterval;
|
||||
}
|
||||
|
||||
const UpdateTechnicalStatus: FC<Props> = ({ assignmentId, onClose }) => {
|
||||
const [modalState, setModalState] = useState<ModalState | null>(null);
|
||||
const [deletingId, setDeletingId] = useState<string | null>(null);
|
||||
const [deleteTarget, setDeleteTarget] = useState<DeleteTarget | null>(null);
|
||||
const [isDeleting, setIsDeleting] = useState(false);
|
||||
|
||||
const { data: existTimeline, isLoading: isLoadingTimeline, mutate } = useFetchWithAxios(`project-assignment/status-detail/${assignmentId}`);
|
||||
const router = useRouter();
|
||||
@@ -387,28 +404,37 @@ const UpdateTimelineStatus: FC<Props> = ({ assignmentId, onClose }) => {
|
||||
});
|
||||
};
|
||||
|
||||
// Handle deleting a specific date entry from the status
|
||||
const handleDeleteDate = async (item: StatusItem, removeIndex: number) => {
|
||||
const itemKey = `${item.technicalId}-${removeIndex}`;
|
||||
setDeletingId(itemKey);
|
||||
// Handle confirming date deletion from AlertDialog
|
||||
const handleConfirmDelete = async () => {
|
||||
if (!deleteTarget) return;
|
||||
|
||||
const { item, index: removeIndex } = deleteTarget;
|
||||
setIsDeleting(true);
|
||||
|
||||
const remainingDates = item.dates.filter((_, idx) => idx !== removeIndex);
|
||||
// If the remaining dates are empty (last date removed), also clear the description
|
||||
const finalDescription = remainingDates.length === 0 ? '' : item.description.trim();
|
||||
|
||||
const submitPayload = {
|
||||
project_assignment_technical_status_id: Number(item.technicalId),
|
||||
project_assignment_status_detail_id: Number(item.detailId),
|
||||
date: remainingDates,
|
||||
description: item.description.trim()
|
||||
description: finalDescription
|
||||
};
|
||||
|
||||
const res = await serverApiCall('PUT', `/project-assignment/technical-status/${assignmentId}`,
|
||||
submitPayload
|
||||
);
|
||||
|
||||
setDeletingId(null);
|
||||
setIsDeleting(false);
|
||||
|
||||
if (res.success) {
|
||||
toast.success('Schedule interval removed');
|
||||
toast.success(
|
||||
remainingDates.length === 0
|
||||
? 'Schedule interval and notes removed'
|
||||
: 'Schedule interval removed'
|
||||
);
|
||||
setDeleteTarget(null);
|
||||
mutate();
|
||||
router.refresh();
|
||||
} else {
|
||||
@@ -478,7 +504,6 @@ const UpdateTimelineStatus: FC<Props> = ({ assignmentId, onClose }) => {
|
||||
{hasDates ? (
|
||||
<div className="space-y-1.5">
|
||||
{item.dates.map((dateEntry, idx) => {
|
||||
const isDeletingThis = deletingId === `${item.technicalId}-${idx}`;
|
||||
const start = dateEntry.start_date ? dayjs(dateEntry.start_date) : null;
|
||||
const end = dateEntry.end_date ? dayjs(dateEntry.end_date) : null;
|
||||
const spanDays = start && end ? end.diff(start, 'day') + 1 : null;
|
||||
@@ -504,7 +529,7 @@ const UpdateTimelineStatus: FC<Props> = ({ assignmentId, onClose }) => {
|
||||
<Button variant="outline" className="h-8 w-8 text-teal-600 hover:text-teal-700 hover:bg-teal-100" onClick={() => handleEditExistingDate(item, idx)}>
|
||||
<Edit2 className="size-3.5" />
|
||||
</Button>
|
||||
<Button variant="outline" className="h-8 w-8 text-red-600 hover:text-red-700 hover:bg-red-100" onClick={() => handleDeleteDate(item, idx)}>
|
||||
<Button variant="outline" className="h-8 w-8 text-red-600 hover:text-red-700 hover:bg-red-100" onClick={() => setDeleteTarget({ item, index: idx, dateEntry })}>
|
||||
<Trash2 className="size-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
@@ -564,8 +589,63 @@ const UpdateTimelineStatus: FC<Props> = ({ assignmentId, onClose }) => {
|
||||
onSuccess={handleSuccess}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{/* Confirmation Dialog: Delete Date Interval */}
|
||||
<AlertDialog
|
||||
open={Boolean(deleteTarget)}
|
||||
onOpenChange={(open) => {
|
||||
if (!open && !isDeleting) setDeleteTarget(null);
|
||||
}}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle className="flex items-center gap-2 text-destructive">
|
||||
<Trash2 className="size-4" />
|
||||
Delete Schedule Interval
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription className="space-y-2 pt-1 text-left">
|
||||
{deleteTarget && (
|
||||
<>
|
||||
<span>
|
||||
Are you sure you want to delete the schedule interval{' '}
|
||||
<strong className="font-mono text-foreground">
|
||||
{deleteTarget.dateEntry.start_date ? dayjs(deleteTarget.dateEntry.start_date).format('DD MMM YYYY') : 'TBD'} – {deleteTarget.dateEntry.end_date ? dayjs(deleteTarget.dateEntry.end_date).format('DD MMM YYYY') : 'Present'}
|
||||
</strong>{' '}
|
||||
from <strong className="text-foreground">{deleteTarget.item.statusName}</strong>?
|
||||
</span>
|
||||
{deleteTarget.item.dates.length === 1 && (
|
||||
<div className="rounded-md border border-amber-500/30 bg-amber-500/10 p-2.5 text-xs text-amber-700 dark:text-amber-400 mt-3">
|
||||
<strong>Note:</strong> This is the last remaining schedule for this status. Deleting it will also remove the description and progress notes.
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isDeleting}>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
handleConfirmDelete();
|
||||
}}
|
||||
disabled={isDeleting}
|
||||
className="bg-destructive text-white hover:bg-destructive/90 gap-1.5"
|
||||
>
|
||||
{isDeleting ? (
|
||||
<>
|
||||
<Loader2 className="size-3.5 animate-spin" />
|
||||
Deleting...
|
||||
</>
|
||||
) : (
|
||||
'Delete'
|
||||
)}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateTimelineStatus;
|
||||
export default UpdateTechnicalStatus;
|
||||
@@ -40,16 +40,32 @@ export function formatStatusText(status?: any): string {
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
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 = getTechnicalBadgeVariant(raw) || STATUS_BADGE_MAP[lookupKey] || "default";
|
||||
|
||||
return (
|
||||
<Badge
|
||||
variant={STATUS_BADGE_MAP[lookupKey] || "default"}
|
||||
variant={variant}
|
||||
className={cn("text-[10px] font-semibold tracking-wide px-2 py-0.5", className)}
|
||||
>
|
||||
{formatted}
|
||||
|
||||
+45
-22
@@ -30,13 +30,22 @@ const badgeVariants = cva(
|
||||
|
||||
// --- CUSTOM STATUS VARIANTS ---
|
||||
statusNotStarted: "border-transparent bg-slate-500 text-zinc-50 hover:opacity-80", // Gray
|
||||
statusActive: "border-transparent bg-teal-500 text-zinc-50 hover:opacity-80", // Blue
|
||||
statusActive: "border-transparent bg-teal-500 text-zinc-50 hover:opacity-80", // Teal
|
||||
statusWarning: "border-transparent bg-amber-500 text-zinc-50 hover:opacity-80", // Yellow/Orange
|
||||
statusDanger: "border-transparent bg-red-500 text-zinc-50 hover:opacity-80", // Red
|
||||
statusTesting: "border-transparent bg-indigo-500 text-zinc-50 hover:opacity-80", // Indigo/Purple
|
||||
statusTesting: "border-transparent bg-indigo-500 text-zinc-50 hover:opacity-80", // Indigo
|
||||
statusSuccess: "border-transparent bg-emerald-500 text-zinc-50 hover:opacity-80", // Green
|
||||
statusMaintenance: "border-transparent bg-blue-500 text-zinc-50 hover:opacity-80", // Teal
|
||||
statusEnded: "border-transparent bg-stone-500 text-zinc-50 hover:opacity-80", // Dark Gray/Brown
|
||||
statusMaintenance: "border-transparent bg-blue-500 text-zinc-50 hover:opacity-80", // Blue
|
||||
statusEnded: "border-transparent bg-stone-500 text-zinc-50 hover:opacity-80", // Dark Gray
|
||||
|
||||
// --- TECHNICAL PROGRESSION STATUS VARIANTS ---
|
||||
techDevelopment: "border-transparent bg-orange-500 text-white dark:bg-orange-600 hover:opacity-85", // Orange
|
||||
techSIT: "border-transparent bg-blue-500 text-white dark:bg-blue-600 hover:opacity-85", // Blue
|
||||
techUAT: "border-transparent bg-purple-500 text-white dark:bg-purple-600 hover:opacity-85", // Purple/Violet
|
||||
techPTR: "border-transparent bg-teal-500 text-white dark:bg-teal-600 hover:opacity-85", // Mint / Aqua (Teal)
|
||||
techGoLive: "border-transparent bg-lime-600 text-white dark:bg-lime-700 hover:opacity-85", // Lime Green
|
||||
techBAST: "border-transparent bg-yellow-500 text-white dark:bg-yellow-600 hover:opacity-85", // Yellow / Amber (BAST)
|
||||
techWarranty: "border-transparent bg-sky-500 text-white dark:bg-sky-600 hover:opacity-85", // Sky Blue
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
@@ -57,30 +66,44 @@ export const STATUS_BADGE_MAP: Record<string, VariantProps<typeof badgeVariants>
|
||||
"issue": "statusDanger",
|
||||
"canceled": "statusDanger",
|
||||
|
||||
// Technical progression stages
|
||||
"development": "info",
|
||||
// Technical progression stages based on color reference:
|
||||
// 1. Development -> Orange
|
||||
"development": "techDevelopment",
|
||||
"dev": "techDevelopment",
|
||||
|
||||
"sit": "statusTesting",
|
||||
"system integration testing (sit)": "statusTesting",
|
||||
"system integration testing": "statusTesting",
|
||||
// 2. System Integration Testing (SIT) -> Blue
|
||||
"sit": "techSIT",
|
||||
"(sit)": "techSIT",
|
||||
"system integration testing (sit)": "techSIT",
|
||||
"system integration testing": "techSIT",
|
||||
|
||||
"uat": "violet",
|
||||
"user acceptance testing (uat)": "violet",
|
||||
"user acceptance testing": "violet",
|
||||
// 3. User Acceptance Testing (UAT) -> Purple/Violet
|
||||
"uat": "techUAT",
|
||||
"(uat)": "techUAT",
|
||||
"user acceptance testing (uat)": "techUAT",
|
||||
"user acceptance testing": "techUAT",
|
||||
|
||||
"ptr": "statusWarning",
|
||||
"production trial run (ptr)": "statusWarning",
|
||||
"production trial run": "statusWarning",
|
||||
// 4. Production Trial Run (PTR) -> Mint / Aqua Green
|
||||
"ptr": "techPTR",
|
||||
"(ptr)": "techPTR",
|
||||
"production trial run (ptr)": "techPTR",
|
||||
"production trial run": "techPTR",
|
||||
|
||||
"go-live": "statusSuccess",
|
||||
"go live": "statusSuccess",
|
||||
"golive": "statusSuccess",
|
||||
// 5. Go-live -> Lime Green
|
||||
"go-live": "techGoLive",
|
||||
"go live": "techGoLive",
|
||||
"golive": "techGoLive",
|
||||
|
||||
"bast": "statusActive",
|
||||
"project handover & bast": "statusActive",
|
||||
"project handover and bast": "statusActive",
|
||||
// 6. Project Handover & BAST -> Yellow
|
||||
"bast": "techBAST",
|
||||
"(bast)": "techBAST",
|
||||
"project handover & bast": "techBAST",
|
||||
"project handover and bast": "techBAST",
|
||||
"project handover & bast (bast)": "techBAST",
|
||||
"project handover": "techBAST",
|
||||
|
||||
"warranty": "statusMaintenance",
|
||||
// 7. Warranty -> Light Sky Blue
|
||||
"warranty": "techWarranty",
|
||||
|
||||
"end of support": "statusEnded",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user