feat: deal product services

This commit is contained in:
2024-05-19 04:07:59 +03:00
parent c5cd8e350f
commit 268a58d39f
3 changed files with 17 additions and 16 deletions

View File

@@ -1,10 +1,9 @@
import {ObjectSelectProps} from "../ObjectSelect/ObjectSelect.tsx"; import {ObjectSelectProps} from "../ObjectSelect/ObjectSelect.tsx";
import {ServiceSchema} from "../../client"; import {ServiceSchema} from "../../client";
import {ActionIcon, Flex, FlexProps, NumberInput, NumberInputProps, rem} from "@mantine/core"; import {Flex, FlexProps, NumberInput, NumberInputProps, rem} from "@mantine/core";
import {FC, useEffect, useRef, useState} from "react"; import {FC, useEffect, useRef, useState} from "react";
import ServiceSelectNew from "../Selects/ServiceSelectNew/ServiceSelectNew.tsx"; import ServiceSelectNew from "../Selects/ServiceSelectNew/ServiceSelectNew.tsx";
import {ServiceType} from "../../shared/enums/ServiceType.ts"; import {ServiceType} from "../../shared/enums/ServiceType.ts";
import {IconReload, IconTrash, IconUpload} from "@tabler/icons-react";
type ServiceProps = Omit<ObjectSelectProps<ServiceSchema>, 'data'>; type ServiceProps = Omit<ObjectSelectProps<ServiceSchema>, 'data'>;
type PriceProps = NumberInputProps; type PriceProps = NumberInputProps;
@@ -14,14 +13,16 @@ type Props = {
priceProps: PriceProps, priceProps: PriceProps,
quantity: number, quantity: number,
containerProps: FlexProps, containerProps: FlexProps,
filterType?: ServiceType filterType?: ServiceType,
lockOnEdit?: boolean
} }
const ServiceWithPriceInput: FC<Props> = ({ const ServiceWithPriceInput: FC<Props> = ({
serviceProps, serviceProps,
priceProps, priceProps,
quantity, quantity,
containerProps, containerProps,
filterType = ServiceType.PRODUCT_SERVICE filterType = ServiceType.PRODUCT_SERVICE,
lockOnEdit = true
}) => { }) => {
const [price, setPrice] = useState<number | undefined>( const [price, setPrice] = useState<number | undefined>(
typeof priceProps.value === 'number' ? priceProps.value : undefined); typeof priceProps.value === 'number' ? priceProps.value : undefined);
@@ -48,23 +49,21 @@ const ServiceWithPriceInput: FC<Props> = ({
setPrice(value); setPrice(value);
} }
useEffect(() => { useEffect(() => {
if (isFirstRender.current) return; if (isFirstRender.current && lockOnEdit) return;
setPriceBasedOnQuantity(); setPriceBasedOnQuantity();
}, [quantity]); }, [quantity]);
useEffect(() => { useEffect(() => {
if (isFirstRender.current) return; if (isFirstRender.current && lockOnEdit) return;
if (!priceProps.onChange || typeof price === 'undefined') return; if (!priceProps.onChange || typeof price === 'undefined') return;
priceProps.onChange(price); priceProps.onChange(price);
}, [price]); }, [price]);
useEffect(() => { useEffect(() => {
// if (!isFirstRender) setPrice(0);
// if (isFirstRender.current && price) return;
if (!serviceProps.onChange || !service) return; if (!serviceProps.onChange || !service) return;
if (price && isFirstRender.current) return; if (price && isFirstRender.current && lockOnEdit) return;
setPriceBasedOnService(); setPriceBasedOnService();
serviceProps.onChange(service); serviceProps.onChange(service);
}, [service]); }, [service]);
@@ -73,9 +72,7 @@ const ServiceWithPriceInput: FC<Props> = ({
isFirstRender.current = false; isFirstRender.current = false;
}, []); }, []);
const onReload = () => {
setPriceBasedOnService();
}
return ( return (
<Flex <Flex
align={"center"} align={"center"}
@@ -83,19 +80,21 @@ const ServiceWithPriceInput: FC<Props> = ({
{...containerProps} {...containerProps}
> >
<ActionIcon variant={"default"}> {/*<ActionIcon variant={"default"}>*/}
<IconReload onClick={() => onReload()}/> {/*<IconReload onClick={() => onReload()}/>*/}
</ActionIcon> {/*</ActionIcon>*/}
<ServiceSelectNew <ServiceSelectNew
{...serviceProps} {...serviceProps}
value={service} value={service}
onChange={onServiceManualChange} onChange={onServiceManualChange}
filterType={filterType} filterType={filterType}
disabled={serviceProps.value !== undefined && lockOnEdit}
/> />
<NumberInput <NumberInput
{...priceProps} {...priceProps}
onChange={onPriceManualChange} onChange={onPriceManualChange}
value={price} // value={price}
defaultValue={priceProps.value}
/> />
</Flex> </Flex>

View File

@@ -55,6 +55,7 @@ const AddDealProductModal = ({
placeholder={"Выберите товар"} placeholder={"Выберите товар"}
label={"Товар"} label={"Товар"}
clientId={innerProps.clientId} clientId={innerProps.clientId}
disabled={isEditing}
{...form.getInputProps('product')} {...form.getInputProps('product')}
/> />
<NumberInput <NumberInput

View File

@@ -70,6 +70,7 @@ const AddDealServiceModal = ({
style: {width: "100%"} style: {width: "100%"}
}} }}
filterType={ServiceType.DEAL_SERVICE} filterType={ServiceType.DEAL_SERVICE}
lockOnEdit={isEditing}
/> />
<NumberInput <NumberInput
placeholder={"Введите количество"} placeholder={"Введите количество"}