update order details each 10 s and enhance the steppers UI and logic
This commit is contained in:
@@ -6,16 +6,20 @@ import { useAppDispatch, useAppSelector } from "redux/hooks";
|
|||||||
|
|
||||||
export default function CarPlateCard() {
|
export default function CarPlateCard() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
const {plateCar} = useAppSelector(state => state.order)
|
const plateCar = useAppSelector((state) => state.order.plateCar);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ProInputCard
|
<ProInputCard
|
||||||
title={t("cart.plateNumber")}
|
title={t("cart.plateNumber")}
|
||||||
dividerStyle={{ margin: "5px 0 0 0" }}
|
dividerStyle={{ margin: "5px 0 0 0" }}
|
||||||
>
|
>
|
||||||
<Form.Item label={t("cart.plateNumber")} name="plateNumber" style={{position:"relative", top: -5}}>
|
<Form.Item
|
||||||
|
label={t("cart.plateNumber")}
|
||||||
|
name="plateNumber"
|
||||||
|
style={{ position: "relative", top: -5 }}
|
||||||
|
>
|
||||||
<Input
|
<Input
|
||||||
placeholder={t("cart.plateNumber")}
|
placeholder={t("cart.plateNumber")}
|
||||||
size="large"
|
size="large"
|
||||||
|
|||||||
@@ -1,10 +1,43 @@
|
|||||||
import { Col, Row } from "antd";
|
import { Col, Row } from "antd";
|
||||||
import ProText from "components/ProText";
|
import ProText from "components/ProText";
|
||||||
|
import { Status } from "pages/checkout/hooks/types";
|
||||||
|
import type { CSSProperties } from "react";
|
||||||
|
import { Fragment, useMemo } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { colors } from "ThemeConstants";
|
import { colors } from "ThemeConstants";
|
||||||
|
|
||||||
export default function Stepper() {
|
interface StepperProps {
|
||||||
|
statuses?: Status[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Stepper({ statuses = [] }: StepperProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const labels = useMemo(
|
||||||
|
() => [t("order.reserved"), t("order.prepare"), t("order.ready")],
|
||||||
|
[t],
|
||||||
|
);
|
||||||
|
|
||||||
|
const activeIndex = useMemo(() => {
|
||||||
|
const reachedStatuses = statuses.length > 0 ? statuses.length - 1 : 0;
|
||||||
|
return Math.min(Math.max(reachedStatuses, 0), 2);
|
||||||
|
}, [statuses.length]);
|
||||||
|
|
||||||
|
const steps = useMemo(
|
||||||
|
() =>
|
||||||
|
Array.from({ length: 3 }, (_, index) => {
|
||||||
|
const status = statuses[index];
|
||||||
|
const label = status?.name || status?.alias || labels[index] || "";
|
||||||
|
const isPending = index > activeIndex;
|
||||||
|
return {
|
||||||
|
key: status ? `status-${status.id}` : `placeholder-${index}`,
|
||||||
|
label,
|
||||||
|
isPending,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
[activeIndex, labels, statuses],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
@@ -18,60 +51,46 @@ export default function Stepper() {
|
|||||||
align={"middle"}
|
align={"middle"}
|
||||||
style={{
|
style={{
|
||||||
width: 330,
|
width: 330,
|
||||||
|
maxWidth: "100%",
|
||||||
position: "relative",
|
position: "relative",
|
||||||
padding: "12px",
|
padding: "12px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Col>
|
{steps.map((step, index) => {
|
||||||
<div
|
const circleStyle: CSSProperties = step.isPending
|
||||||
style={{
|
? {
|
||||||
width: 12,
|
width: 12,
|
||||||
height: 12,
|
height: 12,
|
||||||
borderRadius: "50%",
|
borderRadius: "50%",
|
||||||
backgroundColor: colors.primary,
|
backgroundColor: "#FFF",
|
||||||
}}
|
border: "2px solid #BDBDBD",
|
||||||
></div>
|
}
|
||||||
</Col>
|
: {
|
||||||
<Col flex={"auto"}>
|
width: 12,
|
||||||
<div
|
height: 12,
|
||||||
style={{
|
borderRadius: "50%",
|
||||||
height: 1.5,
|
backgroundColor: colors.primary,
|
||||||
backgroundColor: colors.primary,
|
};
|
||||||
margin: "0 8px",
|
|
||||||
}}
|
const lineStyle: CSSProperties = {
|
||||||
></div>
|
height: 1.5,
|
||||||
</Col>
|
backgroundColor: step.isPending ? "#BDBDBD" : colors.primary,
|
||||||
<Col>
|
margin: "0 8px",
|
||||||
<div
|
};
|
||||||
style={{
|
|
||||||
width: 12,
|
return (
|
||||||
height: 12,
|
<Fragment key={step.key}>
|
||||||
borderRadius: "50%",
|
<Col>
|
||||||
backgroundColor: colors.primary,
|
<div style={circleStyle}></div>
|
||||||
}}
|
</Col>
|
||||||
></div>
|
{index < steps.length - 1 && (
|
||||||
</Col>
|
<Col flex={"auto"}>
|
||||||
<Col flex={"auto"}>
|
<div style={lineStyle}></div>
|
||||||
<div
|
</Col>
|
||||||
style={{
|
)}
|
||||||
height: 1.5,
|
</Fragment>
|
||||||
backgroundColor: colors.primary,
|
);
|
||||||
margin: "0 8px",
|
})}
|
||||||
}}
|
|
||||||
></div>
|
|
||||||
</Col>
|
|
||||||
<Col>
|
|
||||||
{" "}
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: 12,
|
|
||||||
height: 12,
|
|
||||||
borderRadius: "50%",
|
|
||||||
backgroundColor: "#FFF",
|
|
||||||
border: `2px solid #BDBDBD`,
|
|
||||||
}}
|
|
||||||
></div>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@@ -81,26 +100,25 @@ export default function Stepper() {
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{" "}
|
|
||||||
<Row
|
<Row
|
||||||
align={"middle"}
|
align={"middle"}
|
||||||
style={{
|
style={{
|
||||||
width: 330,
|
width: 330,
|
||||||
|
maxWidth: "100%",
|
||||||
position: "relative",
|
position: "relative",
|
||||||
padding: "12px",
|
padding: "12px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Col>
|
{steps.map((step, index) => (
|
||||||
<ProText>{t("order.reserved")}</ProText>
|
<Fragment key={`label-${step.key}`}>
|
||||||
</Col>
|
<Col>
|
||||||
<Col flex={"auto"}></Col>
|
<ProText type={step.isPending ? "secondary" : undefined}>
|
||||||
<Col>
|
{step.label}
|
||||||
<ProText>{t("order.prepare")}</ProText>
|
</ProText>
|
||||||
</Col>
|
</Col>
|
||||||
<Col flex={"auto"}></Col>
|
{index < steps.length - 1 && <Col flex={"auto"}></Col>}
|
||||||
<Col>
|
</Fragment>
|
||||||
<ProText type="secondary">{t("order.ready")}</ProText>
|
))}
|
||||||
</Col>
|
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ export default function OrderPage() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
skip: !orderId,
|
skip: !orderId,
|
||||||
|
// return it t0 60000 after finish testing
|
||||||
|
pollingInterval: 10000,
|
||||||
|
refetchOnMountOrArgChange: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -114,7 +117,7 @@ export default function OrderPage() {
|
|||||||
|
|
||||||
<Divider style={{ margin: "12px 0" }} />
|
<Divider style={{ margin: "12px 0" }} />
|
||||||
|
|
||||||
<Stepper />
|
<Stepper statuses={orderDetails?.status} />
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user