mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 04:33:11 +00:00
* feat(vendors): support company roster workflows * fix(vendors): address roster review feedback * test(vendors): preserve draft on roster load failure * fix(vendors): preserve current roster selection
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { useState } from "react";
|
|
import { useDeleteVendor } from "@/domain/vendors/use-cases/use-delete-vendor";
|
|
import { useVendorDeactivationImpact } from "@/domain/vendors/use-cases/use-vendor-deactivation-impact";
|
|
import type { VendorDeactivationImpact, VendorListItem } from "@/domain/vendors/types/vendor";
|
|
|
|
export interface VendorDeactivationState {
|
|
target: VendorListItem | null;
|
|
error: string | null;
|
|
impact: VendorDeactivationImpact | undefined;
|
|
isLoading: boolean;
|
|
impactError: Error | null;
|
|
isSaving: boolean;
|
|
open: (row: VendorListItem) => void;
|
|
close: () => void;
|
|
confirm: () => void;
|
|
}
|
|
|
|
export function useVendorDeactivation(): VendorDeactivationState {
|
|
const [target, setTarget] = useState<VendorListItem | null>(null);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const deleteVendor = useDeleteVendor();
|
|
const {
|
|
data: impact,
|
|
isLoading,
|
|
error: impactError,
|
|
} = useVendorDeactivationImpact(target?.id ?? undefined);
|
|
|
|
const open = (row: VendorListItem) => {
|
|
setTarget(row);
|
|
setError(null);
|
|
};
|
|
|
|
const close = () => {
|
|
setTarget(null);
|
|
setError(null);
|
|
};
|
|
|
|
const confirm = () => {
|
|
if (!target || target.id == null) return;
|
|
setError(null);
|
|
deleteVendor.mutate(target.id, {
|
|
onSuccess: () => setTarget(null),
|
|
onError: (err: Error) => setError(err.message || "Failed to deactivate vendor"),
|
|
});
|
|
};
|
|
|
|
return {
|
|
target,
|
|
error,
|
|
impact,
|
|
isLoading,
|
|
impactError,
|
|
isSaving: deleteVendor.isPending,
|
|
open,
|
|
close,
|
|
confirm,
|
|
};
|
|
}
|