diff --git a/src/app/deals/components/shared/CreateDealButton/CreateDealButton.module.css b/src/app/deals/components/shared/CreateDealButton/CreateDealButton.module.css new file mode 100644 index 0000000..0d2a887 --- /dev/null +++ b/src/app/deals/components/shared/CreateDealButton/CreateDealButton.module.css @@ -0,0 +1,10 @@ +.create-button { + cursor: pointer; + + @mixin light { + background-color: var(--color-light-white-blue); + } + @mixin dark { + background-color: var(--mantine-color-dark-7); + } +} diff --git a/src/app/deals/components/shared/CreateDealButton/CreateDealButton.tsx b/src/app/deals/components/shared/CreateDealButton/CreateDealButton.tsx new file mode 100644 index 0000000..50ca331 --- /dev/null +++ b/src/app/deals/components/shared/CreateDealButton/CreateDealButton.tsx @@ -0,0 +1,51 @@ +import { useState } from "react"; +import { IconPlus } from "@tabler/icons-react"; +import { Card, Center, Group, Text, Transition } from "@mantine/core"; +import { useDealsContext } from "@/app/deals/contexts/DealsContext"; +import CreateCardForm, { CreateDealForm } from "./components/CreateCardForm"; +import styles from "./CreateDealButton.module.css"; + +const CreateCardButton = () => { + const [isCreating, setIsCreating] = useState(false); + const [isTransitionEnded, setIsTransitionEnded] = useState(true); + const { dealsCrud } = useDealsContext(); + + const onSubmit = (values: CreateDealForm) => { + dealsCrud.onCreate(values.name); + setIsCreating(prevState => !prevState); + setIsTransitionEnded(false); + }; + + return ( + { + if (isCreating) return; + setIsCreating(prevState => !prevState); + setIsTransitionEnded(false); + }}> + {!isCreating && isTransitionEnded && ( +
+ + + Добавить + +
+ )} + setIsTransitionEnded(true)}> + {styles => ( +
+ setIsCreating(false)} + onSubmit={onSubmit} + /> +
+ )} +
+
+ ); +}; +export default CreateCardButton; diff --git a/src/app/deals/components/shared/CreateDealButton/components/CreateCardForm.tsx b/src/app/deals/components/shared/CreateDealButton/components/CreateCardForm.tsx new file mode 100644 index 0000000..89b75c7 --- /dev/null +++ b/src/app/deals/components/shared/CreateDealButton/components/CreateCardForm.tsx @@ -0,0 +1,54 @@ +import { FC } from "react"; +import { IconCheck, IconX } from "@tabler/icons-react"; +import { Button, Group, Stack, TextInput } from "@mantine/core"; +import { useForm } from "@mantine/form"; + +export type CreateDealForm = { + name: string; +}; + +type Props = { + onSubmit: (values: CreateDealForm) => void; + onCancel: () => void; +}; + +const CreateCardForm: FC = ({ onSubmit, onCancel }) => { + const form = useForm({ + initialValues: { + name: "", + }, + validate: { + name: value => !value && "Введите название", + }, + }); + + return ( +
{ + onSubmit(values); + form.reset(); + })}> + + + + + + + +
+ ); +}; + +export default CreateCardForm; diff --git a/src/app/deals/components/shared/DealCard/DealCard.tsx b/src/app/deals/components/shared/DealCard/DealCard.tsx index 756e1ac..f38fb63 100644 --- a/src/app/deals/components/shared/DealCard/DealCard.tsx +++ b/src/app/deals/components/shared/DealCard/DealCard.tsx @@ -1,4 +1,6 @@ import { Card, Group, Pill, Stack, Text } from "@mantine/core"; +import { useDealsContext } from "@/app/deals/contexts/DealsContext"; +import { useDrawersContext } from "@/drawers/DrawersContext"; import { DealSchema } from "@/lib/client"; import styles from "./DealCard.module.css"; @@ -7,8 +9,17 @@ type Props = { }; const DealCard = ({ deal }: Props) => { + const { dealsCrud } = useDealsContext(); + const { openDrawer } = useDrawersContext(); + + const onClick = () => { + openDrawer({ key: "dealEditorDrawer", props: { deal, dealsCrud } }); + }; + return ( - + {deal.name} Wb электросталь diff --git a/src/app/deals/components/shared/Funnel/Funnel.tsx b/src/app/deals/components/shared/Funnel/Funnel.tsx index c516e91..ecb91f8 100644 --- a/src/app/deals/components/shared/Funnel/Funnel.tsx +++ b/src/app/deals/components/shared/Funnel/Funnel.tsx @@ -45,11 +45,13 @@ const Funnel: FC = () => { renderContainer={( status: StatusSchema, funnelColumnComponent: ReactNode, - renderDraggable + renderDraggable, + index ) => ( + renderHeader={renderDraggable} + createFormEnabled={index === 0}> {funnelColumnComponent} )} diff --git a/src/app/deals/components/shared/StatusColumnWrapper/StatusColumnWrapper.tsx b/src/app/deals/components/shared/StatusColumnWrapper/StatusColumnWrapper.tsx index 2f22aef..a16f020 100644 --- a/src/app/deals/components/shared/StatusColumnWrapper/StatusColumnWrapper.tsx +++ b/src/app/deals/components/shared/StatusColumnWrapper/StatusColumnWrapper.tsx @@ -1,5 +1,6 @@ import React, { ReactNode } from "react"; import { Box, ScrollArea, Stack } from "@mantine/core"; +import CreateCardButton from "@/app/deals/components/shared/CreateDealButton/CreateDealButton"; import { StatusSchema } from "@/lib/client"; import styles from "./StatusColumnWrapper.module.css"; @@ -7,9 +8,14 @@ type Props = { status: StatusSchema; renderHeader: () => ReactNode; children: ReactNode; + createFormEnabled?: boolean; }; -const StatusColumnWrapper = ({ renderHeader, children }: Props) => { +const StatusColumnWrapper = ({ + renderHeader, + children, + createFormEnabled = false, +}: Props) => { return ( { scrollbarSize={10} type={"always"} scrollbars={"y"}> - {children} + + {createFormEnabled && } + {children} + diff --git a/src/app/deals/contexts/BoardsContext.tsx b/src/app/deals/contexts/BoardsContext.tsx index 7fcc746..61ee806 100644 --- a/src/app/deals/contexts/BoardsContext.tsx +++ b/src/app/deals/contexts/BoardsContext.tsx @@ -13,8 +13,6 @@ type BoardsContextState = { setSelectedBoardId: React.Dispatch>; refetchBoards: () => void; boardsCrud: BoardsCrud; - isEditorDrawerOpened: boolean; - setIsEditorDrawerOpened: React.Dispatch>; }; const BoardsContext = createContext(undefined); @@ -26,8 +24,6 @@ const useBoardsContextState = () => { setBoards, refetch: refetchBoards, } = useBoardsList({ projectId: project?.id }); - const [isEditorDrawerOpened, setIsEditorDrawerOpened] = - useState(false); const [selectedBoardId, setSelectedBoardId] = useState(null); const selectedBoard = @@ -51,8 +47,6 @@ const useBoardsContextState = () => { setSelectedBoardId, refetchBoards, boardsCrud, - isEditorDrawerOpened, - setIsEditorDrawerOpened, }; }; diff --git a/src/app/deals/contexts/DealsContext.tsx b/src/app/deals/contexts/DealsContext.tsx index db4a470..e0fc838 100644 --- a/src/app/deals/contexts/DealsContext.tsx +++ b/src/app/deals/contexts/DealsContext.tsx @@ -1,57 +1,43 @@ "use client"; import React, { createContext, FC, useContext } from "react"; -import { useMutation, UseMutationResult } from "@tanstack/react-query"; -import { AxiosError } from "axios"; import { useBoardsContext } from "@/app/deals/contexts/BoardsContext"; +import { useStatusesContext } from "@/app/deals/contexts/StatusesContext"; +import { DealsCrud, useDealsCrud } from "@/hooks/cruds/useDealsCrud"; import useDealsList from "@/hooks/lists/useDealsList"; -import { - DealSchema, - HttpValidationError, - Options, - UpdateDealData, - UpdateDealResponse, -} from "@/lib/client"; -import { updateDealMutation } from "@/lib/client/@tanstack/react-query.gen"; -import { notifications } from "@/lib/notifications"; +import { DealSchema } from "@/lib/client"; type DealsContextState = { deals: DealSchema[]; setDeals: React.Dispatch>; - updateDeal: UseMutationResult< - UpdateDealResponse, - AxiosError, - Options - >; refetchDeals: () => void; + dealsCrud: DealsCrud; }; const DealsContext = createContext(undefined); const useDealsContextState = () => { const { selectedBoard } = useBoardsContext(); + const { statuses } = useStatusesContext(); const { deals, setDeals, refetch: refetchDeals, } = useDealsList({ boardId: selectedBoard?.id }); - const updateDeal = useMutation({ - ...updateDealMutation(), - onError: error => { - console.error(error); - notifications.error({ - message: error.response?.data?.detail as string | undefined, - }); - refetchDeals(); - }, + const dealsCrud = useDealsCrud({ + deals, + setDeals, + refetchDeals, + boardId: selectedBoard?.id, + statuses, }); return { deals, setDeals, - updateDeal, refetchDeals, + dealsCrud, }; }; diff --git a/src/app/deals/drawers/DealEditorDrawer/DealEditorDrawer.module.css b/src/app/deals/drawers/DealEditorDrawer/DealEditorDrawer.module.css new file mode 100644 index 0000000..9e60d88 --- /dev/null +++ b/src/app/deals/drawers/DealEditorDrawer/DealEditorDrawer.module.css @@ -0,0 +1,4 @@ + +.tab { + border-bottom-width: 3px; +} diff --git a/src/app/deals/drawers/DealEditorDrawer/DealEditorDrawer.tsx b/src/app/deals/drawers/DealEditorDrawer/DealEditorDrawer.tsx new file mode 100644 index 0000000..be1566b --- /dev/null +++ b/src/app/deals/drawers/DealEditorDrawer/DealEditorDrawer.tsx @@ -0,0 +1,48 @@ +"use client"; + +import React, { FC } from "react"; +import { Drawer } from "@mantine/core"; +import DealEditorBody from "@/app/deals/drawers/DealEditorDrawer/components/DealEditorBody"; +import { DrawerProps } from "@/drawers/types"; +import { DealsCrud } from "@/hooks/cruds/useDealsCrud"; +import useIsMobile from "@/hooks/utils/useIsMobile"; +import { DealSchema } from "@/lib/client"; + +type Props = { + deal: DealSchema; + dealsCrud: DealsCrud; +}; + +const DealEditorDrawer: FC> = ({ + opened, + onClose, + props, +}) => { + const isMobile = useIsMobile(); + + return ( + + + + ); +}; + +export default DealEditorDrawer; diff --git a/src/app/deals/drawers/DealEditorDrawer/components/DealEditorBody.tsx b/src/app/deals/drawers/DealEditorDrawer/components/DealEditorBody.tsx new file mode 100644 index 0000000..157ef57 --- /dev/null +++ b/src/app/deals/drawers/DealEditorDrawer/components/DealEditorBody.tsx @@ -0,0 +1,47 @@ +import { FC } from "react"; +import { IconCircleDotted, IconEdit } from "@tabler/icons-react"; +import { Tabs, Text } from "@mantine/core"; +import GeneralTab from "@/app/deals/drawers/DealEditorDrawer/components/GeneralTab"; +import { DealsCrud } from "@/hooks/cruds/useDealsCrud"; +import { DealSchema } from "@/lib/client"; +import styles from "../DealEditorDrawer.module.css"; + +type Props = { + dealsCrud: DealsCrud; + deal: DealSchema; + onClose: () => void; +}; + +const DealEditorBody: FC = ({ dealsCrud, deal, onClose }) => { + return ( + + + }> + Общая информация + + }> + Mock + + + + + + + + mock + + + ); +}; + +export default DealEditorBody; diff --git a/src/app/deals/drawers/DealEditorDrawer/components/GeneralTab.tsx b/src/app/deals/drawers/DealEditorDrawer/components/GeneralTab.tsx new file mode 100644 index 0000000..fafc4e6 --- /dev/null +++ b/src/app/deals/drawers/DealEditorDrawer/components/GeneralTab.tsx @@ -0,0 +1,67 @@ +import { FC, useState } from "react"; +import { isEqual } from "lodash"; +import { Button, Group, Stack, TextInput } from "@mantine/core"; +import { useForm } from "@mantine/form"; +import { DealsCrud } from "@/hooks/cruds/useDealsCrud"; +import { DealSchema } from "@/lib/client"; + +type Props = { + dealsCrud: DealsCrud; + deal: DealSchema; + onClose: () => void; +}; + +const GeneralTab: FC = ({ deal, dealsCrud, onClose }) => { + const [initialValues, setInitialValues] = useState(deal); + const form = useForm({ + initialValues, + validate: { + name: value => !value && "Введите название", + }, + }); + + const onSubmit = (values: DealSchema) => { + dealsCrud.onUpdate(deal.id, values); + setInitialValues(values); + }; + + const onDelete = () => { + dealsCrud.onDelete(deal, onClose); + }; + + return ( +
+ + + + + + + + + + +
+ ); +}; + +export default GeneralTab; diff --git a/src/app/deals/drawers/DealEditorDrawer/index.ts b/src/app/deals/drawers/DealEditorDrawer/index.ts new file mode 100644 index 0000000..906564b --- /dev/null +++ b/src/app/deals/drawers/DealEditorDrawer/index.ts @@ -0,0 +1,3 @@ +import ProjectsEditorDrawer from "@/app/deals/drawers/ProjectsEditorDrawer/ProjectsEditorDrawer"; + +export default ProjectsEditorDrawer; diff --git a/src/app/deals/hooks/useDealsAndStatusesDnd.ts b/src/app/deals/hooks/useDealsAndStatusesDnd.ts index 9081bdf..5c01c82 100644 --- a/src/app/deals/hooks/useDealsAndStatusesDnd.ts +++ b/src/app/deals/hooks/useDealsAndStatusesDnd.ts @@ -25,7 +25,7 @@ const useDealsAndStatusesDnd = (): ReturnType => { const [activeDeal, setActiveDeal] = useState(null); const [activeStatus, setActiveStatus] = useState(null); const { statuses, setStatuses, statusesCrud } = useStatusesContext(); - const { deals, setDeals, updateDeal } = useDealsContext(); + const { deals, setDeals, dealsCrud } = useDealsContext(); const sortedStatuses = useMemo(() => sortByLexorank(statuses), [statuses]); const isMobile = useIsMobile(); @@ -253,17 +253,7 @@ const useDealsAndStatusesDnd = (): ReturnType => { statusId: number, lexorank?: string ) => { - updateDeal.mutate({ - path: { - dealId, - }, - body: { - deal: { - statusId, - lexorank, - }, - }, - }); + dealsCrud.onUpdate(dealId, { statusId, lexorank, name: null }); }; const handleDragStart = ({ active }: DragStartEvent) => { diff --git a/src/components/dnd/FunnelDnd/FunnelDnd.tsx b/src/components/dnd/FunnelDnd/FunnelDnd.tsx index f0df506..d8bfbc5 100644 --- a/src/components/dnd/FunnelDnd/FunnelDnd.tsx +++ b/src/components/dnd/FunnelDnd/FunnelDnd.tsx @@ -32,7 +32,8 @@ type Props = { renderContainer: ( container: TContainer, children: ReactNode, - renderDraggable: () => ReactNode + renderDraggable: () => ReactNode, + index: number ) => ReactNode; renderContainerHeader: (container: TContainer) => ReactNode; renderContainerOverlay: ( @@ -75,7 +76,7 @@ const FunnelDnd = < const isMobile = useIsMobile(); const renderContainers = () => - containers.map(container => { + containers.map((container, index) => { const containerItems = getItemsByContainer(container, items); const containerId = getContainerId(container); return ( @@ -94,7 +95,8 @@ const FunnelDnd = < items={containerItems} renderItem={renderItem} />, - renderDraggable! + renderDraggable!, + index ) } renderDraggable={() => renderContainerHeader(container)} diff --git a/src/drawers/DrawersContext.tsx b/src/drawers/DrawersContext.tsx index 80b9702..33ac12a 100644 --- a/src/drawers/DrawersContext.tsx +++ b/src/drawers/DrawersContext.tsx @@ -49,7 +49,7 @@ const useDrawersContextState = () => { setStack(prev => key ? prev.filter(d => d.key !== key) : prev.slice(0, -1) ); - }, 1000); + }, 300); }; return { diff --git a/src/drawers/drawersRegistry.tsx b/src/drawers/drawersRegistry.tsx index 89cf378..206f647 100644 --- a/src/drawers/drawersRegistry.tsx +++ b/src/drawers/drawersRegistry.tsx @@ -1,11 +1,13 @@ import BoardStatusesEditorDrawer from "@/app/deals/drawers/BoardStatusesEditorDrawer"; -import ProjectsEditorDrawer from "@/app/deals/drawers/ProjectsEditorDrawer"; +import DealEditorDrawer from "@/app/deals/drawers/DealEditorDrawer/DealEditorDrawer"; import ProjectBoardsEditorDrawer from "@/app/deals/drawers/ProjectBoardsEditorDrawer"; +import ProjectsEditorDrawer from "@/app/deals/drawers/ProjectsEditorDrawer"; const drawerRegistry = { projectsEditorDrawer: ProjectsEditorDrawer, boardStatusesEditorDrawer: BoardStatusesEditorDrawer, projectBoardsEditorDrawer: ProjectBoardsEditorDrawer, + dealEditorDrawer: DealEditorDrawer, }; export default drawerRegistry; diff --git a/src/hooks/cruds/baseCrud/useCrudOperations.tsx b/src/hooks/cruds/baseCrud/useCrudOperations.tsx index 62fa967..6429833 100644 --- a/src/hooks/cruds/baseCrud/useCrudOperations.tsx +++ b/src/hooks/cruds/baseCrud/useCrudOperations.tsx @@ -120,7 +120,7 @@ const useCrudOperations = < }); }; - const onDelete = (entity: TEntity) => { + const onDelete = (entity: TEntity, onSuccess?: () => void) => { modals.openConfirmModal({ title: getDeleteConfirmTitle(entity), children: ( @@ -130,6 +130,7 @@ const useCrudOperations = < confirmProps: { color: "red" }, onConfirm: () => { deleteMutation.mutate({ path: { pk: entity.id } } as any); + onSuccess && onSuccess(); setEntities(prev => prev.filter(e => e.id !== entity.id)); }, }); diff --git a/src/hooks/cruds/useDealsCrud.tsx b/src/hooks/cruds/useDealsCrud.tsx new file mode 100644 index 0000000..6eefe57 --- /dev/null +++ b/src/hooks/cruds/useDealsCrud.tsx @@ -0,0 +1,76 @@ +import React from "react"; +import { LexoRank } from "lexorank"; +import { useCrudOperations } from "@/hooks/cruds/baseCrud"; +import { + CreateDealSchema, + DealSchema, + StatusSchema, + UpdateDealSchema, +} from "@/lib/client"; +import { + createDealMutation, + deleteDealMutation, + updateDealMutation, +} from "@/lib/client/@tanstack/react-query.gen"; +import { getNewLexorank } from "@/utils/lexorank"; + +type UseDealsOperationsProps = { + deals: DealSchema[]; + setDeals: React.Dispatch>; + refetchDeals: () => void; + boardId?: number; + statuses: StatusSchema[]; +}; + +export type DealsCrud = { + onCreate: (name: string) => void; + onUpdate: (dealId: number, deal: UpdateDealSchema) => void; + onDelete: (deal: DealSchema, onSuccess?: () => void) => void; +}; + +export const useDealsCrud = ({ + deals, + setDeals, + refetchDeals, + boardId, + statuses, +}: UseDealsOperationsProps): DealsCrud => { + return useCrudOperations({ + entities: deals, + setEntities: setDeals, + refetch: refetchDeals, + mutations: { + create: createDealMutation(), + update: updateDealMutation(), + delete: deleteDealMutation(), + }, + getCreateEntity: name => { + if (!boardId || statuses.length === 0) return null; + const firstStatus = statuses[0]; + const filteredDeals = deals.filter( + d => d.statusId === firstStatus.id + ); + let firstDeal: DealSchema | null = null; + if (filteredDeals.length > 0) { + firstDeal = filteredDeals[0]; + } + const newLexorank = getNewLexorank( + null, + firstDeal ? LexoRank.parse(firstDeal.lexorank) : null + ); + return { + name, + boardId, + statusId: firstStatus.id, + lexorank: newLexorank.toString(), + }; + }, + getUpdateEntity: (old, update) => ({ + ...old, + name: update.name ?? old.name, + lexorank: update.lexorank ?? old.lexorank, + statusId: update.statusId ?? old.statusId, + }), + getDeleteConfirmTitle: () => "Удаление сделки", + }); +}; diff --git a/src/lib/client/@tanstack/react-query.gen.ts b/src/lib/client/@tanstack/react-query.gen.ts index 53f95f4..12fb916 100644 --- a/src/lib/client/@tanstack/react-query.gen.ts +++ b/src/lib/client/@tanstack/react-query.gen.ts @@ -5,9 +5,11 @@ import type { AxiosError } from "axios"; import { client as _heyApiClient } from "../client.gen"; import { createBoard, + createDeal, createProject, createStatus, deleteBoard, + deleteDeal, deleteProject, deleteStatus, getBoards, @@ -24,6 +26,9 @@ import type { CreateBoardData, CreateBoardError, CreateBoardResponse2, + CreateDealData, + CreateDealError, + CreateDealResponse2, CreateProjectData, CreateProjectError, CreateProjectResponse2, @@ -33,6 +38,9 @@ import type { DeleteBoardData, DeleteBoardError, DeleteBoardResponse2, + DeleteDealData, + DeleteDealError, + DeleteDealResponse2, DeleteProjectData, DeleteProjectError, DeleteProjectResponse2, @@ -237,6 +245,81 @@ export const getDealsOptions = (options: Options) => { }); }; +export const createDealQueryKey = (options: Options) => + createQueryKey("createDeal", options); + +/** + * Create Deal + */ +export const createDealOptions = (options: Options) => { + return queryOptions({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await createDeal({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + }); + return data; + }, + queryKey: createDealQueryKey(options), + }); +}; + +/** + * Create Deal + */ +export const createDealMutation = ( + options?: Partial> +): UseMutationOptions< + CreateDealResponse2, + AxiosError, + Options +> => { + const mutationOptions: UseMutationOptions< + CreateDealResponse2, + AxiosError, + Options + > = { + mutationFn: async localOptions => { + const { data } = await createDeal({ + ...options, + ...localOptions, + throwOnError: true, + }); + return data; + }, + }; + return mutationOptions; +}; + +/** + * Delete Deal + */ +export const deleteDealMutation = ( + options?: Partial> +): UseMutationOptions< + DeleteDealResponse2, + AxiosError, + Options +> => { + const mutationOptions: UseMutationOptions< + DeleteDealResponse2, + AxiosError, + Options + > = { + mutationFn: async localOptions => { + const { data } = await deleteDeal({ + ...options, + ...localOptions, + throwOnError: true, + }); + return data; + }, + }; + return mutationOptions; +}; + /** * Update Deal */ diff --git a/src/lib/client/sdk.gen.ts b/src/lib/client/sdk.gen.ts index 54ece02..7f53ca7 100644 --- a/src/lib/client/sdk.gen.ts +++ b/src/lib/client/sdk.gen.ts @@ -6,6 +6,9 @@ import type { CreateBoardData, CreateBoardErrors, CreateBoardResponses, + CreateDealData, + CreateDealErrors, + CreateDealResponses, CreateProjectData, CreateProjectErrors, CreateProjectResponses, @@ -15,6 +18,9 @@ import type { DeleteBoardData, DeleteBoardErrors, DeleteBoardResponses, + DeleteDealData, + DeleteDealErrors, + DeleteDealResponses, DeleteProjectData, DeleteProjectErrors, DeleteProjectResponses, @@ -48,12 +54,16 @@ import type { import { zCreateBoardData, zCreateBoardResponse2, + zCreateDealData, + zCreateDealResponse2, zCreateProjectData, zCreateProjectResponse2, zCreateStatusData, zCreateStatusResponse2, zDeleteBoardData, zDeleteBoardResponse2, + zDeleteDealData, + zDeleteDealResponse2, zDeleteProjectData, zDeleteProjectResponse2, zDeleteStatusData, @@ -216,6 +226,56 @@ export const getDeals = ( }); }; +/** + * Create Deal + */ +export const createDeal = ( + options: Options +) => { + return (options.client ?? _heyApiClient).post< + CreateDealResponses, + CreateDealErrors, + ThrowOnError + >({ + requestValidator: async data => { + return await zCreateDealData.parseAsync(data); + }, + responseType: "json", + responseValidator: async data => { + return await zCreateDealResponse2.parseAsync(data); + }, + url: "/deal/", + ...options, + headers: { + "Content-Type": "application/json", + ...options.headers, + }, + }); +}; + +/** + * Delete Deal + */ +export const deleteDeal = ( + options: Options +) => { + return (options.client ?? _heyApiClient).delete< + DeleteDealResponses, + DeleteDealErrors, + ThrowOnError + >({ + requestValidator: async data => { + return await zDeleteDealData.parseAsync(data); + }, + responseType: "json", + responseValidator: async data => { + return await zDeleteDealResponse2.parseAsync(data); + }, + url: "/deal/{pk}", + ...options, + }); +}; + /** * Update Deal */ @@ -234,7 +294,7 @@ export const updateDeal = ( responseValidator: async data => { return await zUpdateDealResponse2.parseAsync(data); }, - url: "/deal/{dealId}", + url: "/deal/{pk}", ...options, headers: { "Content-Type": "application/json", diff --git a/src/lib/client/types.gen.ts b/src/lib/client/types.gen.ts index b5b71b7..3483cb0 100644 --- a/src/lib/client/types.gen.ts +++ b/src/lib/client/types.gen.ts @@ -54,6 +54,46 @@ export type CreateBoardSchema = { lexorank: string; }; +/** + * CreateDealRequest + */ +export type CreateDealRequest = { + entity: CreateDealSchema; +}; + +/** + * CreateDealResponse + */ +export type CreateDealResponse = { + /** + * Message + */ + message: string; + entity: DealSchema; +}; + +/** + * CreateDealSchema + */ +export type CreateDealSchema = { + /** + * Name + */ + name: string; + /** + * Boardid + */ + boardId: number; + /** + * Lexorank + */ + lexorank: string; + /** + * Statusid + */ + statusId: number; +}; + /** * CreateProjectRequest */ @@ -122,14 +162,14 @@ export type CreateStatusSchema = { * DealSchema */ export type DealSchema = { - /** - * Name - */ - name: string; /** * Id */ id: number; + /** + * Name + */ + name: string; /** * Lexorank */ @@ -150,6 +190,16 @@ export type DeleteBoardResponse = { message: string; }; +/** + * DeleteDealResponse + */ +export type DeleteDealResponse = { + /** + * Message + */ + message: string; +}; + /** * DeleteProjectResponse */ @@ -287,7 +337,7 @@ export type UpdateBoardSchema = { * UpdateDealRequest */ export type UpdateDealRequest = { - deal: UpdateDealSchema; + entity: UpdateDealSchema; }; /** @@ -542,16 +592,73 @@ export type GetDealsResponses = { export type GetDealsResponse2 = GetDealsResponses[keyof GetDealsResponses]; +export type CreateDealData = { + body: CreateDealRequest; + path?: never; + query?: never; + url: "/deal/"; +}; + +export type CreateDealErrors = { + /** + * Validation Error + */ + 422: HttpValidationError; +}; + +export type CreateDealError = CreateDealErrors[keyof CreateDealErrors]; + +export type CreateDealResponses = { + /** + * Successful Response + */ + 200: CreateDealResponse; +}; + +export type CreateDealResponse2 = + CreateDealResponses[keyof CreateDealResponses]; + +export type DeleteDealData = { + body?: never; + path: { + /** + * Pk + */ + pk: number; + }; + query?: never; + url: "/deal/{pk}"; +}; + +export type DeleteDealErrors = { + /** + * Validation Error + */ + 422: HttpValidationError; +}; + +export type DeleteDealError = DeleteDealErrors[keyof DeleteDealErrors]; + +export type DeleteDealResponses = { + /** + * Successful Response + */ + 200: DeleteDealResponse; +}; + +export type DeleteDealResponse2 = + DeleteDealResponses[keyof DeleteDealResponses]; + export type UpdateDealData = { body: UpdateDealRequest; path: { /** - * Dealid + * Pk */ - dealId: number; + pk: number; }; query?: never; - url: "/deal/{dealId}"; + url: "/deal/{pk}"; }; export type UpdateDealErrors = { diff --git a/src/lib/client/zod.gen.ts b/src/lib/client/zod.gen.ts index e74fe4b..d10d445 100644 --- a/src/lib/client/zod.gen.ts +++ b/src/lib/client/zod.gen.ts @@ -35,6 +35,41 @@ export const zCreateBoardResponse = z.object({ entity: zBoardSchema, }); +/** + * CreateDealSchema + */ +export const zCreateDealSchema = z.object({ + name: z.string(), + boardId: z.int(), + lexorank: z.string(), + statusId: z.int(), +}); + +/** + * CreateDealRequest + */ +export const zCreateDealRequest = z.object({ + entity: zCreateDealSchema, +}); + +/** + * DealSchema + */ +export const zDealSchema = z.object({ + id: z.int(), + name: z.string(), + lexorank: z.string(), + statusId: z.int(), +}); + +/** + * CreateDealResponse + */ +export const zCreateDealResponse = z.object({ + message: z.string(), + entity: zDealSchema, +}); + /** * CreateProjectSchema */ @@ -98,16 +133,6 @@ export const zCreateStatusResponse = z.object({ entity: zStatusSchema, }); -/** - * DealSchema - */ -export const zDealSchema = z.object({ - name: z.string(), - id: z.int(), - lexorank: z.string(), - statusId: z.int(), -}); - /** * DeleteBoardResponse */ @@ -115,6 +140,13 @@ export const zDeleteBoardResponse = z.object({ message: z.string(), }); +/** + * DeleteDealResponse + */ +export const zDeleteDealResponse = z.object({ + message: z.string(), +}); + /** * DeleteProjectResponse */ @@ -208,7 +240,7 @@ export const zUpdateDealSchema = z.object({ * UpdateDealRequest */ export const zUpdateDealRequest = z.object({ - deal: zUpdateDealSchema, + entity: zUpdateDealSchema, }); /** @@ -324,10 +356,34 @@ export const zGetDealsData = z.object({ */ export const zGetDealsResponse2 = zGetDealsResponse; +export const zCreateDealData = z.object({ + body: zCreateDealRequest, + path: z.optional(z.never()), + query: z.optional(z.never()), +}); + +/** + * Successful Response + */ +export const zCreateDealResponse2 = zCreateDealResponse; + +export const zDeleteDealData = z.object({ + body: z.optional(z.never()), + path: z.object({ + pk: z.int(), + }), + query: z.optional(z.never()), +}); + +/** + * Successful Response + */ +export const zDeleteDealResponse2 = zDeleteDealResponse; + export const zUpdateDealData = z.object({ body: zUpdateDealRequest, path: z.object({ - dealId: z.int(), + pk: z.int(), }), query: z.optional(z.never()), });