From 532bb738bda5d58fdb9cf22c492b00335cc1f0fa Mon Sep 17 00:00:00 2001 From: fakz9 Date: Sun, 28 Apr 2024 19:58:41 +0300 Subject: [PATCH] feat: small refactor, address now is telegram --- src/client/models/ClientDetailsSchema.ts | 2 +- src/client/models/DealQuickCreateRequest.ts | 1 - .../models/DealSummaryReorderRequest.ts | 4 ++-- .../Dnd/CreateDealForm/CreateDealFrom.tsx | 3 --- .../ClientAutocomplete/ClientAutocomplete.tsx | 24 ++++++------------- .../components/ClientsTable/columns.tsx | 10 +++++--- .../ClientFormModal/ClientFormModal.tsx | 17 +++++++------ .../tabs/DealEditDrawerGeneralTab.tsx | 6 ++--- src/pages/LeadsPage/ui/LeadsPage.tsx | 20 ++++++++++++++-- src/pages/ProductsPage/ui/ProductsPage.tsx | 4 ++++ 10 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/client/models/ClientDetailsSchema.ts b/src/client/models/ClientDetailsSchema.ts index ef63374..e0dc86c 100644 --- a/src/client/models/ClientDetailsSchema.ts +++ b/src/client/models/ClientDetailsSchema.ts @@ -3,7 +3,7 @@ /* tslint:disable */ /* eslint-disable */ export type ClientDetailsSchema = { - address?: (string | null); + telegram?: (string | null); phoneNumber?: (string | null); inn?: (string | null); email?: (string | null); diff --git a/src/client/models/DealQuickCreateRequest.ts b/src/client/models/DealQuickCreateRequest.ts index 16e1dda..e6adbdb 100644 --- a/src/client/models/DealQuickCreateRequest.ts +++ b/src/client/models/DealQuickCreateRequest.ts @@ -5,7 +5,6 @@ export type DealQuickCreateRequest = { name: string; clientName: string; - clientAddress: string; comment: string; acceptanceDate: string; }; diff --git a/src/client/models/DealSummaryReorderRequest.ts b/src/client/models/DealSummaryReorderRequest.ts index 4846b70..d056a6f 100644 --- a/src/client/models/DealSummaryReorderRequest.ts +++ b/src/client/models/DealSummaryReorderRequest.ts @@ -6,7 +6,7 @@ export type DealSummaryReorderRequest = { dealId: number; status: number; index: number; - deadline: string; - comment: string; + deadline?: (string | null); + comment?: (string | null); }; diff --git a/src/components/Dnd/CreateDealForm/CreateDealFrom.tsx b/src/components/Dnd/CreateDealForm/CreateDealFrom.tsx index d72d314..fcd9106 100644 --- a/src/components/Dnd/CreateDealForm/CreateDealFrom.tsx +++ b/src/components/Dnd/CreateDealForm/CreateDealFrom.tsx @@ -39,12 +39,9 @@ const CreateDealFrom: FC = ({onSubmit, onCancel}) => { {...form.getInputProps('name')} /> -
diff --git a/src/components/Selects/ClientAutocomplete/ClientAutocomplete.tsx b/src/components/Selects/ClientAutocomplete/ClientAutocomplete.tsx index 6fe998b..c446ffe 100644 --- a/src/components/Selects/ClientAutocomplete/ClientAutocomplete.tsx +++ b/src/components/Selects/ClientAutocomplete/ClientAutocomplete.tsx @@ -1,5 +1,5 @@ import {useDebouncedValue} from "@mantine/hooks"; -import {Autocomplete, AutocompleteProps, TextInput, TextInputProps} from "@mantine/core"; +import {Autocomplete, AutocompleteProps, TextInputProps} from "@mantine/core"; import {FC, useEffect, useState} from "react"; import {Client} from "../../../types/Client.ts"; import {ClientService} from "../../../client"; @@ -71,23 +71,13 @@ const ClientAutocomplete: FC = ({onSelect, addressRestProps, nameRestProp } : {}} /> - {withAddress && - { - selectClient(prevState => prevState && {...prevState, address: event.target.value}) - }} - /> - } + ) } -export default ClientAutocomplete; \ No newline at end of file +export default ClientAutocomplete; + + + + diff --git a/src/pages/ClientsPage/components/ClientsTable/columns.tsx b/src/pages/ClientsPage/components/ClientsTable/columns.tsx index 2bcdf51..800743d 100644 --- a/src/pages/ClientsPage/components/ClientsTable/columns.tsx +++ b/src/pages/ClientsPage/components/ClientsTable/columns.tsx @@ -10,16 +10,20 @@ export const useClientsTableColumns = () => { header: "Имя", }, { - accessorKey: "details.address", - header: "Адрес" + accessorKey: "details.telegram", + header: "Телеграм" }, { accessorKey: "details.email", header: "EMAIL" }, { - accessorKey: "details.phone_number", + accessorKey: "details.phoneNumber", header: "Телефон" + }, + { + accessorKey: "details.inn", + header: "ИНН" } ], []); } diff --git a/src/pages/ClientsPage/modals/ClientFormModal/ClientFormModal.tsx b/src/pages/ClientsPage/modals/ClientFormModal/ClientFormModal.tsx index 15c7f11..dcddb43 100644 --- a/src/pages/ClientsPage/modals/ClientFormModal/ClientFormModal.tsx +++ b/src/pages/ClientsPage/modals/ClientFormModal/ClientFormModal.tsx @@ -1,5 +1,5 @@ import {ContextModalProps} from "@mantine/modals"; -import {Fieldset, NumberInput, TextInput} from "@mantine/core"; +import {Fieldset, TextInput} from "@mantine/core"; import {useForm} from "@mantine/form"; import {ClientSchema} from "../../../../client"; import {getDigitsCount} from "../../../../shared/lib/utils.ts"; @@ -19,7 +19,7 @@ const ClientFormModal = ({ id: innerProps.element.id, name: innerProps.element.name, details: { - address: innerProps.element.details?.address, + telegram: innerProps.element.details?.telegram, phoneNumber: innerProps.element.details?.phoneNumber, email: innerProps.element.details?.email, inn: innerProps.element.details?.inn @@ -28,7 +28,7 @@ const ClientFormModal = ({ id: -1, name: '', details: { - address: '', + telegram: '', phoneNumber: '', email: '', inn: undefined @@ -39,7 +39,7 @@ const ClientFormModal = ({ validate: { name: (name: string) => name.trim() !== '' ? null : "Необходимо ввести название клиента", details: { - address: (address: string | undefined | null) => (address && address.trim() !== '') ? null : "Необходимо ввести адрес", + telegram: (address: string | undefined | null) => (address && address.trim() !== '') ? null : "Необходимо ввести телеграм", phoneNumber: (phoneNumber: string | undefined | null) => (phoneNumber && phoneNumber.trim() !== '') ? null : "Необходимо ввести номер телефона", email: (email: string | undefined | null) => (email && email.trim() !== '') ? null : "Необходимо ввести почту", inn: (inn: string | undefined | null) => (inn && getDigitsCount(parseInt(inn)) >= 10) ? null : "ИНН должен содержать не менее 10 цифр", @@ -71,9 +71,9 @@ const ClientFormModal = ({
- = ({deal}) => { {...form.getInputProps('client.details.email')} /> { } const onDragEnd = async (result: DropResult) => { setIsDragEnded(true); + // If there is no changes if (!result.destination || result.destination == result.source) return; + + // Checking for valid dealId const dealId = parseInt(result.draggableId); if (isNaN(dealId)) return; + // Checking for valid deal + const summary = summaries.find(summary => summary.id == dealId); + if (!summary) return; + + // Checking if it is custom actions const droppableId = result.destination.droppableId; if (droppableId === 'DELETE') { onDelete(dealId); return; } - + const status = getDealStatusByName(droppableId); const request: Partial = { dealId: dealId, index: result.destination.index, - status: getDealStatusByName(droppableId) + status: status + } + if (status == summary.status) { + DealService.reorderDealSummaries({requestBody: request as DealSummaryReorderRequest}) + .then(async response => { + setSummaries(response.summaries); + await refetch(); + }); + return; } modals.openContextModal({ modal: 'enterDeadline', diff --git a/src/pages/ProductsPage/ui/ProductsPage.tsx b/src/pages/ProductsPage/ui/ProductsPage.tsx index b6ddeb7..ac19298 100644 --- a/src/pages/ProductsPage/ui/ProductsPage.tsx +++ b/src/pages/ProductsPage/ui/ProductsPage.tsx @@ -78,7 +78,11 @@ export const ProductsPage: FC = () => { useEffect(() => { if (!paginationInfo) return; setTotalPages(paginationInfo.totalPages); + if (currentPage > paginationInfo.totalPages) { + setCurrentPage(1); + } }, [paginationInfo]); + return ( <>