resend privileges resend discounts before calc
This commit is contained in:
parent
1f508e8a9c
commit
185c8aabda
@ -30,6 +30,7 @@ import { testUser } from "@root/stores/mocks/user";
|
||||
import { useTariffStore } from "@root/stores/tariffsStore";
|
||||
import { Discount } from "@root/model/discount";
|
||||
import useDiscounts from "@root/utils/hooks/useDiscounts";
|
||||
import { authStore } from "@root/stores/auth";
|
||||
|
||||
interface Props {
|
||||
selectedTariffs: GridSelectionModel;
|
||||
@ -53,12 +54,14 @@ interface MergedTariff {
|
||||
|
||||
export default function Cart({ selectedTariffs }: Props) {
|
||||
let cartTariffs = Object.values(useTariffStore().tariffs)
|
||||
useDiscounts({ onNewDiscounts: setDiscounts });
|
||||
const discounts = useDiscountStore((store) => store.discounts);
|
||||
// useDiscounts({ onNewDiscounts: setDiscounts });
|
||||
// const discounts = useDiscountStore((store) => store.discounts);
|
||||
const [discounts, setDiscounts] = useState<Discount[]>([]);
|
||||
const cartTotal = useCartStore((state) => state.cartTotal);
|
||||
const setCartTotal = useCartStore((store) => store.setCartTotal);
|
||||
const [couponField, setCouponField] = useState<string>("");
|
||||
const [loyaltyField, setLoyaltyField] = useState<string>("");
|
||||
const makeRequest = authStore.getState().makeRequest;
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
const [isNonCommercial, setIsNonCommercial] = useState<boolean>(false);
|
||||
console.log(cartTotal)
|
||||
@ -126,8 +129,17 @@ console.log(cartTotal)
|
||||
</Box>
|
||||
);
|
||||
|
||||
function handleCalcCartClick() {
|
||||
async function handleCalcCartClick() {
|
||||
//рассчитать
|
||||
const dis = await makeRequest<unknown>({
|
||||
url: "https://admin.pena.digital/price/discounts",
|
||||
method: "get",
|
||||
useToken: true,
|
||||
bearer: true,
|
||||
})
|
||||
console.log(dis)
|
||||
// @ts-ignore
|
||||
setDiscounts(dis.Discounts)
|
||||
|
||||
const cartItems = cartTariffs.filter((tariff) => selectedTariffs.includes(tariff.id)).map((tariff) => createCartItem(tariff));
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { Container, Typography } from "@mui/material";
|
||||
import { Container, IconButton, Tooltip, Typography } from "@mui/material";
|
||||
import { GridSelectionModel } from "@mui/x-data-grid";
|
||||
|
||||
import Cart from "@root/kitUI/Cart/Cart";
|
||||
@ -8,7 +8,7 @@ import axios from "axios";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { authStore } from "@root/stores/auth";
|
||||
import { useTariffStore } from "@root/stores/tariffsStore";
|
||||
import { usePrivilegeStore } from "@root/stores/privilegesStore";
|
||||
import { usePrivilegeStore, resetPrivilegeArray } from "@root/stores/privilegesStore";
|
||||
import { useGetTariffs } from "@root/hooks/useGetTariffs.hook";
|
||||
|
||||
import TariffsDG from "./tariffsDG";
|
||||
@ -17,14 +17,37 @@ import Privileges from "./Privileges/Privileges";
|
||||
import ChangePriceModal from "./Privileges/ChangePriceModal";
|
||||
import {useRefreshPrivilegesStore} from "@root/hooks/useRefreshPrivilegesStore.hook"
|
||||
import { Tariff } from "@root/model/tariff";
|
||||
import AutorenewIcon from '@mui/icons-material/Autorenew';
|
||||
import { RealPrivilege } from "@root/model/privilege";
|
||||
import { Discount, GetDiscountResponse } from "@root/model/discount";
|
||||
|
||||
export default function Tariffs() {
|
||||
const token = authStore((state) => state.token);
|
||||
// const tariffs = useTariffStore((state) => state.tariffs);
|
||||
const privileges = usePrivilegeStore((state) => state.privileges);
|
||||
const tariffs = useTariffStore((state) => state.tariffs);
|
||||
const [selectedTariffs, setSelectedTariffs] = useState<GridSelectionModel>([]);
|
||||
|
||||
const refreshStores = async () => {
|
||||
const priv = await axios<RealPrivilege[]>({
|
||||
method: "get",
|
||||
url: "https://admin.pena.digital/strator/privilege/service",
|
||||
});
|
||||
let extracted:RealPrivilege[] = []
|
||||
for (let serviceKey in priv.data) { //Приходит объект. В его значениях массивы привилегий для разных сервисов. Высыпаем в общую кучу и обновляем стор
|
||||
extracted = extracted.concat(priv.data[serviceKey])
|
||||
}
|
||||
let readyArray = extracted.map((privilege) => ({
|
||||
serviceKey: privilege.serviceKey,
|
||||
privilegeId: privilege.privilegeId,
|
||||
name: privilege.name,
|
||||
description: privilege.description,
|
||||
type: privilege.type,
|
||||
price: privilege.price,
|
||||
value: privilege.value,
|
||||
id: privilege._id,
|
||||
}))
|
||||
resetPrivilegeArray(readyArray)
|
||||
enqueueSnackbar("привилегии обновлены")
|
||||
}
|
||||
|
||||
return (
|
||||
<Container
|
||||
@ -43,6 +66,7 @@ export default function Tariffs() {
|
||||
|
||||
<Typography variant="h6">Список привилегий</Typography>
|
||||
|
||||
<Tooltip title="обновить список привилегий"><IconButton onClick={refreshStores}><AutorenewIcon sx={{color:"white"}}/></IconButton></Tooltip>
|
||||
<Privileges />
|
||||
|
||||
<ChangePriceModal />
|
||||
|
BIN
src/stores/tariffs.ts.zip
Normal file
BIN
src/stores/tariffs.ts.zip
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user