This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { ActionIcon, Group, Loader, ScrollArea, Stack, Table, Title, Tooltip } from "@mantine/core";
|
||||
import { t } from "@/config/i18n";
|
||||
import { useGetAllContractFile, useGetContracts, useGetRecap } from "@/services/api";
|
||||
import {
|
||||
useDeleteContract,
|
||||
useGetAllContractFile,
|
||||
useGetContract,
|
||||
useGetContracts,
|
||||
useGetRecap,
|
||||
} from "@/services/api";
|
||||
import { IconDownload, IconTableExport } from "@tabler/icons-react";
|
||||
import ContractRow from "@/components/Contracts/Row";
|
||||
import { useLocation, useNavigate, useSearchParams } from "react-router";
|
||||
@@ -8,6 +14,7 @@ import { ContractModal } from "@/components/Contracts/Modal";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { type Contract } from "@/services/resources/contracts";
|
||||
import ContractsFilters from "@/components/Contracts/Filter";
|
||||
import { DeleteModal } from "@/components/DeleteModal";
|
||||
|
||||
export default function Contracts() {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
@@ -17,18 +24,29 @@ export default function Contracts() {
|
||||
const getRecapMutation = useGetRecap();
|
||||
const isdownload = location.pathname.includes("/download");
|
||||
const isrecap = location.pathname.includes("/export");
|
||||
const isDelete = location.pathname.includes("/delete");
|
||||
|
||||
const deleteId = useMemo(() => {
|
||||
if (isDelete) {
|
||||
return location.pathname.split("/")[3];
|
||||
}
|
||||
return null;
|
||||
}, [location]);
|
||||
|
||||
const closeModal = useCallback(() => {
|
||||
navigate(`/dashboard/contracts${searchParams ? `?${searchParams.toString()}` : ""}`);
|
||||
}, [navigate, searchParams]);
|
||||
|
||||
const { data: contracts, isPending } = useGetContracts(searchParams);
|
||||
const { data: currentContract } = useGetContract(Number(deleteId), {
|
||||
enabled: !!deleteId,
|
||||
});
|
||||
|
||||
const { data: allContracts } = useGetContracts();
|
||||
const deleteContractMutation = useDeleteContract();
|
||||
|
||||
const forms = useMemo(() => {
|
||||
if (!allContracts)
|
||||
return [];
|
||||
if (!allContracts) return [];
|
||||
return allContracts
|
||||
?.map((contract: Contract) => contract.form.name)
|
||||
.filter((contract, index, array) => array.indexOf(contract) === index);
|
||||
@@ -57,11 +75,11 @@ export default function Contracts() {
|
||||
);
|
||||
|
||||
const handleDownloadRecap = useCallback(
|
||||
async (id: number) => {
|
||||
async (id: number) => {
|
||||
await getRecapMutation.mutateAsync(id);
|
||||
},
|
||||
[getAllContractFilesMutation],
|
||||
)
|
||||
);
|
||||
|
||||
if (!contracts || isPending)
|
||||
return (
|
||||
@@ -87,9 +105,7 @@ export default function Contracts() {
|
||||
<IconDownload />
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
<Tooltip
|
||||
label={t("download recap", { capfirst: true })}
|
||||
>
|
||||
<Tooltip label={t("download recap", { capfirst: true })}>
|
||||
<ActionIcon
|
||||
disabled={false}
|
||||
onClick={(e) => {
|
||||
@@ -103,7 +119,7 @@ export default function Contracts() {
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
</Group>
|
||||
|
||||
|
||||
<ContractModal
|
||||
opened={isdownload}
|
||||
onClose={closeModal}
|
||||
@@ -114,6 +130,18 @@ export default function Contracts() {
|
||||
onClose={closeModal}
|
||||
handleSubmit={handleDownloadRecap}
|
||||
/>
|
||||
<DeleteModal
|
||||
opened={isDelete}
|
||||
onClose={closeModal}
|
||||
handleSubmit={(id: number) => {
|
||||
deleteContractMutation.mutate(id);
|
||||
}}
|
||||
entityType={"contract"}
|
||||
entity={{
|
||||
name: `${currentContract?.firstname} ${currentContract?.lastname}`,
|
||||
id: currentContract?.id || 0,
|
||||
}}
|
||||
/>
|
||||
</Group>
|
||||
<ContractsFilters
|
||||
forms={forms || []}
|
||||
|
||||
Reference in New Issue
Block a user