This commit is contained in:
2024-07-20 09:32:01 +03:00
parent 5c6e7cf5f5
commit 54c9ca8908
48 changed files with 1057 additions and 87 deletions

View File

@@ -2,15 +2,18 @@ import {FC} from "react";
import {useDealPageContext} from "../../../contexts/DealPageContext.tsx";
import {Button, Checkbox, Divider, Fieldset, Flex, Group, rem, Textarea, TextInput} from "@mantine/core";
import {useForm} from "@mantine/form";
import {ClientService, DealSchema, DealService} from "../../../../../client";
import {ClientService, DealSchema, DealService, ShippingWarehouseSchema} from "../../../../../client";
import {DealStatus, DealStatusDictionary} from "../../../../../shared/enums/DealStatus.ts";
import {isEqual} from "lodash";
import {notifications} from "../../../../../shared/lib/notifications.ts";
import {useQueryClient} from "@tanstack/react-query";
import ShippingWarehouseAutocomplete
from "../../../../../components/Selects/ShippingWarehouseAutocomplete/ShippingWarehouseAutocomplete.tsx";
type Props = {
deal: DealSchema
}
type FormType = Omit<DealSchema, 'statusHistory' | 'services' | 'products'>
const Content: FC<Props> = ({deal}) => {
@@ -30,7 +33,7 @@ const Content: FC<Props> = ({deal}) => {
return DealService.updateDealGeneralInfo({
requestBody: {
dealId: deal.id,
data: values
data: {...values, shippingWarehouse: values.shippingWarehouse?.toString()}
}
}).then(({ok, message}) => {
notifications.guess(ok, {message});
@@ -61,6 +64,10 @@ const Content: FC<Props> = ({deal}) => {
// updating deal info
await updateDealInfo(values);
}
const isShippingWarehouse = (value: (ShippingWarehouseSchema | string | null | undefined)): value is ShippingWarehouseSchema => {
return !["string", "null", "undefined"].includes((typeof value));
}
return (
<form onSubmit={form.onSubmit((values) => handleSubmit(values))}>
<Flex direction={'column'}>
@@ -87,11 +94,17 @@ const Content: FC<Props> = ({deal}) => {
placeholder={'Введите коментарий к сделке'}
{...form.getInputProps('comment')}
/>
<TextInput
disabled
<ShippingWarehouseAutocomplete
placeholder={"Введите склад отгрузки"}
label={"Склад отгрузки"}
value={form.values.shippingWarehouse?.name}
value={isShippingWarehouse(form.values.shippingWarehouse) ? form.values.shippingWarehouse : undefined}
onChange={event => {
if (isShippingWarehouse(event)) {
form.getInputProps('shippingWarehouse').onChange(event.name)
return
}
form.getInputProps('shippingWarehouse').onChange(event)
}}
/>
</Flex>
</Fieldset>