2023-02-28 08:30:57 +00:00
|
|
|
import * as React from "react";
|
|
|
|
import { GridColDef, GridSelectionModel, GridToolbar } from "@mui/x-data-grid";
|
2023-05-16 16:57:44 +00:00
|
|
|
|
2023-02-28 08:30:57 +00:00
|
|
|
import DataGrid from "@kitUI/datagrid";
|
2023-05-16 16:57:44 +00:00
|
|
|
|
2023-03-06 13:26:55 +00:00
|
|
|
import { useTariffStore } from "@root/stores/tariffs";
|
|
|
|
import { SERVICE_LIST } from "@root/model/tariff";
|
2023-05-23 12:20:37 +00:00
|
|
|
import { findPrivilegeById } from "@root/stores/privileges";
|
2023-02-28 08:30:57 +00:00
|
|
|
|
|
|
|
const columns: GridColDef[] = [
|
2023-05-16 16:57:44 +00:00
|
|
|
{ field: "id", headerName: "ID", width: 100 },
|
|
|
|
{ field: "name", headerName: "Название тарифа", width: 150 },
|
|
|
|
{ field: "serviceName", headerName: "Сервис", width: 150 }, //инфо из гитлаба.
|
|
|
|
{ field: "privilege", headerName: "Привелегия", width: 150 },
|
|
|
|
{ field: "amount", headerName: "Количество", width: 110 },
|
|
|
|
{ field: "type", headerName: "Единица", width: 100 },
|
|
|
|
{ field: "pricePerUnit", headerName: "Цена за ед.", width: 100 },
|
|
|
|
{ field: "isCustomPrice", headerName: "Кастомная цена", width: 130 },
|
|
|
|
{ field: "total", headerName: "Сумма", width: 130 },
|
2023-03-06 13:26:55 +00:00
|
|
|
];
|
2023-02-28 08:30:57 +00:00
|
|
|
|
2023-03-06 13:26:55 +00:00
|
|
|
interface Props {
|
2023-05-16 16:57:44 +00:00
|
|
|
handleSelectionChange: (selectionModel: GridSelectionModel) => void;
|
2023-03-06 13:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function TariffsDG({ handleSelectionChange }: Props) {
|
2023-05-16 16:57:44 +00:00
|
|
|
const tariffs = useTariffStore((state) => state.tariffs);
|
2023-03-06 13:26:55 +00:00
|
|
|
|
2023-05-16 16:57:44 +00:00
|
|
|
const gridData = tariffs.map((tariff) => ({
|
|
|
|
id: tariff.id,
|
|
|
|
name: tariff.name,
|
2023-05-23 12:20:37 +00:00
|
|
|
serviceName: SERVICE_LIST.find((service) => service.serviceKey === findPrivilegeById(tariff.privilegeId)?.serviceKey)?.displayName,
|
|
|
|
privilege: `(${tariff.privilegeId}) ${findPrivilegeById(tariff.privilegeId)?.description ?? "Привилегия не найдена"}`,
|
2023-05-16 16:57:44 +00:00
|
|
|
amount: tariff.amount,
|
2023-05-23 12:20:37 +00:00
|
|
|
type: findPrivilegeById(tariff.privilegeId)?.type === "count" ? "день" : "шт.",
|
|
|
|
pricePerUnit: tariff.customPricePerUnit ?? findPrivilegeById(tariff.privilegeId)?.pricePerUnit,
|
2023-05-16 16:57:44 +00:00
|
|
|
isCustomPrice: tariff.customPricePerUnit === undefined ? "Нет" : "Да",
|
2023-05-23 12:20:37 +00:00
|
|
|
total: tariff.amount * (tariff.customPricePerUnit ?? findPrivilegeById(tariff.privilegeId)?.pricePerUnit ?? 0),
|
2023-05-16 16:57:44 +00:00
|
|
|
}));
|
2023-02-28 08:30:57 +00:00
|
|
|
|
2023-05-16 16:57:44 +00:00
|
|
|
return (
|
|
|
|
<DataGrid
|
|
|
|
checkboxSelection={true}
|
|
|
|
rows={gridData}
|
|
|
|
columns={columns}
|
|
|
|
components={{ Toolbar: GridToolbar }}
|
|
|
|
onSelectionModelChange={handleSelectionChange}
|
|
|
|
/>
|
|
|
|
);
|
2023-02-28 08:30:57 +00:00
|
|
|
}
|