feat: deal prefilling

This commit is contained in:
2024-10-15 21:34:39 +04:00
parent f1566cdf44
commit 2bd4fddfa7
22 changed files with 736 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ import CreateDealFrom from "../CreateDealForm/CreateDealFrom.tsx";
import { DealService } from "../../../client";
import { useQueryClient } from "@tanstack/react-query";
import { dateWithoutTimezone } from "../../../shared/lib/date.ts";
import { useDealPageContext } from "../../../pages/LeadsPage/contexts/DealPageContext.tsx";
type Props = {
onClick: () => void;
@@ -14,6 +15,7 @@ const CreateDealButton: FC<Props> = () => {
const [isCreating, setIsCreating] = useState(false);
const [isTransitionEnded, setIsTransitionEnded] = useState(true);
const queryClient = useQueryClient();
const { prefillDeal, setPrefillDeal } = useDealPageContext();
return (
<div
@@ -34,6 +36,7 @@ const CreateDealButton: FC<Props> = () => {
<div style={styles}>
<CreateDealFrom
onCancel={() => {
setPrefillDeal(undefined);
setIsCreating(false);
}}
onSubmit={quickDeal => {
@@ -41,10 +44,18 @@ const CreateDealButton: FC<Props> = () => {
requestBody: {
...quickDeal,
acceptanceDate: dateWithoutTimezone(
quickDeal.acceptanceDate
quickDeal.acceptanceDate,
),
},
}).then(async () => {
}).then(async (result) => {
if (prefillDeal) {
DealService.prefillDeal({
requestBody: {
oldDealId: prefillDeal.id,
newDealId: result.dealId,
},
});
}
await queryClient.invalidateQueries({
queryKey: ["getDealSummaries"],
});

View File

@@ -12,3 +12,8 @@
display: flex;
gap: rem(10);
}
.button-prefill {
display: grid;
width: 100%;
}

View File

@@ -8,12 +8,14 @@ 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 { useDealPageContext } from "../../../pages/LeadsPage/contexts/DealPageContext.tsx";
type Props = {
onSubmit: (quickDeal: QuickDeal) => void;
onCancel: () => void;
};
const CreateDealFrom: FC<Props> = ({ onSubmit, onCancel }) => {
const { prefillOnOpen, prefillDeal } = useDealPageContext();
const form = useForm<QuickDeal>({
initialValues: {
name: "",
@@ -29,6 +31,9 @@ const CreateDealFrom: FC<Props> = ({ onSubmit, onCancel }) => {
},
},
});
const prefillButtonLabel = prefillDeal ? `Предзаполнено [ID: ${prefillDeal.id}]` : "Предзаполнить";
return (
<form
style={{ width: "100%" }}
@@ -86,7 +91,14 @@ const CreateDealFrom: FC<Props> = ({ onSubmit, onCancel }) => {
{...form.getInputProps("acceptanceDate")}
/>
</div>
<div className={styles["button-prefill"]}>
<Button
style={{ whiteSpace: "wrap" }}
variant={"outline"}
onClick={() => prefillOnOpen()}>
{prefillButtonLabel}
</Button>
</div>
<div className={styles["buttons"]}>
<Button type={"submit"}>Добавить</Button>
<Button