add coupon state feedback

This commit is contained in:
nflnkr 2023-03-14 15:47:05 +03:00
parent fe6e939e4a
commit af428416ea
3 changed files with 25 additions and 21 deletions

@ -23,7 +23,6 @@ export default function Cart({ selectedTariffs }: Props) {
const [couponField, setCouponField] = useState<string>("");
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [isNonCommercial, setIsNonCommercial] = useState<boolean>(false);
// const [coupon, setCoupon] = useState<string | undefined>();
const cartRows = cartTotal?.items.map(cartItemTotal => {
const service = cartItemTotal.tariff.privilege.serviceKey;
@ -126,6 +125,22 @@ export default function Cart({ selectedTariffs }: Props) {
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
sx={{
border: "1px solid white",
@ -151,27 +166,13 @@ export default function Cart({ selectedTariffs }: Props) {
}
}}
/>
{/* <Button
sx={{ maxWidth: "140px" }}
onClick={() => setCoupon(couponField)}
>применить промокод</Button> */}
</Box>
<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,
}}
/>
{cartTotal?.couponState && (
cartTotal.couponState === "applied" ?
<Alert severity="success">Купон применен!</Alert>
:
<Alert severity="error">Подходящий купон не найден!</Alert>
)}
<Button onClick={handleCalcCartClick} sx={{ ml: "auto" }}>рассчитать</Button>
</Paper>

@ -45,6 +45,7 @@ export function calcCartData(
dwarfener: null,
},
envolvedCartDiscounts: [],
couponState: coupon ? "not found" : null,
};
// layer 0
@ -87,6 +88,7 @@ export function calcCartData(
cartItemTotal.totalPrice *= product.factor;
cartItemTotal.envolvedDiscounts.push(couponDiscount);
cartTotal.couponState = "applied";
privilegesAffectedByCoupon.push(product.privilegeId);
});

@ -140,4 +140,5 @@ export interface CartTotal {
discountsByService: ServiceToDiscountMap;
/** Учтенные скидки типов userType, cartPurchasesAmount, totalPurchasesAmount */
envolvedCartDiscounts: (UserTypeDiscount | CartPurchasesAmountDiscount | PurchasesAmountDiscount)[];
couponState: "applied" | "not found" | null;
}