2024-03-03 13:30:57 +00:00
|
|
|
import { IconButton } from "@mui/material";
|
|
|
|
import { GridColDef } from "@mui/x-data-grid";
|
|
|
|
import { Promocode } from "@root/model/promocodes";
|
2024-03-30 20:19:53 +00:00
|
|
|
import { useMemo, useState } from "react";
|
2024-03-03 13:30:57 +00:00
|
|
|
|
2024-03-26 15:41:22 +00:00
|
|
|
import { BarChart, Delete } from "@mui/icons-material";
|
2024-03-29 20:27:07 +00:00
|
|
|
import {promocodeApi} from "@root/api/promocode/requests";
|
2024-03-26 15:41:22 +00:00
|
|
|
|
|
|
|
export function usePromocodeGridColDef(
|
|
|
|
setStatistics: (id: string) => void,
|
|
|
|
deletePromocode: (id: string) => void
|
|
|
|
) {
|
2024-03-29 20:27:07 +00:00
|
|
|
const validity = (value:string|number) => {if(value===0){return "неоганичен"}else {return new Date(value).toLocaleString()}}
|
|
|
|
return useMemo<GridColDef<Promocode, string | number, string >[]>(
|
2024-03-26 15:41:22 +00:00
|
|
|
() => [
|
|
|
|
{
|
|
|
|
field: "id",
|
|
|
|
headerName: "ID",
|
|
|
|
width: 30,
|
|
|
|
sortable: false,
|
|
|
|
valueGetter: ({ row }) => row.id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "codeword",
|
|
|
|
headerName: "Кодовое слово",
|
|
|
|
width: 160,
|
|
|
|
sortable: false,
|
|
|
|
valueGetter: ({ row }) => row.codeword,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "factor",
|
|
|
|
headerName: "Коэф. скидки",
|
|
|
|
width: 120,
|
|
|
|
sortable: false,
|
|
|
|
valueGetter: ({ row }) =>
|
|
|
|
Math.round(row.bonus.discount.factor * 1000) / 1000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "activationCount",
|
|
|
|
headerName: "Кол-во активаций",
|
|
|
|
width: 140,
|
|
|
|
sortable: false,
|
|
|
|
valueGetter: ({ row }) => row.activationCount,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "dueTo",
|
|
|
|
headerName: "Истекает",
|
|
|
|
width: 160,
|
|
|
|
sortable: false,
|
|
|
|
valueGetter: ({ row }) => row.dueTo * 1000,
|
2024-03-29 20:27:07 +00:00
|
|
|
valueFormatter: ({ value }) => `${validity(value)}`,
|
2024-03-26 15:41:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "settings",
|
|
|
|
headerName: "",
|
|
|
|
width: 60,
|
|
|
|
sortable: false,
|
|
|
|
renderCell: (params) => {
|
|
|
|
return (
|
2024-03-29 20:27:07 +00:00
|
|
|
<IconButton onClick={() => {
|
|
|
|
setStatistics(params.row.id,)
|
|
|
|
promocodeApi.getPromocodeStatistics(params.row.id, 0, 0)
|
|
|
|
}}>
|
2024-03-26 15:41:22 +00:00
|
|
|
<BarChart />
|
|
|
|
</IconButton>
|
|
|
|
);
|
2024-03-03 13:30:57 +00:00
|
|
|
},
|
2024-03-26 15:41:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "delete",
|
|
|
|
headerName: "",
|
|
|
|
width: 60,
|
|
|
|
sortable: false,
|
|
|
|
renderCell: (params) => {
|
|
|
|
return (
|
|
|
|
<IconButton onClick={() => deletePromocode(params.row.id)}>
|
|
|
|
<Delete />
|
|
|
|
</IconButton>
|
|
|
|
);
|
2024-03-03 13:30:57 +00:00
|
|
|
},
|
2024-03-26 15:41:22 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
[deletePromocode, setStatistics]
|
|
|
|
);
|
2024-03-03 13:30:57 +00:00
|
|
|
}
|