Merge branch 'patch-discounts' into 'dev'
fix: patch discounts See merge request frontend/admin!30
This commit is contained in:
commit
c238e76b68
@ -1,47 +1,51 @@
|
||||
import { Box, Button, IconButton, useTheme } from "@mui/material";
|
||||
import { DataGrid, GridColDef, GridRowsProp, GridToolbar } from "@mui/x-data-grid";
|
||||
import { formatDiscountFactor } from "@root/kitUI/Cart/calc";
|
||||
import { openEditDiscountDialog, setDiscounts, setSelectedDiscountIds, updateDiscount, useDiscountStore } from "@root/stores/discounts";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { GridSelectionModel } from "@mui/x-data-grid";
|
||||
import { Box, Button } from "@mui/material";
|
||||
|
||||
import { changeDiscount } from "@root/api/discounts";
|
||||
import { findDiscountsById } from "@root/stores/discounts";
|
||||
import { GridSelectionModel, GridRowId } from "@mui/x-data-grid";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
|
||||
import { requestDiscounts } from "@root/services/discounts.service";
|
||||
|
||||
interface Props {
|
||||
selectedRows: GridSelectionModel
|
||||
selectedRows: GridSelectionModel;
|
||||
}
|
||||
export default function DiscountDataGrid({selectedRows}:Props) {
|
||||
export default function DiscountDataGrid({ selectedRows }: Props) {
|
||||
const changeData = async (isActive: boolean) => {
|
||||
let done = 0;
|
||||
let fatal = 0;
|
||||
|
||||
const changeData = (isActive:boolean) => {
|
||||
let done = 0
|
||||
let fatal = 0
|
||||
selectedRows.forEach((id:GridRowId) => {
|
||||
const discount = findDiscountsById(String(id))
|
||||
if (discount) {
|
||||
discount.Deprecated = isActive
|
||||
changeDiscount(String(id), discount)
|
||||
.then(() => {
|
||||
done += 1
|
||||
})
|
||||
.catch(() => {
|
||||
fatal += 1
|
||||
})
|
||||
.finally(() => {
|
||||
if (done) enqueueSnackbar("Успешно изменён статус " + done + " скидок")
|
||||
if (fatal) enqueueSnackbar(fatal + " скидок не изменили статус")
|
||||
})
|
||||
} else {
|
||||
enqueueSnackbar("Скидка не найдена")
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
for (const id of selectedRows) {
|
||||
const discount = findDiscountsById(String(id));
|
||||
|
||||
return (
|
||||
<Box width="400px" display="flex" justifyContent="space-between">
|
||||
<Button onClick={() => changeData(false)}>Активировать</Button>
|
||||
<Button onClick={() => changeData(true)}>Деактивировать</Button>
|
||||
</Box>
|
||||
);
|
||||
if (!discount) {
|
||||
return enqueueSnackbar("Скидка не найдена");
|
||||
}
|
||||
|
||||
try {
|
||||
await changeDiscount(String(id), { ...discount, Deprecated: isActive });
|
||||
|
||||
done += 1;
|
||||
} catch {
|
||||
fatal += 1;
|
||||
}
|
||||
}
|
||||
|
||||
await requestDiscounts();
|
||||
|
||||
if (done) {
|
||||
enqueueSnackbar("Успешно изменён статус " + done + " скидок");
|
||||
}
|
||||
|
||||
if (fatal) {
|
||||
enqueueSnackbar(fatal + " скидок не изменили статус");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Box width="400px" display="flex" justifyContent="space-between">
|
||||
<Button onClick={() => changeData(false)}>Активировать</Button>
|
||||
<Button onClick={() => changeData(true)}>Деактивировать</Button>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ export default function DiscountDataGrid({ selectedRowsHC }: Props) {
|
||||
}, []);
|
||||
|
||||
const rowBackDicounts: GridRowsProp = realDiscounts
|
||||
.filter((e) => e.Layer > 0)
|
||||
.filter(({ Layer }) => Layer > 0)
|
||||
.map((discount) => {
|
||||
console.log(
|
||||
discount.Condition[
|
||||
|
Loading…
Reference in New Issue
Block a user