Merge branch 'dev' into 'staging'

Dev

See merge request frontend/admin!78
This commit is contained in:
Nastya 2024-04-27 13:52:43 +00:00
commit 888fefae2b

@ -4,14 +4,20 @@ import { Promocode } from "@root/model/promocodes";
import { useMemo, useState } from "react"; import { useMemo, useState } from "react";
import { BarChart, Delete } from "@mui/icons-material"; import { BarChart, Delete } from "@mui/icons-material";
import {promocodeApi} from "@root/api/promocode/requests"; import { promocodeApi } from "@root/api/promocode/requests";
export function usePromocodeGridColDef( export function usePromocodeGridColDef(
setStatistics: (id: string) => void, setStatistics: (id: string) => void,
deletePromocode: (id: string) => void deletePromocode: (id: string) => void
) { ) {
const validity = (value:string|number) => {if(value===0){return "неоганичен"}else {return new Date(value).toLocaleString()}} const validity = (value: string | number) => {
return useMemo<GridColDef<Promocode, string | number, string >[]>( if (value === 0) {
return "неоганичен";
} else {
return new Date(value).toLocaleString();
}
};
return useMemo<GridColDef<Promocode, string | number, string>[]>(
() => [ () => [
{ {
field: "id", field: "id",
@ -50,6 +56,14 @@ export function usePromocodeGridColDef(
valueGetter: ({ row }) => row.dueTo * 1000, valueGetter: ({ row }) => row.dueTo * 1000,
valueFormatter: ({ value }) => `${validity(value)}`, valueFormatter: ({ value }) => `${validity(value)}`,
}, },
{
field: "description",
headerName: "Описание",
minWidth: 200,
flex: 1,
sortable: false,
valueGetter: ({ row }) => row.description,
},
{ {
field: "settings", field: "settings",
headerName: "", headerName: "",
@ -57,10 +71,12 @@ export function usePromocodeGridColDef(
sortable: false, sortable: false,
renderCell: (params) => { renderCell: (params) => {
return ( return (
<IconButton onClick={() => { <IconButton
setStatistics(params.row.id,) onClick={() => {
promocodeApi.getPromocodeStatistics(params.row.id, 0, 0) setStatistics(params.row.id);
}}> promocodeApi.getPromocodeStatistics(params.row.id, 0, 0);
}}
>
<BarChart /> <BarChart />
</IconButton> </IconButton>
); );