Merge branch 'patch-discounts' into 'dev'
fix: patch discounts See merge request frontend/admin!30
This commit is contained in:
commit
c238e76b68
@ -1,43 +1,47 @@
|
|||||||
import { Box, Button, IconButton, useTheme } from "@mui/material";
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { DataGrid, GridColDef, GridRowsProp, GridToolbar } from "@mui/x-data-grid";
|
import { GridSelectionModel } from "@mui/x-data-grid";
|
||||||
import { formatDiscountFactor } from "@root/kitUI/Cart/calc";
|
import { Box, Button } from "@mui/material";
|
||||||
import { openEditDiscountDialog, setDiscounts, setSelectedDiscountIds, updateDiscount, useDiscountStore } from "@root/stores/discounts";
|
|
||||||
import { changeDiscount } from "@root/api/discounts";
|
import { changeDiscount } from "@root/api/discounts";
|
||||||
import { findDiscountsById } from "@root/stores/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 {
|
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) => {
|
for (const id of selectedRows) {
|
||||||
let done = 0
|
const discount = findDiscountsById(String(id));
|
||||||
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("Скидка не найдена")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
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 (
|
return (
|
||||||
<Box width="400px" display="flex" justifyContent="space-between">
|
<Box width="400px" display="flex" justifyContent="space-between">
|
||||||
<Button onClick={() => changeData(false)}>Активировать</Button>
|
<Button onClick={() => changeData(false)}>Активировать</Button>
|
||||||
|
@ -125,7 +125,7 @@ export default function DiscountDataGrid({ selectedRowsHC }: Props) {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const rowBackDicounts: GridRowsProp = realDiscounts
|
const rowBackDicounts: GridRowsProp = realDiscounts
|
||||||
.filter((e) => e.Layer > 0)
|
.filter(({ Layer }) => Layer > 0)
|
||||||
.map((discount) => {
|
.map((discount) => {
|
||||||
console.log(
|
console.log(
|
||||||
discount.Condition[
|
discount.Condition[
|
||||||
|
Loading…
Reference in New Issue
Block a user