Merge warning and success modals while taking to work

dev
Platon Yasev 3 years ago
parent f73e799271
commit 46d88a255a

@ -39,7 +39,7 @@ export const PendingPointsFilters = ({ fullRange }) => {
"prediction", "prediction",
]); ]);
const clearFilters = () => clear(fullRange?.prediction); const clearFilters = () => clear(fullRange);
const hasActiveFilters = const hasActiveFilters =
filters.region || filters.region ||

@ -1,4 +1,4 @@
import { Alert, Button, Modal, Popover } from "antd"; import { Alert, Button, Modal, Spin } from "antd";
import { useQueryClient } from "@tanstack/react-query"; import { useQueryClient } from "@tanstack/react-query";
import { usePointSelection } from "../../../stores/usePointSelection"; import { usePointSelection } from "../../../stores/usePointSelection";
import { STATUSES } from "../../../config"; import { STATUSES } from "../../../config";
@ -13,15 +13,15 @@ export const TakeToWorkButton = () => {
const { prediction, categories, region } = filters; const { prediction, categories, region } = filters;
const { selection } = usePointSelection(); const { selection } = usePointSelection();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const [popupVisible, setPopupVisible] = useState(false); const [isModalOpened, setIsModalOpened] = useState(false);
const [isSuccessModalOpened, setIsSuccessModalOpened] = useState(false); const {
mutate: updateStatus,
const { mutate: updateStatus } = useUpdateStatus({ isLoading,
isSuccess,
} = useUpdateStatus({
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries(["table", 1, filters]); queryClient.invalidateQueries(["table", 1, filters]);
setPopupVisible(false);
setIsSuccessModalOpened(true);
}, },
}); });
@ -47,50 +47,71 @@ export const TakeToWorkButton = () => {
updateStatus(params); updateStatus(params);
}; };
const getModalFooter = () => {
if (isSuccess) {
return [
<Button
key="ok-button"
type="primary"
onClick={() => setIsModalOpened(false)}
>
Хорошо
</Button>,
];
}
if (isLoading) return null;
return (
<div className="flex items-center justify-center gap-x-4">
<Button onClick={() => setIsModalOpened(false)}>Отмена</Button>
<Button type="primary" onClick={takeToWork}>
Да
</Button>
</div>
);
};
return ( return (
<> <>
<Popover <Button
trigger="click" type="primary"
open={popupVisible} block
onOpenChange={setPopupVisible} className={"mt-2"}
content={ onClick={() => setIsModalOpened(true)}
<div className="p-2">
<Title text="Уверены, что хотите взять отобранные локации в работу?" />
<div className="flex items-center justify-center gap-x-4">
<Button onClick={() => setPopupVisible(false)}>Отмена</Button>
<Button type="primary" onClick={takeToWork}>
Да
</Button>
</div>
</div>
}
> >
<Button type="primary" block className={"mt-2"}> <span className="mr-1">Взять в работу</span>
<span className="mr-1">Взять в работу</span> <ArrowRightOutlined />
<ArrowRightOutlined /> </Button>
</Button>
</Popover>
<Modal <Modal
title={" "} title={" "}
centered centered
open={isSuccessModalOpened} open={isModalOpened}
footer={[ onCancel={() => setIsModalOpened(false)}
<Button closable={true}
key="ok-button" footer={getModalFooter()}
type="primary"
onClick={() => setIsSuccessModalOpened(false)}
>
Хорошо
</Button>,
]}
> >
<Alert {isSuccess ? (
message="Успешно" <Alert
description="Выбранные точки отправлены на согласование. Посмотреть на них можно во второй message="Успешно"
description="Выбранные точки отправлены на согласование. Посмотреть на них можно во второй
вкладке" вкладке"
type="success" type="success"
showIcon showIcon
/> />
) : (
<Title
text="Уверены, что хотите взять отобранные локации в работу?"
className="text-center"
/>
)}
{isLoading && (
<div className="flex justify-center py-2">
<Spin tip="Отправляем на согласование..." size="large" />
</div>
)}
</Modal> </Modal>
</> </>
); );

@ -25,16 +25,16 @@ const store = (set) => ({
state.filters.region = value; state.filters.region = value;
}), }),
clear: (predictionFullRange) => clear: (fullRange) =>
set((state) => { set((state) => {
if (!predictionFullRange) { if (!fullRange) {
state.filters = INITIAL; state.filters = INITIAL;
return state; return state;
} }
state.filters = { state.filters = {
...INITIAL, ...INITIAL,
prediction: [predictionFullRange[0], predictionFullRange[1]], prediction: fullRange.prediction,
}; };
}), }),
}); });

@ -41,11 +41,13 @@ const store = (set) => ({
return state; return state;
} }
const { deltaTraffic, factTraffic, age } = fullRange;
state.filters = { state.filters = {
...INITIAL, ...INITIAL,
deltaTraffic: [fullRange.deltaTraffic[0], fullRange.deltaTraffic[1]], deltaTraffic,
factTraffic: [fullRange.factTraffic[0], fullRange.factTraffic[1]], factTraffic,
age: [fullRange.age[0], fullRange.age[1]], age,
}; };
}), }),
}); });

Loading…
Cancel
Save