add coupon state feedback
This commit is contained in:
parent
fe6e939e4a
commit
af428416ea
@ -23,7 +23,6 @@ export default function Cart({ selectedTariffs }: Props) {
|
|||||||
const [couponField, setCouponField] = useState<string>("");
|
const [couponField, setCouponField] = useState<string>("");
|
||||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||||
const [isNonCommercial, setIsNonCommercial] = useState<boolean>(false);
|
const [isNonCommercial, setIsNonCommercial] = useState<boolean>(false);
|
||||||
// const [coupon, setCoupon] = useState<string | undefined>();
|
|
||||||
|
|
||||||
const cartRows = cartTotal?.items.map(cartItemTotal => {
|
const cartRows = cartTotal?.items.map(cartItemTotal => {
|
||||||
const service = cartItemTotal.tariff.privilege.serviceKey;
|
const service = cartItemTotal.tariff.privilege.serviceKey;
|
||||||
@ -126,6 +125,22 @@ export default function Cart({ selectedTariffs }: Props) {
|
|||||||
gap: "20px",
|
gap: "20px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<FormControlLabel
|
||||||
|
checked={isNonCommercial}
|
||||||
|
onChange={(e, checked) => setIsNonCommercial(checked)}
|
||||||
|
control={<Checkbox
|
||||||
|
sx={{
|
||||||
|
color: theme.palette.secondary.main,
|
||||||
|
"&.Mui-checked": {
|
||||||
|
color: theme.palette.secondary.main,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>}
|
||||||
|
label="НКО"
|
||||||
|
sx={{
|
||||||
|
color: theme.palette.secondary.main,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
border: "1px solid white",
|
border: "1px solid white",
|
||||||
@ -151,27 +166,13 @@ export default function Cart({ selectedTariffs }: Props) {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{/* <Button
|
|
||||||
sx={{ maxWidth: "140px" }}
|
|
||||||
onClick={() => setCoupon(couponField)}
|
|
||||||
>применить промокод</Button> */}
|
|
||||||
</Box>
|
</Box>
|
||||||
<FormControlLabel
|
{cartTotal?.couponState && (
|
||||||
checked={isNonCommercial}
|
cartTotal.couponState === "applied" ?
|
||||||
onChange={(e, checked) => setIsNonCommercial(checked)}
|
<Alert severity="success">Купон применен!</Alert>
|
||||||
control={<Checkbox
|
:
|
||||||
sx={{
|
<Alert severity="error">Подходящий купон не найден!</Alert>
|
||||||
color: theme.palette.secondary.main,
|
)}
|
||||||
"&.Mui-checked": {
|
|
||||||
color: theme.palette.secondary.main,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>}
|
|
||||||
label="НКО"
|
|
||||||
sx={{
|
|
||||||
color: theme.palette.secondary.main,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Button onClick={handleCalcCartClick} sx={{ ml: "auto" }}>рассчитать</Button>
|
<Button onClick={handleCalcCartClick} sx={{ ml: "auto" }}>рассчитать</Button>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ export function calcCartData(
|
|||||||
dwarfener: null,
|
dwarfener: null,
|
||||||
},
|
},
|
||||||
envolvedCartDiscounts: [],
|
envolvedCartDiscounts: [],
|
||||||
|
couponState: coupon ? "not found" : null,
|
||||||
};
|
};
|
||||||
|
|
||||||
// layer 0
|
// layer 0
|
||||||
@ -87,6 +88,7 @@ export function calcCartData(
|
|||||||
|
|
||||||
cartItemTotal.totalPrice *= product.factor;
|
cartItemTotal.totalPrice *= product.factor;
|
||||||
cartItemTotal.envolvedDiscounts.push(couponDiscount);
|
cartItemTotal.envolvedDiscounts.push(couponDiscount);
|
||||||
|
cartTotal.couponState = "applied";
|
||||||
privilegesAffectedByCoupon.push(product.privilegeId);
|
privilegesAffectedByCoupon.push(product.privilegeId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -140,4 +140,5 @@ export interface CartTotal {
|
|||||||
discountsByService: ServiceToDiscountMap;
|
discountsByService: ServiceToDiscountMap;
|
||||||
/** Учтенные скидки типов userType, cartPurchasesAmount, totalPurchasesAmount */
|
/** Учтенные скидки типов userType, cartPurchasesAmount, totalPurchasesAmount */
|
||||||
envolvedCartDiscounts: (UserTypeDiscount | CartPurchasesAmountDiscount | PurchasesAmountDiscount)[];
|
envolvedCartDiscounts: (UserTypeDiscount | CartPurchasesAmountDiscount | PurchasesAmountDiscount)[];
|
||||||
|
couponState: "applied" | "not found" | null;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user