From 8083bdf3d0cc2feba70379219dfb5b1eeb541d80 Mon Sep 17 00:00:00 2001 From: AlexSserb Date: Thu, 20 Feb 2025 20:21:08 +0400 Subject: [PATCH] feat: processing of modules in card, renaming --- src/client/models/CardGeneralInfoSchema.ts | 1 + src/client/models/CardQuickCreateRequest.ts | 6 +- src/client/models/CardSchema.ts | 5 +- src/client/models/CardSummary.ts | 2 +- .../CardAttributeFields.tsx | 14 +- .../Cards/CardSummaryItem/CardSummaryItem.tsx | 18 +- .../Cards/CardsDndColumn/CardsDndColumn.tsx | 15 +- ...m.module.css => CreateCardForm.module.css} | 0 .../Cards/CreateCardForm/CreateCardForm.tsx | 72 +++--- .../CardStatusChangeTable.tsx | 0 .../columns.tsx | 0 .../CardsPageHeader.tsx} | 4 +- .../{DealsTable => CardsTable}/CardsTable.tsx | 0 .../{DealsTable => CardsTable}/columns.tsx | 0 .../DealProductServiceTable.tsx | 132 ----------- .../DealProductsTable/DealProductsTable.tsx | 168 -------------- .../components/DealProductsTable/columns.tsx | 107 --------- .../DealServicesTable/DealServicesTable.tsx | 129 ----------- .../components/DealServicesTable/columns.tsx | 63 ------ .../drawers/CardEditDrawer/CardEditDrawer.tsx | 22 +- .../CardsPage/tabs/ClientTab/ClientTab.tsx | 4 + .../CardsPage/tabs/GeneralTab/GeneralTab.tsx | 206 ++++++++++-------- .../ProductAndServiceTab.tsx | 8 +- src/pages/CardsPage/ui/CardsPage.tsx | 6 +- .../CardsPage/utils/isModuleInProject.ts | 12 +- .../modals/ShippingWarehouseForm.tsx | 2 +- .../components/ProfitChart/ProfitChart.tsx | 3 +- .../components/ProfitTable/hooks/columns.tsx | 2 +- src/types/QuickCard.ts | 7 +- 29 files changed, 240 insertions(+), 768 deletions(-) rename src/components/Dnd/Cards/CreateCardForm/{CreateDealForm.module.css => CreateCardForm.module.css} (100%) rename src/pages/CardsPage/components/{DealStatusChangeTable => CardStatusChangeTable}/CardStatusChangeTable.tsx (100%) rename src/pages/CardsPage/components/{DealStatusChangeTable => CardStatusChangeTable}/columns.tsx (100%) rename src/pages/CardsPage/components/{LeadsPageHeader/LeadsPageHeader.tsx => CardsPageHeader/CardsPageHeader.tsx} (98%) rename src/pages/CardsPage/components/{DealsTable => CardsTable}/CardsTable.tsx (100%) rename src/pages/CardsPage/components/{DealsTable => CardsTable}/columns.tsx (100%) delete mode 100644 src/pages/CardsPage/components/DealProductsTable/DealProductServiceTable.tsx delete mode 100644 src/pages/CardsPage/components/DealProductsTable/DealProductsTable.tsx delete mode 100644 src/pages/CardsPage/components/DealProductsTable/columns.tsx delete mode 100644 src/pages/CardsPage/components/DealServicesTable/DealServicesTable.tsx delete mode 100644 src/pages/CardsPage/components/DealServicesTable/columns.tsx diff --git a/src/client/models/CardGeneralInfoSchema.ts b/src/client/models/CardGeneralInfoSchema.ts index 301eb65..a99d21d 100644 --- a/src/client/models/CardGeneralInfoSchema.ts +++ b/src/client/models/CardGeneralInfoSchema.ts @@ -13,5 +13,6 @@ export type CardGeneralInfoSchema = { manager?: (UserSchema | null); boardId: number; statusId: number; + isServicesProfitAccounted: boolean; }; diff --git a/src/client/models/CardQuickCreateRequest.ts b/src/client/models/CardQuickCreateRequest.ts index 3489182..aa54794 100644 --- a/src/client/models/CardQuickCreateRequest.ts +++ b/src/client/models/CardQuickCreateRequest.ts @@ -5,11 +5,11 @@ import type { BaseMarketplaceSchema } from './BaseMarketplaceSchema'; export type CardQuickCreateRequest = { name: string; - clientName: string; + clientName: (string | null); comment: string; acceptanceDate: string; - shippingWarehouse: string; - baseMarketplace: BaseMarketplaceSchema; + shippingWarehouse: (string | null); + baseMarketplace: (BaseMarketplaceSchema | null); statusId: number; }; diff --git a/src/client/models/CardSchema.ts b/src/client/models/CardSchema.ts index 9b1f818..a6fed84 100644 --- a/src/client/models/CardSchema.ts +++ b/src/client/models/CardSchema.ts @@ -26,11 +26,12 @@ export type CardSchema = { statusHistory: Array; isDeleted: boolean; isCompleted: boolean; + isServicesProfitAccounted: boolean; isLocked: boolean; services: Array; products: Array; - clientId: number; - client: ClientSchema; + clientId: (number | null); + client: (ClientSchema | null); shippingWarehouse?: (ShippingWarehouseSchema | string | null); billRequest?: (CardBillRequestSchema | null); group?: (CardGroupSchema | null); diff --git a/src/client/models/CardSummary.ts b/src/client/models/CardSummary.ts index d08d489..15d4d81 100644 --- a/src/client/models/CardSummary.ts +++ b/src/client/models/CardSummary.ts @@ -10,7 +10,7 @@ import type { StatusSchema } from './StatusSchema'; export type CardSummary = { id: number; name: string; - clientName: string; + clientName: (string | null); createdAt: string; status: StatusSchema; board: BoardSchema; diff --git a/src/components/CardAttributeFields/CardAttributeFields.tsx b/src/components/CardAttributeFields/CardAttributeFields.tsx index 3a2518e..ce090a7 100644 --- a/src/components/CardAttributeFields/CardAttributeFields.tsx +++ b/src/components/CardAttributeFields/CardAttributeFields.tsx @@ -1,4 +1,4 @@ -import { ProjectSchema } from "../../client"; +import { AttributeSchema, ProjectSchema } from "../../client"; import { UseFormReturnType } from "@mantine/form"; import { rem, Stack } from "@mantine/core"; import { ReactNode } from "react"; @@ -11,7 +11,17 @@ type Props = { } const CardAttributeFields = ({ project, form }: Props) => { - const fields: ReactNode[] = project.attributes.map(attribute => { + const attributes: AttributeSchema[] = []; + + project.attributes.forEach(attribute => { + if (attribute.type.type === "boolean") { + attributes.push(attribute); + } else { + attributes.unshift(attribute); + } + }); + + const fields: ReactNode[] = attributes.map(attribute => { return ( = ({ cardSummary, color }) => { const { onDelete, onComplete, onDeleteFromGroup } = useCardSummaryState(); const isServicesAndProductsIncluded = isModuleInProject(Modules.SERVICES_AND_PRODUCTS, selectedProject); + const isClientIncluded = isModuleInProject(Modules.CLIENTS, selectedProject); const onDealSummaryClick = () => { CardService.getCardById({ cardId: cardSummary.id }).then(card => { @@ -61,16 +62,13 @@ const CardSummaryItem: FC = ({ cardSummary, color }) => { style={{ backgroundColor: color }} > - - - - {cardSummary.clientName} - - + {isClientIncluded && ( + + + {cardSummary.clientName} + + + )} = ({ return has(obj, "cards"); }; - const getDealGroups = (): GroupWithCards[] => { + const getCardGroups = (): GroupWithCards[] => { const groups = uniq(summaries.filter(s => s.group).map(summary => summary.group) as CardGroupSchema[]); if (groups.length === 0) return []; const groupedSummaries = groupBy(summaries, "group.id"); const groupDict = groups.reduce((acc, group) => { - acc[group.id] = group; - return acc; - } - , {} as { [key: number]: CardGroupSchema }); + acc[group.id] = group; + return acc; + }, {} as { [key: number]: CardGroupSchema }); return Object.entries(groupedSummaries).reduce((acc, [groupId, cards]) => { if (!groupId) return acc; const group = groupDict[parseInt(groupId)]; @@ -57,8 +56,8 @@ export const CardsDndColumn: FC = ({ }, [] as { group: CardGroupSchema; cards: CardSummary[] }[]); }; - const getDealsAndGroups = (): (GroupWithCards | CardSummary)[] => { - const groups = getDealGroups(); + const getCardsAndGroups = (): (GroupWithCards | CardSummary)[] => { + const groups = getCardGroups(); const cards = summaries.filter(s => !s.group).sort((a, b) => { return new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(); }); @@ -144,7 +143,7 @@ export const CardsDndColumn: FC = ({ } )} - {getDealsAndGroups().map(obj => { + {getCardsAndGroups().map(obj => { if (isGroup(obj)) { return renderGroup(obj); } diff --git a/src/components/Dnd/Cards/CreateCardForm/CreateDealForm.module.css b/src/components/Dnd/Cards/CreateCardForm/CreateCardForm.module.css similarity index 100% rename from src/components/Dnd/Cards/CreateCardForm/CreateDealForm.module.css rename to src/components/Dnd/Cards/CreateCardForm/CreateCardForm.module.css diff --git a/src/components/Dnd/Cards/CreateCardForm/CreateCardForm.tsx b/src/components/Dnd/Cards/CreateCardForm/CreateCardForm.tsx index 2e42bc8..4042c3d 100644 --- a/src/components/Dnd/Cards/CreateCardForm/CreateCardForm.tsx +++ b/src/components/Dnd/Cards/CreateCardForm/CreateCardForm.tsx @@ -2,7 +2,7 @@ import { Button, rem, Textarea, TextInput } from "@mantine/core"; import { QuickCard } from "../../../../types/QuickCard.ts"; import { FC } from "react"; import { useForm } from "@mantine/form"; -import styles from "./CreateDealForm.module.css"; +import styles from "./CreateCardForm.module.css"; import ClientAutocomplete from "../../../Selects/ClientAutocomplete/ClientAutocomplete.tsx"; import { DateTimePicker } from "@mantine/dates"; import ShippingWarehouseAutocomplete @@ -19,22 +19,28 @@ type Props = { const CreateCardForm: FC = ({ onSubmit, onCancel }) => { const { selectedProject } = useCardPageContext(); - const isPrefillingDealEnabled = isModuleInProject(Modules.SERVICES_AND_PRODUCTS, selectedProject); - + const isPrefillingEnabled = isModuleInProject(Modules.SERVICES_AND_PRODUCTS, selectedProject); const { prefillOnOpen, prefillCard } = usePrefillCardContext(); + + const isServicesAndProductsIncluded = isModuleInProject(Modules.SERVICES_AND_PRODUCTS, selectedProject); + const isClientsIncluded = isModuleInProject(Modules.CLIENTS, selectedProject); + const form = useForm({ initialValues: { name: "", - clientName: "", - clientAddress: "", + clientName: null, comment: "", acceptanceDate: new Date(), - shippingWarehouse: "", - baseMarketplace: { - key: "", - iconUrl: "", - name: "", - }, + shippingWarehouse: null, + baseMarketplace: null, + }, + validate: { + baseMarketplace: baseMarketplace => + isServicesAndProductsIncluded && !baseMarketplace && "МП не выбран", + shippingWarehouse: shippingWarehouse => + isServicesAndProductsIncluded && !shippingWarehouse && "Склад отгрузки не выбран", + clientName: clientName => + isClientsIncluded && !clientName && "Клиент не выбран", }, }); @@ -54,26 +60,34 @@ const CreateCardForm: FC = ({ onSubmit, onCancel }) => { }}>
-
- -
-
- } - placeholder={"Базовый маркетплейс"} - {...form.getInputProps("baseMarketplace")} - /> - -
+ {isClientsIncluded && ( +
+ +
+ )} + {isServicesAndProductsIncluded && ( + <> +
+ } + placeholder={"Базовый маркетплейс"} + {...form.getInputProps("baseMarketplace")} + /> +
+
+ +
+ + )}