preserve cart & checkout elment on refersh

This commit is contained in:
2025-12-31 16:23:37 +03:00
parent 71e1d71c96
commit 2416b37069
9 changed files with 46 additions and 34 deletions

View File

@@ -4,6 +4,8 @@ import ProInputCard from "components/ProInputCard/ProInputCard.tsx";
import ProRatioGroups from "components/ProRatioGroups/ProRatioGroups.tsx";
import dayjs from "dayjs";
import {
selectCart,
updateEstimateWay,
updatePickupDate,
updatePickupTime,
updatePickUpType,
@@ -11,9 +13,9 @@ import {
import useBreakPoint from "hooks/useBreakPoint.ts";
import { BottomSheet } from "pages/cart/components/timeEstimate/BottomSheet.tsx";
import { Dialog } from "pages/cart/components/timeEstimate/Dialog.tsx";
import { useState } from "react";
import { useState, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { useAppDispatch } from "redux/hooks";
import { useAppDispatch, useAppSelector } from "redux/hooks";
import { SERVER_DATE_FORMAT, UI_TIME_FORMAT } from "utils/constants.ts";
export default function TimeEstimateCard() {
@@ -21,7 +23,7 @@ export default function TimeEstimateCard() {
const { t } = useTranslation();
const form = useFormInstance();
const { isDesktop } = useBreakPoint();
const [estimateWay, setEstimateWay] = useState("now");
const { estimateWay } = useAppSelector(selectCart);
const [isEstimateTimeOpen, setIsEstimateTimeOpen] = useState(false);
const handleEstimateTimeSave = (date: string, time: string) => {
@@ -34,6 +36,11 @@ export default function TimeEstimateCard() {
setIsEstimateTimeOpen(false);
};
useEffect(() => {
form.setFieldsValue({ estimateWay });
}, [estimateWay]);
return (
<>
<ProInputCard title={t("cart.estimateTime")}>
@@ -52,16 +59,16 @@ export default function TimeEstimateCard() {
value={estimateWay}
onRatioClick={(value) => {
if (value === "now") {
setEstimateWay(value);
dispatch(updateEstimateWay(value));
handleEstimateTimeSave(
dayjs().format(SERVER_DATE_FORMAT),
dayjs().format(UI_TIME_FORMAT),
);
dispatch(updatePickUpType("now"));
} else {
setEstimateWay(value);
setIsEstimateTimeOpen(true);
dispatch(updateEstimateWay(value));
dispatch(updatePickUpType(""));
setIsEstimateTimeOpen(true);
}
}}
/>