diff --git a/modules/customer-invoices/src/web/proformas/delete/utils/build-delete-proforma-targets.ts b/modules/customer-invoices/src/web/proformas/delete/utils/build-delete-proforma-targets.ts deleted file mode 100644 index cc27efb9..00000000 --- a/modules/customer-invoices/src/web/proformas/delete/utils/build-delete-proforma-targets.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { Proforma, ProformaListRow } from "../../shared"; -import type { DeleteProformaTarget } from "../entities"; - -export const buildDeleteProformaTargetFromListRow = ( - proforma: ProformaListRow -): DeleteProformaTarget => ({ - id: proforma.id, - reference: proforma.reference, -}); - -export const buildDeleteProformaTargetFromEntity = (proforma: Proforma): DeleteProformaTarget => ({ - id: proforma.id, - reference: proforma.reference, -}); - -export const buildDeleteProformaTargetsFromListRows = ( - proformas: ProformaListRow[] -): DeleteProformaTarget[] => proformas.map(buildDeleteProformaTargetFromListRow); diff --git a/modules/customer-invoices/src/web/proformas/delete/utils/index.ts b/modules/customer-invoices/src/web/proformas/delete/utils/index.ts index 76f2170c..0c1f7fca 100644 --- a/modules/customer-invoices/src/web/proformas/delete/utils/index.ts +++ b/modules/customer-invoices/src/web/proformas/delete/utils/index.ts @@ -1 +1 @@ -export * from "./build-delete-proforma-targets"; +export * from "./prepare-delete-proforma-targets"; diff --git a/modules/customer-invoices/src/web/proformas/delete/utils/prepare-delete-proforma-targets.ts b/modules/customer-invoices/src/web/proformas/delete/utils/prepare-delete-proforma-targets.ts new file mode 100644 index 00000000..313c5ff0 --- /dev/null +++ b/modules/customer-invoices/src/web/proformas/delete/utils/prepare-delete-proforma-targets.ts @@ -0,0 +1,15 @@ +import type { Proforma, ProformaListRow } from "../../shared"; +import type { DeleteProformaTarget } from "../entities"; + +export const prepareDeleteProformaTargets = ( + input: Proforma | ProformaListRow | Array +): DeleteProformaTarget[] => { + const items = Array.isArray(input) ? input : [input]; + + return items.map(mapToDeleteProformaTarget); +}; + +const mapToDeleteProformaTarget = (proforma: Proforma | ProformaListRow): DeleteProformaTarget => ({ + id: proforma.id, + reference: proforma.reference, +}); diff --git a/modules/customer-invoices/src/web/proformas/list/controllers/use-list-proformas-page.controller.ts b/modules/customer-invoices/src/web/proformas/list/controllers/use-list-proformas-page.controller.ts index d0448b56..4964d174 100644 --- a/modules/customer-invoices/src/web/proformas/list/controllers/use-list-proformas-page.controller.ts +++ b/modules/customer-invoices/src/web/proformas/list/controllers/use-list-proformas-page.controller.ts @@ -1,11 +1,15 @@ import type { RightPanelMode } from "@repo/rdx-ui/hooks"; import { useSearchParams } from "react-router-dom"; +import { useDeleteProformaDialogController } from "../../delete"; + import { useListProformasController } from "./use-list-proformas.controller"; import { useProformaSummaryPanelController } from "./use-proforma-summary-panel.controller"; export const useListProformasPageController = () => { const listCtrl = useListProformasController(); + const deleteDialogCtrl = useDeleteProformaDialogController(); + const [searchParams] = useSearchParams(); const proformaId = searchParams.get("proformaId") ?? ""; @@ -20,5 +24,7 @@ export const useListProformasPageController = () => { return { listCtrl, panelCtrl, + + deleteDialogCtrl, }; }; diff --git a/modules/customer-invoices/src/web/proformas/list/ui/pages/list-proformas-page.tsx b/modules/customer-invoices/src/web/proformas/list/ui/pages/list-proformas-page.tsx index 1a86b4c4..5afc99e8 100644 --- a/modules/customer-invoices/src/web/proformas/list/ui/pages/list-proformas-page.tsx +++ b/modules/customer-invoices/src/web/proformas/list/ui/pages/list-proformas-page.tsx @@ -15,8 +15,8 @@ import { FilterIcon, PlusIcon } from "lucide-react"; import { useNavigate } from "react-router-dom"; import { useTranslation } from "../../../../i18n"; -import { DeleteProformaDialog, useDeleteProformaDialogController } from "../../../delete"; -import { buildDeleteProformaTargetFromListRow } from "../../../delete/utils"; +import { DeleteProformaDialog } from "../../../delete"; +import { prepareDeleteProformaTargets } from "../../../delete/utils"; import type { ProformaListRow } from "../../../shared"; import { useListProformasPageController } from "../../controllers"; import { ProformaSummaryPanel, ProformasGrid, useProformasGridColumns } from "../blocks"; @@ -25,11 +25,10 @@ export const ListProformasPage = () => { const { t } = useTranslation(); const navigate = useNavigate(); - const { listCtrl, panelCtrl } = useListProformasPageController(); - const deleteDialogCtrl = useDeleteProformaDialogController(); + const { listCtrl, panelCtrl, deleteDialogCtrl } = useListProformasPageController(); - const handleDeleteProforma = (proforma: ProformaListRow) => { - deleteDialogCtrl.openDialog([buildDeleteProformaTargetFromListRow(proforma)]); + const handleDeleteProforma = (proformaRow: ProformaListRow) => { + deleteDialogCtrl.openDialog(prepareDeleteProformaTargets(proformaRow)); }; const columns = useProformasGridColumns({