feat: deal_id fix
This commit is contained in:
@@ -1,28 +1,28 @@
|
|||||||
import {FC} from "react";
|
import { FC } from "react";
|
||||||
import {useDealPageContext} from "../../../contexts/DealPageContext.tsx";
|
import { useDealPageContext } from "../../../contexts/DealPageContext.tsx";
|
||||||
import {Button, Checkbox, Divider, Fieldset, Flex, Group, rem, Textarea, TextInput} from "@mantine/core";
|
import { Button, Checkbox, Divider, Fieldset, Flex, Group, rem, Textarea, TextInput } from "@mantine/core";
|
||||||
import {useForm} from "@mantine/form";
|
import { useForm } from "@mantine/form";
|
||||||
import {ClientService, DealSchema, DealService, ShippingWarehouseSchema} from "../../../../../client";
|
import { ClientService, DealSchema, DealService, ShippingWarehouseSchema } from "../../../../../client";
|
||||||
import {DealStatus, DealStatusDictionary} from "../../../../../shared/enums/DealStatus.ts";
|
import { DealStatus, DealStatusDictionary } from "../../../../../shared/enums/DealStatus.ts";
|
||||||
import {isEqual} from "lodash";
|
import { isEqual } from "lodash";
|
||||||
import {notifications} from "../../../../../shared/lib/notifications.ts";
|
import { notifications } from "../../../../../shared/lib/notifications.ts";
|
||||||
import {useQueryClient} from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import ShippingWarehouseAutocomplete
|
import ShippingWarehouseAutocomplete
|
||||||
from "../../../../../components/Selects/ShippingWarehouseAutocomplete/ShippingWarehouseAutocomplete.tsx";
|
from "../../../../../components/Selects/ShippingWarehouseAutocomplete/ShippingWarehouseAutocomplete.tsx";
|
||||||
import {ButtonCopyControlled} from "../../../../../components/ButtonCopyControlled/ButtonCopyControlled.tsx";
|
import { ButtonCopyControlled } from "../../../../../components/ButtonCopyControlled/ButtonCopyControlled.tsx";
|
||||||
import {useClipboard} from "@mantine/hooks";
|
import { useClipboard } from "@mantine/hooks";
|
||||||
import ButtonCopy from "../../../../../components/ButtonCopy/ButtonCopy.tsx";
|
import ButtonCopy from "../../../../../components/ButtonCopy/ButtonCopy.tsx";
|
||||||
import FileSaver from "file-saver";
|
import FileSaver from "file-saver";
|
||||||
import {getCurrentDateTimeForFilename} from "../../../../../shared/lib/date.ts";
|
import { getCurrentDateTimeForFilename } from "../../../../../shared/lib/date.ts";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
deal: DealSchema
|
deal: DealSchema
|
||||||
}
|
}
|
||||||
|
|
||||||
type FormType = Omit<DealSchema, 'statusHistory' | 'services' | 'products'>
|
type FormType = Omit<DealSchema, "statusHistory" | "services" | "products">
|
||||||
|
|
||||||
const Content: FC<Props> = ({deal}) => {
|
const Content: FC<Props> = ({ deal }) => {
|
||||||
const {setSelectedDeal} = useDealPageContext();
|
const { setSelectedDeal } = useDealPageContext();
|
||||||
const clipboard = useClipboard();
|
const clipboard = useClipboard();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
@@ -31,37 +31,37 @@ const Content: FC<Props> = ({deal}) => {
|
|||||||
{
|
{
|
||||||
initialValues: initialValues,
|
initialValues: initialValues,
|
||||||
validate: {
|
validate: {
|
||||||
name: (value: string) => value.length > 0 ? null : 'Название сделки не может быть пустым'
|
name: (value: string) => value.length > 0 ? null : "Название сделки не может быть пустым",
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
)
|
);
|
||||||
const updateDealInfo = async (values: FormType) => {
|
const updateDealInfo = async (values: FormType) => {
|
||||||
return DealService.updateDealGeneralInfo({
|
return DealService.updateDealGeneralInfo({
|
||||||
requestBody: {
|
requestBody: {
|
||||||
dealId: deal.id,
|
dealId: deal.id,
|
||||||
data: {...values, shippingWarehouse: values.shippingWarehouse?.toString()}
|
data: { ...values, shippingWarehouse: values.shippingWarehouse?.toString() },
|
||||||
}
|
},
|
||||||
}).then(({ok, message}) => {
|
}).then(({ ok, message }) => {
|
||||||
notifications.guess(ok, {message});
|
notifications.guess(ok, { message });
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
DealService.getDealById({dealId: deal.id})
|
DealService.getDealById({ dealId: deal.id })
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setSelectedDeal(data);
|
setSelectedDeal(data);
|
||||||
form.setInitialValues(data);
|
form.setInitialValues(data);
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ['getDealSummaries']
|
queryKey: ["getDealSummaries"],
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
const updateClientInfo = async (values: FormType) => {
|
const updateClientInfo = async (values: FormType) => {
|
||||||
return ClientService.updateClient({
|
return ClientService.updateClient({
|
||||||
requestBody: {
|
requestBody: {
|
||||||
data: values.client
|
data: values.client,
|
||||||
}
|
},
|
||||||
}).then(({ok, message}) =>
|
}).then(({ ok, message }) =>
|
||||||
notifications.guess(ok, {message}));
|
notifications.guess(ok, { message }));
|
||||||
}
|
};
|
||||||
const handleSubmit = async (values: FormType) => {
|
const handleSubmit = async (values: FormType) => {
|
||||||
// Updating client info if there changes
|
// Updating client info if there changes
|
||||||
if (!isEqual(values.client, deal.client)) {
|
if (!isEqual(values.client, deal.client)) {
|
||||||
@@ -69,50 +69,50 @@ const Content: FC<Props> = ({deal}) => {
|
|||||||
}
|
}
|
||||||
// updating deal info
|
// updating deal info
|
||||||
await updateDealInfo(values);
|
await updateDealInfo(values);
|
||||||
}
|
};
|
||||||
const isShippingWarehouse = (value: (ShippingWarehouseSchema | string | null | undefined)): value is ShippingWarehouseSchema => {
|
const isShippingWarehouse = (value: (ShippingWarehouseSchema | string | null | undefined)): value is ShippingWarehouseSchema => {
|
||||||
return !["string", "null", "undefined"].includes((typeof value));
|
return !["string", "null", "undefined"].includes((typeof value));
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
const onCopyGuestUrlClick = () => {
|
const onCopyGuestUrlClick = () => {
|
||||||
DealService.createDealGuestUrl({
|
DealService.createDealGuestUrl({
|
||||||
requestBody: {
|
requestBody: {
|
||||||
dealId: deal.id
|
dealId: deal.id,
|
||||||
}
|
},
|
||||||
}).then(({ok, message, url}) => {
|
}).then(({ ok, message, url }) => {
|
||||||
if (!ok)
|
if (!ok)
|
||||||
notifications.guess(ok, {message});
|
notifications.guess(ok, { message });
|
||||||
clipboard.copy(
|
clipboard.copy(
|
||||||
`${window.location.origin}/${url}`
|
`${window.location.origin}/${url}`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
return (
|
return (
|
||||||
<form onSubmit={form.onSubmit((values) => handleSubmit(values))}>
|
<form onSubmit={form.onSubmit((values) => handleSubmit(values))}>
|
||||||
<Flex direction={'column'}>
|
<Flex direction={"column"}>
|
||||||
<Fieldset legend={"Общие параметры [ID: 12311]"}>
|
<Fieldset legend={`Общие параметры [ID: ${deal.id}]`}>
|
||||||
<Flex direction={"column"} gap={rem(10)}>
|
<Flex direction={"column"} gap={rem(10)}>
|
||||||
<TextInput
|
<TextInput
|
||||||
placeholder={"Название сделки"}
|
placeholder={"Название сделки"}
|
||||||
label={"Название сделки"}
|
label={"Название сделки"}
|
||||||
{...form.getInputProps('name')}
|
{...form.getInputProps("name")}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
disabled
|
disabled
|
||||||
placeholder={"Дата создания"}
|
placeholder={"Дата создания"}
|
||||||
label={"Дата создания"}
|
label={"Дата создания"}
|
||||||
value={new Date(deal.createdAt).toLocaleString('ru-RU')}
|
value={new Date(deal.createdAt).toLocaleString("ru-RU")}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
disabled
|
disabled
|
||||||
placeholder={"Текущий статус"}
|
placeholder={"Текущий статус"}
|
||||||
label={"Текущий статус"}
|
label={"Текущий статус"}
|
||||||
value={DealStatusDictionary[deal.currentStatus as DealStatus]}/>
|
value={DealStatusDictionary[deal.currentStatus as DealStatus]} />
|
||||||
<Textarea
|
<Textarea
|
||||||
label={'Коментарий к сделке'}
|
label={"Коментарий к сделке"}
|
||||||
placeholder={'Введите коментарий к сделке'}
|
placeholder={"Введите коментарий к сделке"}
|
||||||
{...form.getInputProps('comment')}
|
{...form.getInputProps("comment")}
|
||||||
/>
|
/>
|
||||||
<ShippingWarehouseAutocomplete
|
<ShippingWarehouseAutocomplete
|
||||||
placeholder={"Введите склад отгрузки"}
|
placeholder={"Введите склад отгрузки"}
|
||||||
@@ -120,10 +120,10 @@ const Content: FC<Props> = ({deal}) => {
|
|||||||
value={isShippingWarehouse(form.values.shippingWarehouse) ? form.values.shippingWarehouse : undefined}
|
value={isShippingWarehouse(form.values.shippingWarehouse) ? form.values.shippingWarehouse : undefined}
|
||||||
onChange={event => {
|
onChange={event => {
|
||||||
if (isShippingWarehouse(event)) {
|
if (isShippingWarehouse(event)) {
|
||||||
form.getInputProps('shippingWarehouse').onChange(event.name)
|
form.getInputProps("shippingWarehouse").onChange(event.name);
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
form.getInputProps('shippingWarehouse').onChange(event)
|
form.getInputProps("shippingWarehouse").onChange(event);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
@@ -138,26 +138,26 @@ const Content: FC<Props> = ({deal}) => {
|
|||||||
<TextInput
|
<TextInput
|
||||||
placeholder={"Введите телефон"}
|
placeholder={"Введите телефон"}
|
||||||
label={"Телефон клиента"}
|
label={"Телефон клиента"}
|
||||||
{...form.getInputProps('client.details.phoneNumber')}
|
{...form.getInputProps("client.details.phoneNumber")}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
placeholder={"Введите email"}
|
placeholder={"Введите email"}
|
||||||
label={"Email"}
|
label={"Email"}
|
||||||
{...form.getInputProps('client.details.email')}
|
{...form.getInputProps("client.details.email")}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
placeholder={"Введите телеграм"}
|
placeholder={"Введите телеграм"}
|
||||||
label={"Телеграм"}
|
label={"Телеграм"}
|
||||||
{...form.getInputProps('client.details.telegram')}
|
{...form.getInputProps("client.details.telegram")}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
placeholder={"Введите ИНН"}
|
placeholder={"Введите ИНН"}
|
||||||
label={"ИНН"}
|
label={"ИНН"}
|
||||||
{...form.getInputProps('client.details.inn')}
|
{...form.getInputProps("client.details.inn")}
|
||||||
/>
|
/>
|
||||||
</Fieldset>
|
</Fieldset>
|
||||||
<Flex mt={'md'} gap={rem(10)} align={'center'} justify={'flex-end'}>
|
<Flex mt={"md"} gap={rem(10)} align={"center"} justify={"flex-end"}>
|
||||||
<Flex align={'center'} gap={rem(10)} justify={'center'}>
|
<Flex align={"center"} gap={rem(10)} justify={"center"}>
|
||||||
|
|
||||||
<Flex gap={rem(10)}>
|
<Flex gap={rem(10)}>
|
||||||
{(deal.billRequest && deal.billRequest.pdfUrl) ?
|
{(deal.billRequest && deal.billRequest.pdfUrl) ?
|
||||||
@@ -199,20 +199,20 @@ const Content: FC<Props> = ({deal}) => {
|
|||||||
/>
|
/>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
label={"Сделка завершена"}
|
label={"Сделка завершена"}
|
||||||
{...form.getInputProps('isCompleted')}
|
{...form.getInputProps("isCompleted")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Checkbox
|
<Checkbox
|
||||||
label={"Сделка удалена"}
|
label={"Сделка удалена"}
|
||||||
{...form.getInputProps('isDeleted')}
|
{...form.getInputProps("isDeleted")}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
</Flex>
|
</Flex>
|
||||||
<Divider
|
<Divider
|
||||||
orientation={'vertical'}
|
orientation={"vertical"}
|
||||||
/>
|
/>
|
||||||
<Group align={'center'} justify={'center'}>
|
<Group align={"center"} justify={"center"}>
|
||||||
<Button
|
<Button
|
||||||
color={"red"}
|
color={"red"}
|
||||||
type={"reset"}
|
type={"reset"}
|
||||||
@@ -230,13 +230,13 @@ const Content: FC<Props> = ({deal}) => {
|
|||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
const DealEditDrawerGeneralTab: FC = () => {
|
const DealEditDrawerGeneralTab: FC = () => {
|
||||||
const {selectedDeal} = useDealPageContext();
|
const { selectedDeal } = useDealPageContext();
|
||||||
if (!selectedDeal) return <>No deal selected</>;
|
if (!selectedDeal) return <>No deal selected</>;
|
||||||
return (
|
return (
|
||||||
<Content deal={selectedDeal}/>
|
<Content deal={selectedDeal} />
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
export default DealEditDrawerGeneralTab;
|
export default DealEditDrawerGeneralTab;
|
||||||
Reference in New Issue
Block a user