fix: lint, stubs, StatusBadge, uptime %, closure remarks UX
This commit is contained in:
@@ -83,8 +83,14 @@ export function AssetFormModal({
|
||||
});
|
||||
|
||||
const departments = deptsQuery.data?.items ?? [];
|
||||
const allLocations = locsQuery.data?.items ?? [];
|
||||
const categories = catsQuery.data?.items ?? [];
|
||||
const allLocations = useMemo(
|
||||
() => locsQuery.data?.items ?? [],
|
||||
[locsQuery.data?.items]
|
||||
);
|
||||
const categories = useMemo(
|
||||
() => catsQuery.data?.items ?? [],
|
||||
[catsQuery.data?.items]
|
||||
);
|
||||
const vendors = vendorsQuery.data?.items ?? [];
|
||||
|
||||
const defaultDeptId = editing?.department_id ?? departments[0]?.id ?? 0;
|
||||
@@ -161,7 +167,7 @@ export function AssetFormModal({
|
||||
remarks: "",
|
||||
});
|
||||
}
|
||||
}, [open, editing, categories.length, defaultDeptId, defaultLocId, reset]);
|
||||
}, [open, editing, categories, defaultDeptId, defaultLocId, reset]);
|
||||
|
||||
const watchedDeptId = Number(watch("department_id"));
|
||||
const filteredLocations = useMemo(
|
||||
|
||||
@@ -16,26 +16,9 @@ import {
|
||||
} from "@/api/attachments";
|
||||
import { ApiError } from "@/api/client";
|
||||
import { formatDateTime } from "@/lib/format";
|
||||
import { validateAttachmentFile } from "@/lib/validation";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
const MAX_SIZE_BYTES = 10 * 1024 * 1024; // 10 MB
|
||||
const ALLOWED_EXTENSIONS = [".jpg", ".jpeg", ".png", ".pdf"];
|
||||
const ALLOWED_MIME_TYPES = ["image/jpeg", "image/png", "application/pdf"];
|
||||
|
||||
export function validateAttachmentFile(file: File): string | null {
|
||||
const nameLower = file.name.toLowerCase();
|
||||
const hasAllowedExt = ALLOWED_EXTENSIONS.some((ext) => nameLower.endsWith(ext));
|
||||
const hasAllowedMime = !file.type || ALLOWED_MIME_TYPES.includes(file.type);
|
||||
|
||||
if (!hasAllowedExt || !hasAllowedMime) {
|
||||
return "Invalid file type. Only JPG, PNG, and PDF files are allowed.";
|
||||
}
|
||||
if (file.size > MAX_SIZE_BYTES) {
|
||||
return "File is too large. Maximum allowed size is 10 MB.";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
if (bytes < 1024) return `${bytes} B`;
|
||||
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
||||
|
||||
@@ -12,7 +12,7 @@ import { assetsApi, type BulkImportResult } from "@/api/assets";
|
||||
import { ApiError } from "@/api/client";
|
||||
import { Modal } from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { toast } from "@/components/ToastProvider";
|
||||
import { toast } from "@/lib/toast";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface BulkAssetImportModalProps {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AlertCircle, Paperclip, X } from "lucide-react";
|
||||
import { Modal } from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { validateAttachmentFile } from "@/components/Attachments";
|
||||
import { validateAttachmentFile } from "@/lib/validation";
|
||||
import { ApiError } from "@/api/client";
|
||||
import { assetsApi } from "@/api/assets";
|
||||
import { vendorsApi } from "@/api/masters";
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useAuthStore } from "@/hooks/useAuth";
|
||||
import { formatDate } from "@/lib/format";
|
||||
import { Modal } from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { toast } from "@/components/ToastProvider";
|
||||
import { toast } from "@/lib/toast";
|
||||
|
||||
export function CalibrationReminderModal() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
@@ -8,7 +8,7 @@ import { AlertCircle, Clock, Paperclip, X } from "lucide-react";
|
||||
import { Modal } from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { AssetPicker } from "@/components/AssetPicker";
|
||||
import { validateAttachmentFile } from "@/components/Attachments";
|
||||
import { validateAttachmentFile } from "@/lib/validation";
|
||||
import { ApiError } from "@/api/client";
|
||||
import { assetsApi, type AssetLookupItem, type AssetCriticality } from "@/api/assets";
|
||||
import { complaintsApi, type ComplaintItem } from "@/api/complaints";
|
||||
|
||||
@@ -1,44 +1,5 @@
|
||||
import { create } from "zustand";
|
||||
import { CheckCircle2, Info, AlertTriangle, AlertCircle, X } from "lucide-react";
|
||||
|
||||
export type ToastVariant = "success" | "info" | "warning" | "error";
|
||||
|
||||
export interface ToastEntry {
|
||||
id: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
variant: ToastVariant;
|
||||
}
|
||||
|
||||
interface ToastState {
|
||||
toasts: ToastEntry[];
|
||||
push: (t: Omit<ToastEntry, "id">) => void;
|
||||
dismiss: (id: string) => void;
|
||||
}
|
||||
|
||||
export const useToastStore = create<ToastState>((set) => ({
|
||||
toasts: [],
|
||||
push: (entry) => {
|
||||
const id = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
set((s) => ({ toasts: [...s.toasts.slice(-4), { ...entry, id }] }));
|
||||
setTimeout(() => {
|
||||
set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) }));
|
||||
}, 5000);
|
||||
},
|
||||
dismiss: (id) =>
|
||||
set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })),
|
||||
}));
|
||||
|
||||
export const toast = {
|
||||
success: (title: string, description?: string) =>
|
||||
useToastStore.getState().push({ title, description, variant: "success" }),
|
||||
info: (title: string, description?: string) =>
|
||||
useToastStore.getState().push({ title, description, variant: "info" }),
|
||||
warning: (title: string, description?: string) =>
|
||||
useToastStore.getState().push({ title, description, variant: "warning" }),
|
||||
error: (title: string, description?: string) =>
|
||||
useToastStore.getState().push({ title, description, variant: "error" }),
|
||||
};
|
||||
import { useToastStore, type ToastVariant } from "@/lib/toast";
|
||||
|
||||
const VARIANT_CLS: Record<ToastVariant, string> = {
|
||||
success: "bg-emerald-50 border-emerald-300 text-emerald-900",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { useState, useEffect, useRef, useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
@@ -28,7 +28,7 @@ import { notificationsApi, type NotificationItem } from "@/api/notifications";
|
||||
import { searchApi } from "@/api/search";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { AssetStatusBadge, CallStatusBadge } from "@/components/StatusBadge";
|
||||
import { toast } from "@/components/ToastProvider";
|
||||
import { toast } from "@/lib/toast";
|
||||
|
||||
interface TopBarProps {
|
||||
title?: string;
|
||||
@@ -121,7 +121,10 @@ export function TopBar({ title, onMenuClick }: TopBarProps) {
|
||||
refetchInterval: 60_000,
|
||||
});
|
||||
|
||||
const bellItems = bellQuery.data?.items ?? [];
|
||||
const bellItems = useMemo(
|
||||
() => bellQuery.data?.items ?? [],
|
||||
[bellQuery.data?.items]
|
||||
);
|
||||
const unreadCount = bellQuery.data?.unread_count ?? 0;
|
||||
|
||||
// Detect newly arrived unread notifications while app is open
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { create } from "zustand";
|
||||
|
||||
export type ToastVariant = "success" | "info" | "warning" | "error";
|
||||
|
||||
export interface ToastEntry {
|
||||
id: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
variant: ToastVariant;
|
||||
}
|
||||
|
||||
interface ToastState {
|
||||
toasts: ToastEntry[];
|
||||
push: (t: Omit<ToastEntry, "id">) => void;
|
||||
dismiss: (id: string) => void;
|
||||
}
|
||||
|
||||
export const useToastStore = create<ToastState>((set) => ({
|
||||
toasts: [],
|
||||
push: (entry) => {
|
||||
const id = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
set((s) => ({ toasts: [...s.toasts.slice(-4), { ...entry, id }] }));
|
||||
setTimeout(() => {
|
||||
set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) }));
|
||||
}, 5000);
|
||||
},
|
||||
dismiss: (id) =>
|
||||
set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })),
|
||||
}));
|
||||
|
||||
export const toast = {
|
||||
success: (title: string, description?: string) =>
|
||||
useToastStore.getState().push({ title, description, variant: "success" }),
|
||||
info: (title: string, description?: string) =>
|
||||
useToastStore.getState().push({ title, description, variant: "info" }),
|
||||
warning: (title: string, description?: string) =>
|
||||
useToastStore.getState().push({ title, description, variant: "warning" }),
|
||||
error: (title: string, description?: string) =>
|
||||
useToastStore.getState().push({ title, description, variant: "error" }),
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
const MAX_SIZE_BYTES = 10 * 1024 * 1024; // 10 MB
|
||||
const ALLOWED_EXTENSIONS = [".jpg", ".jpeg", ".png", ".pdf"];
|
||||
const ALLOWED_MIME_TYPES = ["image/jpeg", "image/png", "application/pdf"];
|
||||
|
||||
export function validateAttachmentFile(file: File): string | null {
|
||||
const nameLower = file.name.toLowerCase();
|
||||
const hasAllowedExt = ALLOWED_EXTENSIONS.some((ext) => nameLower.endsWith(ext));
|
||||
const hasAllowedMime = !file.type || ALLOWED_MIME_TYPES.includes(file.type);
|
||||
|
||||
if (!hasAllowedExt || !hasAllowedMime) {
|
||||
return "Invalid file type. Only JPG, PNG, and PDF files are allowed.";
|
||||
}
|
||||
if (file.size > MAX_SIZE_BYTES) {
|
||||
return "File is too large. Maximum allowed size is 10 MB.";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
Plus,
|
||||
} from "lucide-react";
|
||||
import { assetsApi } from "@/api/assets";
|
||||
import type { CalibrationPlanItem } from "@/api/calibration";
|
||||
import { ApiError } from "@/api/client";
|
||||
import { useAuthStore } from "@/hooks/useAuth";
|
||||
import { can } from "@/lib/permissions";
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
type TimestampField,
|
||||
} from "@/api/complaints";
|
||||
import { fetchUsersLookup } from "@/api/masters";
|
||||
import { settingsApi } from "@/api/settings";
|
||||
import { ApiError } from "@/api/client";
|
||||
import { useAuthStore } from "@/hooks/useAuth";
|
||||
import { can } from "@/lib/permissions";
|
||||
@@ -90,6 +91,7 @@ export function ComplaintDetailPage() {
|
||||
|
||||
const [closeOpen, setCloseOpen] = useState(false);
|
||||
const [closureRemarks, setClosureRemarks] = useState("");
|
||||
const [closeError, setCloseError] = useState<string | null>(null);
|
||||
|
||||
const [reopenOpen, setReopenOpen] = useState(false);
|
||||
const [reopenReason, setReopenReason] = useState("");
|
||||
@@ -118,6 +120,21 @@ export function ComplaintDetailPage() {
|
||||
enabled: Number.isFinite(complaintId) && complaintId > 0,
|
||||
});
|
||||
|
||||
const settingsQuery = useQuery({
|
||||
queryKey: ["settings"],
|
||||
queryFn: () => settingsApi.getAll(),
|
||||
enabled: isAdmin,
|
||||
retry: false,
|
||||
});
|
||||
|
||||
const requireClosureRemarks = (() => {
|
||||
const setting = settingsQuery.data?.items?.find(
|
||||
(s) => s.key === "require_closure_remarks"
|
||||
);
|
||||
if (setting !== undefined) return Boolean(setting.value);
|
||||
return true;
|
||||
})();
|
||||
|
||||
const eventsQuery = useQuery({
|
||||
queryKey: ["complaint-events", complaintId],
|
||||
queryFn: () => complaintsApi.events(complaintId),
|
||||
@@ -193,11 +210,16 @@ export function ComplaintDetailPage() {
|
||||
}),
|
||||
onSuccess: async () => {
|
||||
setActionError(null);
|
||||
setCloseError(null);
|
||||
setCloseOpen(false);
|
||||
setClosureRemarks("");
|
||||
await refreshAll();
|
||||
},
|
||||
onError: (err) => setActionError(err instanceof ApiError ? err.detail : "Close failed."),
|
||||
onError: (err) => {
|
||||
const msg = err instanceof ApiError ? err.detail : "Close failed.";
|
||||
setCloseError(msg);
|
||||
setActionError(msg);
|
||||
},
|
||||
});
|
||||
|
||||
const reopenMutation = useMutation({
|
||||
@@ -541,7 +563,10 @@ export function ComplaintDetailPage() {
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="border-green-600 text-green-700 hover:bg-green-50"
|
||||
onClick={() => setCloseOpen(true)}
|
||||
onClick={() => {
|
||||
setCloseError(null);
|
||||
setCloseOpen(true);
|
||||
}}
|
||||
>
|
||||
<CheckCircle2 className="h-3.5 w-3.5 mr-1.5" />
|
||||
Close Call
|
||||
@@ -874,20 +899,48 @@ export function ComplaintDetailPage() {
|
||||
</Modal>
|
||||
|
||||
{/* Close Modal */}
|
||||
<Modal open={closeOpen} onOpenChange={setCloseOpen} title="Close Complaint Call">
|
||||
<Modal
|
||||
open={closeOpen}
|
||||
onOpenChange={(next) => {
|
||||
setCloseOpen(next);
|
||||
if (!next) setCloseError(null);
|
||||
}}
|
||||
title="Close Complaint Call"
|
||||
>
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (requireClosureRemarks && !closureRemarks.trim()) {
|
||||
setCloseError("Closure remarks are required.");
|
||||
return;
|
||||
}
|
||||
setCloseError(null);
|
||||
closeMutation.mutate();
|
||||
}}
|
||||
className="space-y-4"
|
||||
>
|
||||
{closeError && (
|
||||
<div
|
||||
role="alert"
|
||||
className="flex items-start gap-2 rounded-md bg-red-50 border border-red-200 px-3 py-2 text-xs text-red-700"
|
||||
>
|
||||
<AlertCircle className="h-4 w-4 shrink-0 mt-0.5" />
|
||||
<span>{closeError}</span>
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<label className={labelCls}>Closure Remarks</label>
|
||||
<label htmlFor="closure-remarks" className={labelCls}>
|
||||
Closure Remarks {requireClosureRemarks && <span className="text-red-600">*</span>}
|
||||
</label>
|
||||
<textarea
|
||||
id="closure-remarks"
|
||||
rows={3}
|
||||
required={requireClosureRemarks}
|
||||
value={closureRemarks}
|
||||
onChange={(e) => setClosureRemarks(e.target.value)}
|
||||
onChange={(e) => {
|
||||
setClosureRemarks(e.target.value);
|
||||
if (closeError) setCloseError(null);
|
||||
}}
|
||||
placeholder="Summary of resolution and verification..."
|
||||
className={inputCls}
|
||||
/>
|
||||
|
||||
@@ -32,7 +32,7 @@ import { ExpiryChip } from "@/components/StatusBadge";
|
||||
import { AssetPicker } from "@/components/AssetPicker";
|
||||
import { Attachments } from "@/components/Attachments";
|
||||
import { ConfirmDialog } from "@/components/ConfirmDialog";
|
||||
import { toast } from "@/components/ToastProvider";
|
||||
import { toast } from "@/lib/toast";
|
||||
|
||||
type TabKey = "contracts" | "warranties";
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import { Modal } from "@/components/ui/dialog";
|
||||
import { DemoStatusBadge } from "@/components/StatusBadge";
|
||||
import { Attachments } from "@/components/Attachments";
|
||||
import { ConfirmDialog } from "@/components/ConfirmDialog";
|
||||
import { toast } from "@/components/ToastProvider";
|
||||
import { toast } from "@/lib/toast";
|
||||
|
||||
type ViewTab = "active" | "returned" | "all";
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import { AssetPicker } from "@/components/AssetPicker";
|
||||
import { Attachments } from "@/components/Attachments";
|
||||
import { InsuranceDrawer } from "@/components/InsuranceDrawer";
|
||||
import { ConfirmDialog } from "@/components/ConfirmDialog";
|
||||
import { toast } from "@/components/ToastProvider";
|
||||
import { toast } from "@/lib/toast";
|
||||
|
||||
const inputCls =
|
||||
"w-full px-3 py-2 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500";
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
import { formatDate, formatDateTime } from "@/lib/format";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { toast } from "@/components/ToastProvider";
|
||||
import { toast } from "@/lib/toast";
|
||||
|
||||
const TYPE_OPTIONS: { value: NotificationType | ""; label: string }[] = [
|
||||
{ value: "", label: "All Types" },
|
||||
|
||||
@@ -36,7 +36,7 @@ import { useAuthStore } from "@/hooks/useAuth";
|
||||
import { formatDateTime } from "@/lib/format";
|
||||
import { DataTable } from "@/components/DataTable";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { toast } from "@/components/ToastProvider";
|
||||
import { toast } from "@/lib/toast";
|
||||
|
||||
function currentMonthStr(): string {
|
||||
const d = new Date();
|
||||
@@ -94,6 +94,26 @@ function humanizeSummaryKey(key: string): string {
|
||||
);
|
||||
}
|
||||
|
||||
function computeUptimePct(record: Record<string, unknown>): string {
|
||||
const upRaw = record.total_uptime_minutes ?? record.uptime_seconds;
|
||||
const downRaw = record.total_downtime_minutes ?? record.downtime_seconds;
|
||||
if (upRaw != null && downRaw != null) {
|
||||
const up = Number(upRaw);
|
||||
const down = Number(downRaw);
|
||||
const total = up + down;
|
||||
if (Number.isFinite(total) && total > 0) {
|
||||
return `${((up / total) * 100).toFixed(1)} %`;
|
||||
}
|
||||
}
|
||||
if (record.downtime_pct != null) {
|
||||
const dtPct = Number(record.downtime_pct);
|
||||
if (Number.isFinite(dtPct)) {
|
||||
return `${Math.max(0, 100 - dtPct).toFixed(1)} %`;
|
||||
}
|
||||
}
|
||||
return "—";
|
||||
}
|
||||
|
||||
export function ReportDetailPage() {
|
||||
const { reportKey } = useParams<{ reportKey: string }>();
|
||||
const user = useAuthStore((s) => s.user);
|
||||
@@ -215,18 +235,44 @@ export function ReportDetailPage() {
|
||||
|
||||
const columns: ColumnDef<Record<string, unknown>, unknown>[] = useMemo(() => {
|
||||
if (!report) return [];
|
||||
return report.columns.map((col) => ({
|
||||
id: col.key,
|
||||
accessorFn: (row) => row[col.key],
|
||||
header: col.label,
|
||||
cell: ({ getValue }) => {
|
||||
const val = getValue();
|
||||
if (val === null || val === undefined || val === "") return "—";
|
||||
if (typeof val === "boolean") return val ? "Yes" : "No";
|
||||
return String(val);
|
||||
},
|
||||
}));
|
||||
}, [report]);
|
||||
const baseCols: ColumnDef<Record<string, unknown>, unknown>[] = report.columns.map(
|
||||
(col) => ({
|
||||
id: col.key,
|
||||
accessorFn: (row) => row[col.key],
|
||||
header: col.label,
|
||||
cell: ({ getValue }) => {
|
||||
const val = getValue();
|
||||
if (val === null || val === undefined || val === "") return "—";
|
||||
if (typeof val === "boolean") return val ? "Yes" : "No";
|
||||
return String(val);
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
if (
|
||||
key === "monthly-maintenance" &&
|
||||
!report.columns.some((c) => c.key === "uptime_pct")
|
||||
) {
|
||||
const uptimePctCol: ColumnDef<Record<string, unknown>, unknown> = {
|
||||
id: "uptime_pct",
|
||||
accessorFn: (row) => computeUptimePct(row),
|
||||
header: "Uptime %",
|
||||
cell: ({ getValue }) => (
|
||||
<span className="font-semibold text-emerald-700 whitespace-nowrap">
|
||||
{String(getValue() ?? "—")}
|
||||
</span>
|
||||
),
|
||||
};
|
||||
const dtPctIdx = baseCols.findIndex((c) => c.id === "downtime_pct");
|
||||
if (dtPctIdx >= 0) {
|
||||
baseCols.splice(dtPctIdx, 0, uptimePctCol);
|
||||
} else {
|
||||
baseCols.push(uptimePctCol);
|
||||
}
|
||||
}
|
||||
|
||||
return baseCols;
|
||||
}, [report, key]);
|
||||
|
||||
async function handleExport(format: "xlsx" | "csv") {
|
||||
if (!key) return;
|
||||
@@ -701,6 +747,16 @@ export function ReportDetailPage() {
|
||||
{/* Summary Strip */}
|
||||
{report && (
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-2.5 print-break-inside-avoid">
|
||||
{key === "monthly-maintenance" && (
|
||||
<div className="bg-emerald-50 border border-emerald-300 rounded-lg p-3">
|
||||
<div className="text-[11px] font-semibold text-emerald-800">
|
||||
Uptime %
|
||||
</div>
|
||||
<div className="text-xl font-bold text-emerald-900 mt-0.5 truncate">
|
||||
{computeUptimePct(report.summary)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{Object.entries(report.summary).map(([sKey, sVal]) => (
|
||||
<div
|
||||
key={sKey}
|
||||
|
||||
@@ -168,7 +168,7 @@ export function SettingsPage() {
|
||||
onChange={(e) => handleChange(item, e.target.checked)}
|
||||
className="h-4 w-4 rounded border-gray-300 text-[#1e3a8a] focus:ring-blue-500"
|
||||
/>
|
||||
<span className="text-sm text-gray-700">{Boolean(val) ? "Enabled" : "Disabled"}</span>
|
||||
<span className="text-sm text-gray-700">{val ? "Enabled" : "Disabled"}</span>
|
||||
</label>
|
||||
)}
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// Stub pages — replaced phase by phase
|
||||
|
||||
interface StubProps {
|
||||
title: string;
|
||||
phase: number;
|
||||
description?: string;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
function StubPage({ title, phase, description, children }: StubProps) {
|
||||
return (
|
||||
<div className="max-w-lg mx-auto mt-16 text-center">
|
||||
<div className="inline-flex items-center justify-center w-16 h-16 rounded-full bg-blue-50 mb-4">
|
||||
<span className="text-2xl">🏗️</span>
|
||||
</div>
|
||||
<h2 className="text-xl font-semibold text-gray-800 mb-2">{title}</h2>
|
||||
{description && <p className="text-gray-500 text-sm mb-4">{description}</p>}
|
||||
<div className="inline-flex items-center gap-2 bg-amber-50 border border-amber-200 text-amber-700 px-4 py-2 rounded-full text-sm font-medium">
|
||||
Coming in Phase {phase}
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const ReportsPage = () => (
|
||||
<StubPage title="Reports & Exports" phase={7} description="8 reports with Excel export." />
|
||||
);
|
||||
@@ -1,7 +1,8 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { Attachments, validateAttachmentFile } from "@/components/Attachments";
|
||||
import { Attachments } from "@/components/Attachments";
|
||||
import { validateAttachmentFile } from "@/lib/validation";
|
||||
import { attachmentsApi } from "@/api/attachments";
|
||||
|
||||
function renderWithQuery(ui: React.ReactNode) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import { render, screen, waitFor, fireEvent } from "@testing-library/react";
|
||||
import { MemoryRouter, Route, Routes } from "react-router-dom";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { ComplaintDetailPage } from "@/pages/ComplaintDetailPage";
|
||||
@@ -145,5 +145,22 @@ describe("ComplaintDetailPage", () => {
|
||||
screen.getByRole("button", { name: /Save Technical Details/i })
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByDisplayValue("Replaced flow sensor")).toBeInTheDocument();
|
||||
|
||||
const closeSpy = vi.spyOn(complaintsApi, "close").mockResolvedValue(MOCK_COMPLAINT);
|
||||
fireEvent.click(screen.getByRole("button", { name: /Close Call/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Close Complaint Call")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
const remarksInput = screen.getByLabelText(/Closure Remarks/i);
|
||||
expect(remarksInput).toBeRequired();
|
||||
|
||||
const submitForm = remarksInput.closest("form")!;
|
||||
fireEvent.submit(submitForm);
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Closure remarks are required.")).toBeInTheDocument();
|
||||
});
|
||||
expect(closeSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -151,6 +151,7 @@ describe("Phase 7 Reports", () => {
|
||||
screen.getByRole("heading", { name: /Monthly Maintenance Summary/i })
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText("Distinct Downtime Days")).toBeInTheDocument();
|
||||
expect(screen.getAllByText("99.6 %").length).toBeGreaterThanOrEqual(2);
|
||||
expect(screen.getByRole("cell", { name: "ICU" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user