phase-8: polish, global search, audit log, packaging, and demo docs
This commit is contained in:
@@ -31,6 +31,8 @@ import { Modal } from "@/components/ui/dialog";
|
||||
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";
|
||||
|
||||
type TabKey = "contracts" | "warranties";
|
||||
|
||||
@@ -101,6 +103,13 @@ export function ContractsPage() {
|
||||
title: string;
|
||||
} | null>(null);
|
||||
|
||||
// Confirm delete dialog
|
||||
const [deleteTarget, setDeleteTarget] = useState<{
|
||||
kind: "contract" | "warranty";
|
||||
id: number;
|
||||
label: string;
|
||||
} | null>(null);
|
||||
|
||||
const deptsQuery = useQuery({
|
||||
queryKey: ["departments", "active-only"],
|
||||
queryFn: () => departmentsApi.list(false),
|
||||
@@ -150,16 +159,26 @@ export function ContractsPage() {
|
||||
const deleteContractMutation = useMutation({
|
||||
mutationFn: (id: number) => contractsApi.remove(id),
|
||||
onSuccess: () => {
|
||||
setDeleteTarget(null);
|
||||
qc.invalidateQueries({ queryKey: ["contracts"] });
|
||||
qc.invalidateQueries({ queryKey: ["assets"] });
|
||||
toast.success("Contract deleted");
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err instanceof ApiError ? err.detail : "Failed to delete contract");
|
||||
},
|
||||
});
|
||||
|
||||
const deleteWarrantyMutation = useMutation({
|
||||
mutationFn: (id: number) => warrantiesApi.remove(id),
|
||||
onSuccess: () => {
|
||||
setDeleteTarget(null);
|
||||
qc.invalidateQueries({ queryKey: ["warranties"] });
|
||||
qc.invalidateQueries({ queryKey: ["assets"] });
|
||||
toast.success("Warranty deleted");
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err instanceof ApiError ? err.detail : "Failed to delete warranty");
|
||||
},
|
||||
});
|
||||
|
||||
@@ -303,11 +322,13 @@ export function ContractsPage() {
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="text-red-600 hover:text-red-700"
|
||||
onClick={() => {
|
||||
if (window.confirm("Delete this contract?")) {
|
||||
deleteContractMutation.mutate(row.original.id);
|
||||
}
|
||||
}}
|
||||
onClick={() =>
|
||||
setDeleteTarget({
|
||||
kind: "contract",
|
||||
id: row.original.id,
|
||||
label: `${row.original.asset_code} (${row.original.contract_type})`,
|
||||
})
|
||||
}
|
||||
aria-label={`Delete contract ${row.original.id}`}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
@@ -412,6 +433,7 @@ export function ContractsPage() {
|
||||
setEditingWarranty(row.original);
|
||||
setWarrantyFormOpen(true);
|
||||
}}
|
||||
aria-label={`Edit warranty ${row.original.id}`}
|
||||
>
|
||||
<Pencil className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
@@ -419,11 +441,14 @@ export function ContractsPage() {
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="text-red-600 hover:text-red-700"
|
||||
onClick={() => {
|
||||
if (window.confirm("Delete this warranty?")) {
|
||||
deleteWarrantyMutation.mutate(row.original.id);
|
||||
}
|
||||
}}
|
||||
onClick={() =>
|
||||
setDeleteTarget({
|
||||
kind: "warranty",
|
||||
id: row.original.id,
|
||||
label: `${row.original.asset_code} warranty`,
|
||||
})
|
||||
}
|
||||
aria-label={`Delete warranty ${row.original.id}`}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
@@ -652,6 +677,28 @@ export function ContractsPage() {
|
||||
/>
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
<ConfirmDialog
|
||||
open={Boolean(deleteTarget)}
|
||||
onOpenChange={(o) => !o && setDeleteTarget(null)}
|
||||
title={
|
||||
deleteTarget?.kind === "warranty" ? "Delete Warranty" : "Delete Contract"
|
||||
}
|
||||
message={`Are you sure you want to delete ${deleteTarget?.label ?? "this record"}?`}
|
||||
confirmLabel="Delete"
|
||||
variant="danger"
|
||||
loading={
|
||||
deleteContractMutation.isPending || deleteWarrantyMutation.isPending
|
||||
}
|
||||
onConfirm={() => {
|
||||
if (!deleteTarget) return;
|
||||
if (deleteTarget.kind === "warranty") {
|
||||
deleteWarrantyMutation.mutate(deleteTarget.id);
|
||||
} else {
|
||||
deleteContractMutation.mutate(deleteTarget.id);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user