feat: complete requirements gaps - backup/restore, uat signoff, pm attachments, templates, and filters
This commit is contained in:
@@ -200,6 +200,8 @@ export interface AssetListParams {
|
||||
supplier_id?: number;
|
||||
status?: AssetStatus | "";
|
||||
criticality?: AssetCriticality | "";
|
||||
requires_calibration?: boolean;
|
||||
insurance_applicable?: boolean;
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
sort?: string;
|
||||
@@ -264,6 +266,8 @@ export const assetsApi = {
|
||||
if (params.supplier_id) qs.set("supplier_id", String(params.supplier_id));
|
||||
if (params.status) qs.set("status", params.status);
|
||||
if (params.criticality) qs.set("criticality", params.criticality);
|
||||
if (params.requires_calibration !== undefined) qs.set("requires_calibration", String(params.requires_calibration));
|
||||
if (params.insurance_applicable !== undefined) qs.set("insurance_applicable", String(params.insurance_applicable));
|
||||
qs.set("page", String(params.page ?? 1));
|
||||
qs.set("page_size", String(params.page_size ?? 200));
|
||||
if (params.sort) qs.set("sort", params.sort);
|
||||
|
||||
@@ -7,7 +7,8 @@ export type AttachmentEntityType =
|
||||
| "insurance"
|
||||
| "demo_equipment"
|
||||
| "asset"
|
||||
| "warranty";
|
||||
| "warranty"
|
||||
| "pm_record";
|
||||
|
||||
export interface AttachmentItem {
|
||||
id: number;
|
||||
|
||||
@@ -142,4 +142,15 @@ export const calibrationApi = {
|
||||
completed_record: CalibrationRecordItem;
|
||||
next_record: CalibrationRecordItem;
|
||||
}>(`/calibration/records/${id}/complete`, data),
|
||||
downloadImportTemplate: async () => {
|
||||
const { blob } = await api.downloadBlob("/calibration/import-template");
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "calibration_import_template.xlsx";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -33,6 +33,7 @@ export interface ComplaintItem {
|
||||
received_at: string | null;
|
||||
assigned_to_id: number | null;
|
||||
assigned_to_name: string | null;
|
||||
assigned_team?: string | null;
|
||||
assigned_at: string | null;
|
||||
attended_by_id: number | null;
|
||||
attended_by_name: string | null;
|
||||
@@ -77,6 +78,7 @@ export interface ComplaintEventItem {
|
||||
export interface ComplaintListParams {
|
||||
q?: string;
|
||||
department_id?: number;
|
||||
location_id?: number;
|
||||
asset_id?: number;
|
||||
call_status?: CallStatus | "";
|
||||
priority?: AssetCriticality | "";
|
||||
@@ -94,6 +96,7 @@ export interface ComplaintCreatePayload {
|
||||
breakdown_details?: string | null;
|
||||
priority: AssetCriticality;
|
||||
notes?: string | null;
|
||||
assigned_team?: string | null;
|
||||
received_by_id?: number | null;
|
||||
}
|
||||
|
||||
@@ -102,6 +105,7 @@ export interface ComplaintUpdatePayload {
|
||||
breakdown_details?: string | null;
|
||||
priority?: AssetCriticality;
|
||||
notes?: string | null;
|
||||
assigned_team?: string | null;
|
||||
action_taken?: string | null;
|
||||
root_cause?: string | null;
|
||||
corrective_action?: string | null;
|
||||
@@ -119,6 +123,7 @@ export const complaintsApi = {
|
||||
const qs = new URLSearchParams();
|
||||
if (params.q) qs.set("q", params.q);
|
||||
if (params.department_id) qs.set("department_id", String(params.department_id));
|
||||
if (params.location_id) qs.set("location_id", String(params.location_id));
|
||||
if (params.asset_id) qs.set("asset_id", String(params.asset_id));
|
||||
if (params.call_status) qs.set("call_status", params.call_status);
|
||||
if (params.priority) qs.set("priority", params.priority);
|
||||
@@ -136,7 +141,7 @@ export const complaintsApi = {
|
||||
api.get<{ items: ComplaintEventItem[]; total: number }>(`/complaints/${id}/events`),
|
||||
update: (id: number, data: ComplaintUpdatePayload) =>
|
||||
api.patch<ComplaintItem>(`/complaints/${id}`, data),
|
||||
assign: (id: number, data: { assigned_to_id: number; note?: string }) =>
|
||||
assign: (id: number, data: { assigned_to_id?: number | null; assigned_team?: string | null; note?: string }) =>
|
||||
api.post<ComplaintItem>(`/complaints/${id}/assign`, data),
|
||||
attend: (id: number, data: { attended_by_id?: number; note?: string } = {}) =>
|
||||
api.post<ComplaintItem>(`/complaints/${id}/attend`, data),
|
||||
|
||||
@@ -141,6 +141,7 @@ export interface DemoEquipmentItem {
|
||||
id: number;
|
||||
name: string;
|
||||
equipment_type: string;
|
||||
serial_no?: string | null;
|
||||
supplier_id: number;
|
||||
supplier_name: string | null;
|
||||
department_id: number;
|
||||
@@ -172,6 +173,7 @@ export interface DemoListParams {
|
||||
export interface DemoCreatePayload {
|
||||
name: string;
|
||||
equipment_type: string;
|
||||
serial_no?: string | null;
|
||||
supplier_id: number;
|
||||
department_id: number;
|
||||
location_id?: number | null;
|
||||
@@ -202,6 +204,7 @@ export interface VisitItem {
|
||||
visited_by_name: string | null;
|
||||
visit_date: string;
|
||||
observations: string;
|
||||
new_requirements?: string | null;
|
||||
assets: VisitAssetBrief[];
|
||||
complaints: VisitComplaintBrief[];
|
||||
created_at: string;
|
||||
@@ -221,6 +224,7 @@ export interface VisitCreatePayload {
|
||||
department_id: number;
|
||||
visit_date: string;
|
||||
observations: string;
|
||||
new_requirements?: string | null;
|
||||
asset_ids?: number[];
|
||||
complaint_ids?: number[];
|
||||
}
|
||||
@@ -251,6 +255,17 @@ export const contractsApi = {
|
||||
),
|
||||
history: (assetId: number) =>
|
||||
api.get<{ items: ContractItem[] }>(`/contracts/history/${assetId}`),
|
||||
downloadImportTemplate: async () => {
|
||||
const { blob } = await api.downloadBlob("/contracts/import-template");
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "contracts_import_template.xlsx";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
},
|
||||
};
|
||||
|
||||
export const warrantiesApi = {
|
||||
@@ -273,6 +288,17 @@ export const insuranceApi = {
|
||||
update: (id: number, data: Partial<InsuranceCreatePayload>) =>
|
||||
api.patch<InsuranceItem>(`/insurance/${id}`, data),
|
||||
remove: (id: number) => api.delete<void>(`/insurance/${id}`),
|
||||
downloadImportTemplate: async () => {
|
||||
const { blob } = await api.downloadBlob("/insurance/import-template");
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "insurance_import_template.xlsx";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
},
|
||||
};
|
||||
|
||||
export const demoEquipmentApi = {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { ApiError } from "@/api/client";
|
||||
import { assetsApi, type AssetLookupItem } from "@/api/assets";
|
||||
import { vendorsApi } from "@/api/masters";
|
||||
import { pmApi, type ServiceMode } from "@/api/pm";
|
||||
import { attachmentsApi } from "@/api/attachments";
|
||||
|
||||
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";
|
||||
@@ -250,6 +251,7 @@ export function CompletePMModal({
|
||||
const [completedDate, setCompletedDate] = useState("");
|
||||
const [serviceDetails, setServiceDetails] = useState("");
|
||||
const [remarks, setRemarks] = useState("");
|
||||
const [reportFile, setReportFile] = useState<File | null>(null);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
@@ -258,6 +260,7 @@ export function CompletePMModal({
|
||||
setCompletedDate(new Date().toISOString().slice(0, 10));
|
||||
setServiceDetails("");
|
||||
setRemarks("");
|
||||
setReportFile(null);
|
||||
setError(null);
|
||||
}, [open, recordId]);
|
||||
|
||||
@@ -272,8 +275,12 @@ export function CompletePMModal({
|
||||
service_details: serviceDetails.trim(),
|
||||
remarks: remarks.trim() || null,
|
||||
});
|
||||
if (reportFile) {
|
||||
await attachmentsApi.upload("pm_record", recordId, reportFile);
|
||||
}
|
||||
await qc.invalidateQueries({ queryKey: ["pm-records"] });
|
||||
await qc.invalidateQueries({ queryKey: ["pm-schedules"] });
|
||||
await qc.invalidateQueries({ queryKey: ["attachments", "pm_record", recordId] });
|
||||
if (assetId) await qc.invalidateQueries({ queryKey: ["asset-overview", assetId] });
|
||||
onClose();
|
||||
} catch (err) {
|
||||
@@ -317,6 +324,15 @@ export function CompletePMModal({
|
||||
className={inputCls}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className={labelCls}>Service Report / Checklist (optional)</label>
|
||||
<input
|
||||
type="file"
|
||||
accept=".pdf,.png,.jpg,.jpeg,.doc,.docx"
|
||||
onChange={(e) => setReportFile(e.target.files?.[0] ?? null)}
|
||||
className="w-full text-xs text-gray-700 file:mr-3 file:py-1.5 file:px-3 file:rounded-md file:border-0 file:text-xs file:font-medium file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100 border border-gray-200 rounded-md p-1"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2 pt-2">
|
||||
<Button type="button" variant="outline" onClick={onClose}>
|
||||
Cancel
|
||||
|
||||
@@ -34,6 +34,8 @@ export function AssetsPage() {
|
||||
|
||||
const [selectedDeptId, setSelectedDeptId] = useState<number | undefined>(undefined);
|
||||
const [selectedStatus, setSelectedStatus] = useState<AssetStatus | "">("");
|
||||
const [calibrationFilter, setCalibrationFilter] = useState<"all" | "required" | "not_required">("all");
|
||||
const [insuranceFilter, setInsuranceFilter] = useState<"all" | "insured" | "uninsured">("all");
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [bulkOpen, setBulkOpen] = useState(false);
|
||||
|
||||
@@ -44,11 +46,29 @@ export function AssetsPage() {
|
||||
});
|
||||
|
||||
const assetsQuery = useQuery({
|
||||
queryKey: ["assets", selectedDeptId ?? "all", selectedStatus || "all"],
|
||||
queryKey: [
|
||||
"assets",
|
||||
selectedDeptId ?? "all",
|
||||
selectedStatus || "all",
|
||||
calibrationFilter,
|
||||
insuranceFilter,
|
||||
],
|
||||
queryFn: () =>
|
||||
assetsApi.list({
|
||||
department_id: isDeptUser ? undefined : selectedDeptId,
|
||||
status: selectedStatus || undefined,
|
||||
requires_calibration:
|
||||
calibrationFilter === "required"
|
||||
? true
|
||||
: calibrationFilter === "not_required"
|
||||
? false
|
||||
: undefined,
|
||||
insurance_applicable:
|
||||
insuranceFilter === "insured"
|
||||
? true
|
||||
: insuranceFilter === "uninsured"
|
||||
? false
|
||||
: undefined,
|
||||
page_size: 200,
|
||||
}),
|
||||
});
|
||||
@@ -208,6 +228,48 @@ export function AssetsPage() {
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1.5 flex-wrap">
|
||||
<span className="text-xs font-medium text-gray-500 mr-1">Calibration:</span>
|
||||
{[
|
||||
{ value: "all", label: "All" },
|
||||
{ value: "required", label: "Calibration Required" },
|
||||
{ value: "not_required", label: "Not Required" },
|
||||
].map((chip) => (
|
||||
<button
|
||||
key={chip.value}
|
||||
type="button"
|
||||
onClick={() => setCalibrationFilter(chip.value as typeof calibrationFilter)}
|
||||
className={`px-2.5 py-1 rounded-full text-xs font-medium transition-colors ${
|
||||
calibrationFilter === chip.value
|
||||
? "bg-emerald-700 text-white"
|
||||
: "bg-white border border-gray-200 text-gray-700 hover:bg-gray-50"
|
||||
}`}
|
||||
>
|
||||
{chip.label}
|
||||
</button>
|
||||
))}
|
||||
|
||||
<span className="text-xs font-medium text-gray-500 ml-3 mr-1">Insurance:</span>
|
||||
{[
|
||||
{ value: "all", label: "All" },
|
||||
{ value: "insured", label: "Insurance Applicable" },
|
||||
{ value: "uninsured", label: "Not Applicable" },
|
||||
].map((chip) => (
|
||||
<button
|
||||
key={chip.value}
|
||||
type="button"
|
||||
onClick={() => setInsuranceFilter(chip.value as typeof insuranceFilter)}
|
||||
className={`px-2.5 py-1 rounded-full text-xs font-medium transition-colors ${
|
||||
insuranceFilter === chip.value
|
||||
? "bg-purple-700 text-white"
|
||||
: "bg-white border border-gray-200 text-gray-700 hover:bg-gray-50"
|
||||
}`}
|
||||
>
|
||||
{chip.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DataTable
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import type { ColumnDef } from "@tanstack/react-table";
|
||||
import { Plus, CheckCircle2, Paperclip, ShieldCheck, Search } from "lucide-react";
|
||||
import { Plus, CheckCircle2, Paperclip, ShieldCheck, Search, Download } from "lucide-react";
|
||||
import {
|
||||
calibrationApi,
|
||||
type CalibrationRecordItem,
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
ApproveCalibrationPlanModal,
|
||||
CompleteCalibrationModal,
|
||||
} from "@/components/CalibrationModals";
|
||||
import { toast } from "@/lib/toast";
|
||||
|
||||
type CalTab = "records" | "plans";
|
||||
|
||||
@@ -298,10 +299,26 @@ export function CalibrationPage() {
|
||||
</p>
|
||||
</div>
|
||||
{canAddCalPlan && (
|
||||
<Button onClick={() => setBulkAddOpen(true)}>
|
||||
<Plus className="h-4 w-4 mr-1.5" />
|
||||
Add Equipment to Calibration
|
||||
</Button>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={async () => {
|
||||
try {
|
||||
await calibrationApi.downloadImportTemplate();
|
||||
toast.success("Downloaded Calibration import template (.xlsx)");
|
||||
} catch {
|
||||
toast.error("Failed to download template");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Download className="h-4 w-4 mr-1.5" />
|
||||
Template (.xlsx)
|
||||
</Button>
|
||||
<Button onClick={() => setBulkAddOpen(true)}>
|
||||
<Plus className="h-4 w-4 mr-1.5" />
|
||||
Add Equipment to Calibration
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ export function ComplaintDetailPage() {
|
||||
// Modals
|
||||
const [assignOpen, setAssignOpen] = useState(false);
|
||||
const [assignUserId, setAssignUserId] = useState<string>("");
|
||||
const [assignTeam, setAssignTeam] = useState<string>("");
|
||||
const [assignNote, setAssignNote] = useState("");
|
||||
|
||||
const [closeOpen, setCloseOpen] = useState(false);
|
||||
@@ -173,12 +174,14 @@ export function ComplaintDetailPage() {
|
||||
const assignMutation = useMutation({
|
||||
mutationFn: () =>
|
||||
complaintsApi.assign(complaintId, {
|
||||
assigned_to_id: Number(assignUserId),
|
||||
assigned_to_id: assignUserId ? Number(assignUserId) : undefined,
|
||||
assigned_team: assignTeam.trim() || undefined,
|
||||
note: assignNote.trim() || undefined,
|
||||
}),
|
||||
onSuccess: async () => {
|
||||
setActionError(null);
|
||||
setAssignOpen(false);
|
||||
setAssignTeam("");
|
||||
setAssignNote("");
|
||||
await refreshAll();
|
||||
},
|
||||
@@ -432,7 +435,9 @@ export function ComplaintDetailPage() {
|
||||
label="Assigned"
|
||||
value={
|
||||
c.assigned_to_name
|
||||
? `${c.assigned_to_name} (${formatDateTime(c.assigned_at)})`
|
||||
? `${c.assigned_to_name}${c.assigned_team ? ` (${c.assigned_team})` : ""} (${formatDateTime(c.assigned_at)})`
|
||||
: c.assigned_team
|
||||
? `Team: ${c.assigned_team} (${formatDateTime(c.assigned_at)})`
|
||||
: "Unassigned"
|
||||
}
|
||||
/>
|
||||
@@ -523,6 +528,7 @@ export function ComplaintDetailPage() {
|
||||
? String(techUsers[0].id)
|
||||
: ""
|
||||
);
|
||||
setAssignTeam(c.assigned_team ?? "");
|
||||
setAssignOpen(true);
|
||||
}}
|
||||
>
|
||||
@@ -878,6 +884,16 @@ export function ComplaintDetailPage() {
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className={labelCls}>Assigned Team (optional)</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="e.g. Biomedical Bio-Eng Team A, Philips CE"
|
||||
value={assignTeam}
|
||||
onChange={(e) => setAssignTeam(e.target.value)}
|
||||
className={inputCls}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className={labelCls}>Note (optional)</label>
|
||||
<textarea
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
type CallStatus,
|
||||
} from "@/api/complaints";
|
||||
import type { AssetCriticality } from "@/api/assets";
|
||||
import { departmentsApi, fetchUsersLookup } from "@/api/masters";
|
||||
import { departmentsApi, locationsApi, fetchUsersLookup } from "@/api/masters";
|
||||
import { useAuthStore } from "@/hooks/useAuth";
|
||||
import { can } from "@/lib/permissions";
|
||||
import { formatDateTime, formatDuration } from "@/lib/format";
|
||||
@@ -35,6 +35,7 @@ export function ComplaintsPage() {
|
||||
|
||||
const [q, setQ] = useState("");
|
||||
const [departmentId, setDepartmentId] = useState<string>("");
|
||||
const [locationId, setLocationId] = useState<string>("");
|
||||
const [callStatus, setCallStatus] = useState<CallStatus | "">("");
|
||||
const [priority, setPriority] = useState<AssetCriticality | "">("");
|
||||
const [assignedToId, setAssignedToId] = useState<string>("");
|
||||
@@ -49,6 +50,11 @@ export function ComplaintsPage() {
|
||||
enabled: !isDeptUser,
|
||||
});
|
||||
|
||||
const locationsQuery = useQuery({
|
||||
queryKey: ["locations", "active-only"],
|
||||
queryFn: () => locationsApi.list(false),
|
||||
});
|
||||
|
||||
const usersQuery = useQuery({
|
||||
queryKey: ["users-lookup"],
|
||||
queryFn: fetchUsersLookup,
|
||||
@@ -59,6 +65,7 @@ export function ComplaintsPage() {
|
||||
"complaints",
|
||||
q,
|
||||
departmentId,
|
||||
locationId,
|
||||
callStatus,
|
||||
priority,
|
||||
assignedToId,
|
||||
@@ -70,6 +77,7 @@ export function ComplaintsPage() {
|
||||
complaintsApi.list({
|
||||
q: q.trim() || undefined,
|
||||
department_id: !isDeptUser && departmentId ? Number(departmentId) : undefined,
|
||||
location_id: locationId ? Number(locationId) : undefined,
|
||||
call_status: callStatus || undefined,
|
||||
priority: priority || undefined,
|
||||
assigned_to_id: assignedToId ? Number(assignedToId) : undefined,
|
||||
@@ -177,6 +185,10 @@ export function ComplaintsPage() {
|
||||
];
|
||||
|
||||
const departments = deptsQuery.data?.items ?? [];
|
||||
const allLocations = locationsQuery.data?.items ?? [];
|
||||
const filteredLocations = departmentId
|
||||
? allLocations.filter((l) => l.department_id === Number(departmentId))
|
||||
: allLocations;
|
||||
const techUsers = (usersQuery.data?.items ?? []).filter(
|
||||
(u) => u.role === "biomedical" || u.role === "system_admin"
|
||||
);
|
||||
@@ -235,7 +247,10 @@ export function ComplaintsPage() {
|
||||
{!isDeptUser && (
|
||||
<select
|
||||
value={departmentId}
|
||||
onChange={(e) => setDepartmentId(e.target.value)}
|
||||
onChange={(e) => {
|
||||
setDepartmentId(e.target.value);
|
||||
setLocationId("");
|
||||
}}
|
||||
aria-label="Filter by Department"
|
||||
className="px-2.5 py-1.5 text-xs border border-gray-200 rounded-md bg-white"
|
||||
>
|
||||
@@ -248,6 +263,20 @@ export function ComplaintsPage() {
|
||||
</select>
|
||||
)}
|
||||
|
||||
<select
|
||||
value={locationId}
|
||||
onChange={(e) => setLocationId(e.target.value)}
|
||||
aria-label="Filter by Location"
|
||||
className="px-2.5 py-1.5 text-xs border border-gray-200 rounded-md bg-white"
|
||||
>
|
||||
<option value="">All Locations</option>
|
||||
{filteredLocations.map((loc) => (
|
||||
<option key={loc.id} value={String(loc.id)}>
|
||||
{loc.name} {loc.floor_wing ? `(${loc.floor_wing})` : ""}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
<select
|
||||
value={priority}
|
||||
onChange={(e) => setPriority(e.target.value as AssetCriticality | "")}
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
Trash2,
|
||||
Search,
|
||||
AlertCircle,
|
||||
Download,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
contractsApi,
|
||||
@@ -469,20 +470,38 @@ export function ContractsPage() {
|
||||
</p>
|
||||
</div>
|
||||
{canManage && (
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (tab === "contracts") {
|
||||
setEditingContract(null);
|
||||
setContractFormOpen(true);
|
||||
} else {
|
||||
setEditingWarranty(null);
|
||||
setWarrantyFormOpen(true);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-1.5" />
|
||||
{tab === "contracts" ? "Add Contract" : "Add Warranty"}
|
||||
</Button>
|
||||
<div className="flex items-center gap-2">
|
||||
{tab === "contracts" && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={async () => {
|
||||
try {
|
||||
await contractsApi.downloadImportTemplate();
|
||||
toast.success("Downloaded Contract import template (.xlsx)");
|
||||
} catch {
|
||||
toast.error("Failed to download template");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Download className="h-4 w-4 mr-1.5" />
|
||||
Template (.xlsx)
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (tab === "contracts") {
|
||||
setEditingContract(null);
|
||||
setContractFormOpen(true);
|
||||
} else {
|
||||
setEditingWarranty(null);
|
||||
setWarrantyFormOpen(true);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-1.5" />
|
||||
{tab === "contracts" ? "Add Contract" : "Add Warranty"}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -119,14 +119,19 @@ export function DemoEquipmentPage() {
|
||||
const columns: ColumnDef<DemoEquipmentItem, unknown>[] = [
|
||||
{
|
||||
id: "equipment",
|
||||
accessorFn: (r) => `${r.name} ${r.equipment_type ?? ""}`,
|
||||
accessorFn: (r) => `${r.name} ${r.equipment_type ?? ""} ${r.serial_no ?? ""}`,
|
||||
header: "Equipment",
|
||||
cell: ({ row }) => (
|
||||
<div>
|
||||
<div className="font-medium text-gray-900">{row.original.name}</div>
|
||||
{row.original.equipment_type && (
|
||||
<div className="text-xs text-gray-500">{row.original.equipment_type}</div>
|
||||
)}
|
||||
<div className="text-xs text-gray-500">
|
||||
{[
|
||||
row.original.equipment_type,
|
||||
row.original.serial_no ? `SN: ${row.original.serial_no}` : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" • ")}
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
@@ -428,6 +433,7 @@ function DemoFormModal({
|
||||
const qc = useQueryClient();
|
||||
const [name, setName] = useState("");
|
||||
const [equipmentType, setEquipmentType] = useState("");
|
||||
const [serialNo, setSerialNo] = useState("");
|
||||
const [supplierId, setSupplierId] = useState("");
|
||||
const [departmentId, setDepartmentId] = useState("");
|
||||
const [locationId, setLocationId] = useState("");
|
||||
@@ -443,6 +449,7 @@ function DemoFormModal({
|
||||
if (editing) {
|
||||
setName(editing.name);
|
||||
setEquipmentType(editing.equipment_type ?? "");
|
||||
setSerialNo(editing.serial_no ?? "");
|
||||
setSupplierId(String(editing.supplier_id));
|
||||
setDepartmentId(String(editing.department_id));
|
||||
setLocationId(editing.location_id ? String(editing.location_id) : "");
|
||||
@@ -455,6 +462,7 @@ function DemoFormModal({
|
||||
plus14.setDate(plus14.getDate() + 14);
|
||||
setName("");
|
||||
setEquipmentType("");
|
||||
setSerialNo("");
|
||||
setSupplierId("");
|
||||
setDepartmentId("");
|
||||
setLocationId("");
|
||||
@@ -476,6 +484,7 @@ function DemoFormModal({
|
||||
const payload = {
|
||||
name: name.trim(),
|
||||
equipment_type: equipmentType.trim(),
|
||||
serial_no: serialNo.trim() || null,
|
||||
supplier_id: Number(supplierId),
|
||||
department_id: Number(departmentId),
|
||||
location_id: locationId ? Number(locationId) : null,
|
||||
@@ -537,6 +546,16 @@ function DemoFormModal({
|
||||
className={inputCls}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className={labelCls}>Serial Number</label>
|
||||
<input
|
||||
type="text"
|
||||
value={serialNo}
|
||||
onChange={(e) => setSerialNo(e.target.value)}
|
||||
placeholder="e.g. SN-DEMO-901"
|
||||
className={inputCls}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className={labelCls}>Supplier *</label>
|
||||
<select
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
ShieldCheck,
|
||||
Search,
|
||||
AlertCircle,
|
||||
Download,
|
||||
} from "lucide-react";
|
||||
import { insuranceApi, type InsuranceItem } from "@/api/phase5";
|
||||
import { assetsApi, type AssetLookupItem } from "@/api/assets";
|
||||
@@ -238,15 +239,31 @@ export function InsurancePage() {
|
||||
</p>
|
||||
</div>
|
||||
{canManage && (
|
||||
<Button
|
||||
onClick={() => {
|
||||
setEditing(null);
|
||||
setFormOpen(true);
|
||||
}}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-1.5" />
|
||||
Add Insurance Policy
|
||||
</Button>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={async () => {
|
||||
try {
|
||||
await insuranceApi.downloadImportTemplate();
|
||||
toast.success("Downloaded Insurance import template (.xlsx)");
|
||||
} catch {
|
||||
toast.error("Failed to download template");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Download className="h-4 w-4 mr-1.5" />
|
||||
Template (.xlsx)
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setEditing(null);
|
||||
setFormOpen(true);
|
||||
}}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-1.5" />
|
||||
Add Insurance Policy
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
Search,
|
||||
Paperclip,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
pmApi,
|
||||
@@ -28,6 +29,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Modal } from "@/components/ui/dialog";
|
||||
import { ScheduleStatusBadge } from "@/components/StatusBadge";
|
||||
import { Attachments } from "@/components/Attachments";
|
||||
import {
|
||||
NewPMScheduleModal,
|
||||
CompletePMModal,
|
||||
@@ -96,6 +98,7 @@ export function PMPage() {
|
||||
const [completingRec, setCompletingRec] = useState<PMRecordItem | null>(null);
|
||||
const [reschedulingRec, setReschedulingRec] = useState<PMRecordItem | null>(null);
|
||||
const [calendarDetailRec, setCalendarDetailRec] = useState<PMRecordItem | null>(null);
|
||||
const [attachRec, setAttachRec] = useState<PMRecordItem | null>(null);
|
||||
|
||||
const effectiveCalendarMonth = monthFilter || currentYearMonth();
|
||||
|
||||
@@ -236,6 +239,23 @@ export function PMPage() {
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "attachments",
|
||||
header: "Reports",
|
||||
enableSorting: false,
|
||||
enableColumnFilter: false,
|
||||
cell: ({ row }) => (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => setAttachRec(row.original)}
|
||||
aria-label={`Attachments for PM ${row.original.id}`}
|
||||
>
|
||||
<Paperclip className="h-3.5 w-3.5 mr-1" />
|
||||
Docs
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
...(canManagePm
|
||||
? [
|
||||
{
|
||||
@@ -726,6 +746,21 @@ export function PMPage() {
|
||||
}
|
||||
assetId={reschedulingRec?.asset_id}
|
||||
/>
|
||||
|
||||
{attachRec && (
|
||||
<Modal
|
||||
open={Boolean(attachRec)}
|
||||
onOpenChange={(o) => !o && setAttachRec(null)}
|
||||
title={`PM Service Reports — ${attachRec.asset_code} (${attachRec.asset_name})`}
|
||||
>
|
||||
<Attachments
|
||||
entityType="pm_record"
|
||||
entityId={attachRec.id}
|
||||
canUpload={canManagePm}
|
||||
canDelete={canManagePm}
|
||||
/>
|
||||
</Modal>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -106,11 +106,16 @@ export function VisitsPage() {
|
||||
},
|
||||
{
|
||||
accessorKey: "observations",
|
||||
header: "Observations",
|
||||
cell: ({ getValue }) => (
|
||||
<p className="text-xs text-gray-800 whitespace-pre-wrap max-w-sm">
|
||||
{String(getValue())}
|
||||
</p>
|
||||
header: "Observations & Requirements",
|
||||
cell: ({ row }) => (
|
||||
<div className="space-y-1 max-w-sm">
|
||||
<p className="text-xs text-gray-800 whitespace-pre-wrap">{row.original.observations}</p>
|
||||
{row.original.new_requirements && (
|
||||
<p className="text-xs text-blue-700 bg-blue-50 border border-blue-100 rounded px-1.5 py-0.5">
|
||||
<span className="font-semibold">Requirements:</span> {row.original.new_requirements}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
@@ -292,6 +297,7 @@ function VisitFormModal({
|
||||
const [departmentId, setDepartmentId] = useState("");
|
||||
const [visitDate, setVisitDate] = useState("");
|
||||
const [observations, setObservations] = useState("");
|
||||
const [newRequirements, setNewRequirements] = useState("");
|
||||
const [selectedAssetIds, setSelectedAssetIds] = useState<number[]>([]);
|
||||
const [assetSearch, setAssetSearch] = useState("");
|
||||
const [raiseImmediately, setRaiseImmediately] = useState(false);
|
||||
@@ -307,11 +313,13 @@ function VisitFormModal({
|
||||
setDepartmentId(String(editing.department_id));
|
||||
setVisitDate(editing.visit_date);
|
||||
setObservations(editing.observations);
|
||||
setNewRequirements(editing.new_requirements ?? "");
|
||||
setSelectedAssetIds(editing.assets.map((a) => a.id));
|
||||
} else {
|
||||
setDepartmentId("");
|
||||
setVisitDate(new Date().toISOString().slice(0, 10));
|
||||
setObservations("");
|
||||
setNewRequirements("");
|
||||
setSelectedAssetIds([]);
|
||||
}
|
||||
}, [open, editing]);
|
||||
@@ -357,6 +365,7 @@ function VisitFormModal({
|
||||
department_id: Number(departmentId),
|
||||
visit_date: visitDate,
|
||||
observations: observations.trim(),
|
||||
new_requirements: newRequirements.trim() || null,
|
||||
asset_ids: selectedAssetIds,
|
||||
});
|
||||
await qc.invalidateQueries({ queryKey: ["visits"] });
|
||||
@@ -366,6 +375,7 @@ function VisitFormModal({
|
||||
department_id: Number(departmentId),
|
||||
visit_date: visitDate,
|
||||
observations: observations.trim(),
|
||||
new_requirements: newRequirements.trim() || null,
|
||||
asset_ids: selectedAssetIds,
|
||||
});
|
||||
await qc.invalidateQueries({ queryKey: ["visits"] });
|
||||
@@ -498,6 +508,17 @@ function VisitFormModal({
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className={labelCls}>New Equipment / Maintenance Requirements</label>
|
||||
<textarea
|
||||
rows={2}
|
||||
value={newRequirements}
|
||||
onChange={(e) => setNewRequirements(e.target.value)}
|
||||
placeholder="e.g. Additional infusion pumps requested, new mounting brackets needed..."
|
||||
className={inputCls}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{!editing && (
|
||||
<label className="inline-flex items-center gap-2 text-sm text-gray-700 cursor-pointer">
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user