feat: removed price categories
This commit is contained in:
@@ -8,7 +8,6 @@ import { DateTimePicker } from "@mantine/dates";
|
||||
import ShippingWarehouseAutocomplete
|
||||
from "../../../Selects/ShippingWarehouseAutocomplete/ShippingWarehouseAutocomplete.tsx";
|
||||
import BaseMarketplaceSelect from "../../../Selects/BaseMarketplaceSelect/BaseMarketplaceSelect.tsx";
|
||||
import ServicePriceCategorySelect from "../../../Selects/ServicePriceCategorySelect/ServicePriceCategorySelect.tsx";
|
||||
import { usePrefillDealContext } from "../../../../pages/DealsPage/contexts/PrefillDealContext.tsx";
|
||||
|
||||
type Props = {
|
||||
@@ -69,14 +68,6 @@ const CreateDealFrom: FC<Props> = ({ onSubmit, onCancel }) => {
|
||||
placeholder={"Склад отгрузки"}
|
||||
/>
|
||||
</div>
|
||||
<div className={styles["inputs"]}>
|
||||
<ServicePriceCategorySelect
|
||||
rightSection={<></>}
|
||||
placeholder={"Выберите категорию"}
|
||||
{...form.getInputProps("category")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className={styles["inputs"]}>
|
||||
<Textarea
|
||||
autosize
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import ObjectSelect, {
|
||||
ObjectSelectProps,
|
||||
} from "../../ObjectSelect/ObjectSelect.tsx";
|
||||
import { ServicePriceCategorySchema } from "../../../client";
|
||||
import useServicePriceCategoriesList from "../../../pages/ServicesPage/hooks/useServicePriceCategoriesList.tsx";
|
||||
|
||||
type Props = Omit<ObjectSelectProps<ServicePriceCategorySchema>, "data">;
|
||||
|
||||
const ServicePriceCategorySelect = (props: Props) => {
|
||||
const { objects } = useServicePriceCategoriesList();
|
||||
return (
|
||||
<ObjectSelect
|
||||
{...props}
|
||||
data={objects}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default ServicePriceCategorySelect;
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ObjectSelectProps } from "../ObjectSelect/ObjectSelect.tsx";
|
||||
import { ServicePriceCategorySchema, ServiceSchema } from "../../client";
|
||||
import { ServiceSchema } from "../../client";
|
||||
import {
|
||||
Flex,
|
||||
FlexProps,
|
||||
@@ -21,7 +21,6 @@ type Props = {
|
||||
containerProps: FlexProps;
|
||||
filterType?: ServiceType;
|
||||
lockOnEdit?: boolean;
|
||||
category?: ServicePriceCategorySchema;
|
||||
};
|
||||
const ServiceWithPriceInput: FC<Props> = ({
|
||||
serviceProps,
|
||||
@@ -30,7 +29,6 @@ const ServiceWithPriceInput: FC<Props> = ({
|
||||
containerProps,
|
||||
filterType = ServiceType.PRODUCT_SERVICE,
|
||||
lockOnEdit = true,
|
||||
category,
|
||||
}) => {
|
||||
const [price, setPrice] = useState<number | undefined>(
|
||||
typeof priceProps.value === "number" ? priceProps.value : undefined
|
||||
@@ -51,19 +49,8 @@ const ServiceWithPriceInput: FC<Props> = ({
|
||||
setPrice(range.price);
|
||||
return true;
|
||||
};
|
||||
const setPriceBasedOnCategory = () => {
|
||||
if (!category || !service) return false;
|
||||
const categoryPrice = service.categoryPrices.find(
|
||||
categoryPrice => categoryPrice.category.id === category.id
|
||||
);
|
||||
if (!categoryPrice) return false;
|
||||
setPrice(categoryPrice.price);
|
||||
return true;
|
||||
};
|
||||
const setPriceBasedOnService = () => {
|
||||
if (!service) return;
|
||||
// if category is set, we should not set price based on service
|
||||
if (setPriceBasedOnCategory()) return;
|
||||
if (setPriceBasedOnQuantity()) return;
|
||||
setPrice(service.price);
|
||||
};
|
||||
@@ -76,9 +63,6 @@ const ServiceWithPriceInput: FC<Props> = ({
|
||||
};
|
||||
useEffect(() => {
|
||||
if (isFirstRender.current && lockOnEdit) return;
|
||||
|
||||
// we need to set price based on quantity only if category is not set, because category has higher priority
|
||||
if (category) return;
|
||||
setPriceBasedOnQuantity();
|
||||
}, [quantity]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user