diff --git a/package.json b/package.json index 1be0c1e..0ccee7e 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "libphonenumber-js": "^1.12.10", "mantine-datatable": "^8.2.0", "next": "15.4.7", + "phone": "^3.1.67", "react": "19.1.0", "react-dom": "19.1.0", "react-imask": "^7.6.1", diff --git a/src/app/clients/hooks/useClientsCrud.tsx b/src/app/clients/hooks/useClientsCrud.tsx index ca13248..4467e24 100644 --- a/src/app/clients/hooks/useClientsCrud.tsx +++ b/src/app/clients/hooks/useClientsCrud.tsx @@ -16,7 +16,11 @@ type UseClientsProps = { export type ClientsCrud = { onCreate: (client: CreateClientSchema) => void; - onUpdate: (clientId: number, client: UpdateClientSchema) => void; + onUpdate: ( + clientId: number, + client: UpdateClientSchema, + onSuccess?: () => void + ) => void; onDelete: (client: ClientSchema) => void; }; diff --git a/src/app/clients/hooks/useClientsList.tsx b/src/app/clients/hooks/useClientsList.tsx index 5305ddf..99f0633 100644 --- a/src/app/clients/hooks/useClientsList.tsx +++ b/src/app/clients/hooks/useClientsList.tsx @@ -5,8 +5,16 @@ import { getClientsQueryKey, } from "@/lib/client/@tanstack/react-query.gen"; -const useClientsList = () => { - const { data, refetch } = useQuery(getClientsOptions()); +type Props = { + includeDeleted?: boolean; +}; + +const useClientsList = ( + { includeDeleted = false }: Props = { includeDeleted: false } +) => { + const { data, refetch } = useQuery( + getClientsOptions({ query: { includeDeleted } }) + ); const clients = useMemo(() => data?.items ?? [], [data]); const queryKey = getClientsQueryKey(); diff --git a/src/app/deals/components/shared/CreateDealButton/components/CreateCardForm.tsx b/src/app/deals/components/shared/CreateDealButton/components/CreateCardForm.tsx index 89b75c7..2f22a06 100644 --- a/src/app/deals/components/shared/CreateDealButton/components/CreateCardForm.tsx +++ b/src/app/deals/components/shared/CreateDealButton/components/CreateCardForm.tsx @@ -2,9 +2,15 @@ import { FC } from "react"; import { IconCheck, IconX } from "@tabler/icons-react"; import { Button, Group, Stack, TextInput } from "@mantine/core"; import { useForm } from "@mantine/form"; +import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext"; +import { ClientSchema } from "@/lib/client"; +import ClientSelect from "@/modules/dealModularEditorTabs/Clients/shared/components/ClientSelect"; +import { ModuleNames } from "@/modules/modules"; export type CreateDealForm = { name: string; + client?: ClientSchema; + clientId?: number; }; type Props = { @@ -13,25 +19,42 @@ type Props = { }; const CreateCardForm: FC = ({ onSubmit, onCancel }) => { + const { modulesSet } = useProjectsContext(); + const form = useForm({ initialValues: { name: "", }, validate: { name: value => !value && "Введите название", + client: client => + modulesSet.has(ModuleNames.CLIENTS) && + !client && + "Выберите клиента", }, }); return ( -
{ - onSubmit(values); - form.reset(); - })}> + { + onSubmit(values); + form.reset(); + })}> + {modulesSet.has(ModuleNames.CLIENTS) && ( + { + form.setFieldValue("client", client); + form.setFieldValue("clientId", client?.id); + }} + /> + )}