вывод скидок в ДГ
This commit is contained in:
parent
a815229da0
commit
0572d31178
@ -12,12 +12,12 @@ const BoxButton = styled("div")(({ theme }) => ({
|
||||
}));
|
||||
|
||||
const columns: GridColDef[] = [
|
||||
{
|
||||
field: "id",
|
||||
headerName: "ID",
|
||||
width: 70,
|
||||
sortable: false,
|
||||
},
|
||||
// {
|
||||
// field: "id",
|
||||
// headerName: "ID",
|
||||
// width: 70,
|
||||
// sortable: false,
|
||||
// },
|
||||
{
|
||||
field: "name",
|
||||
headerName: "Название скидки",
|
||||
@ -56,6 +56,21 @@ const columns: GridColDef[] = [
|
||||
},
|
||||
];
|
||||
|
||||
const layerTranslate = [
|
||||
"",
|
||||
"Товар",
|
||||
"Сервис",
|
||||
"корзина",
|
||||
"лояльность",
|
||||
]
|
||||
const layerValue = [
|
||||
"",
|
||||
"Term",
|
||||
"PriceFrom",
|
||||
"CartPurchasesAmount",
|
||||
"PurchasesAmount",
|
||||
]
|
||||
|
||||
export default function DiscountDataGrid() {
|
||||
const theme = useTheme();
|
||||
const exampleDiscounts = useMockDiscountStore((state) => state.discounts);
|
||||
@ -63,8 +78,23 @@ export default function DiscountDataGrid() {
|
||||
const realDiscounts = useDiscountStore(state => state.discounts);
|
||||
|
||||
useDiscounts({ onNewDiscounts: addDiscounts });
|
||||
console.log(realDiscounts)
|
||||
|
||||
const discountsGridData: GridRowsProp = exampleDiscounts.map((discount) => {
|
||||
const rowBackDicounts: any = realDiscounts.filter(e => e.Layer > 0).map((discount:any) => {
|
||||
return {
|
||||
id: discount.ID,
|
||||
name: discount.Name,
|
||||
description: discount.Description,
|
||||
conditionType: layerTranslate[discount.Layer],
|
||||
factor: Math.floor(Number((1-discount.Target.Factor)*100)),
|
||||
value: layerValue[discount.Layer],
|
||||
active: discount.Deprecated ? "🚫" : "✅"
|
||||
};
|
||||
|
||||
})
|
||||
|
||||
|
||||
const discountsGridData: any = exampleDiscounts.map((discount) => {
|
||||
const value =
|
||||
(discount.condition as any).purchasesAmount ??
|
||||
(discount.condition as any).cartPurchasesAmount ??
|
||||
@ -82,13 +112,14 @@ export default function DiscountDataGrid() {
|
||||
value,
|
||||
};
|
||||
});
|
||||
const mix = [...rowBackDicounts, ...discountsGridData]
|
||||
|
||||
return (
|
||||
<Box sx={{ width: "100%", marginTop: "55px", p: "16px", maxWidth: "1000px" }}>
|
||||
<Box sx={{ height: 600 }}>
|
||||
<DataGrid
|
||||
checkboxSelection={true}
|
||||
rows={discountsGridData}
|
||||
rows={mix}
|
||||
columns={columns}
|
||||
selectionModel={selectedDiscountIds}
|
||||
onSelectionModelChange={setMockSelectedDiscountIds}
|
||||
|
@ -24,7 +24,12 @@ export const useDiscountStore = create<DiscountStore>()(
|
||||
)
|
||||
);
|
||||
|
||||
export const addDiscounts = (newDiscounts: DiscountStore["discounts"]) => useDiscountStore.setState(state => ({ discounts: [...state.discounts, ...newDiscounts] }));
|
||||
export const addDiscounts = (newDiscounts: DiscountStore["discounts"]) => {
|
||||
console.log(useDiscountStore.getState())
|
||||
console.log(newDiscounts)
|
||||
useDiscountStore.setState(state => ({ discounts: [...state.discounts, ...newDiscounts] }));
|
||||
console.log(useDiscountStore.getState())
|
||||
}
|
||||
|
||||
export const setSelectedDiscountIds = (selectedDiscountIds: DiscountStore["selectedDiscountIds"]) => useDiscountStore.setState({ selectedDiscountIds });
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user