feat: modules and module-editor pages
This commit is contained in:
82
src/app/modules/hooks/useAttributesInnerTableColumns.tsx
Normal file
82
src/app/modules/hooks/useAttributesInnerTableColumns.tsx
Normal file
@ -0,0 +1,82 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import { IconCheck, IconX } from "@tabler/icons-react";
|
||||
import { DataTableColumn } from "mantine-datatable";
|
||||
import { Box } from "@mantine/core";
|
||||
import useIsMobile from "@/hooks/utils/useIsMobile";
|
||||
import { ModuleAttributeSchema } from "@/lib/client";
|
||||
import {
|
||||
utcDateTimeToLocalString,
|
||||
utcDateToLocalString,
|
||||
} from "@/utils/datetime";
|
||||
|
||||
const useAttributesInnerTableColumns = () => {
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
const renderCheck = (value: boolean) => (value ? <IconCheck /> : <IconX />);
|
||||
|
||||
return useMemo(
|
||||
() =>
|
||||
[
|
||||
{
|
||||
title: "Название атрибута",
|
||||
accessor: "label",
|
||||
},
|
||||
{
|
||||
title: "Тип",
|
||||
accessor: "type.name",
|
||||
},
|
||||
{
|
||||
title: "Значение по умолчанию",
|
||||
accessor: "defaultValue",
|
||||
render: attr => {
|
||||
if (!attr.defaultValue) return <>-</>;
|
||||
const value = attr.defaultValue.value;
|
||||
if (value === null) return <>-</>;
|
||||
|
||||
const type = attr.type.type;
|
||||
if (type === "datetime") {
|
||||
return utcDateTimeToLocalString(value as string);
|
||||
}
|
||||
if (type === "date") {
|
||||
return utcDateToLocalString(value as string);
|
||||
}
|
||||
if (type === "bool") {
|
||||
return value ? <IconCheck /> : <IconX />;
|
||||
}
|
||||
|
||||
return <>{value}</>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Синхронизировано в группе",
|
||||
accessor: "isApplicableToGroup",
|
||||
render: attr => renderCheck(attr.isApplicableToGroup),
|
||||
},
|
||||
{
|
||||
title: "Вывод на дашборде",
|
||||
accessor: "isShownOnDashboard",
|
||||
render: attr => renderCheck(attr.isShownOnDashboard),
|
||||
},
|
||||
{
|
||||
title: "Подсветка, если просрочен",
|
||||
accessor: "isHighlightIfExpired",
|
||||
render: attr => renderCheck(attr.isHighlightIfExpired),
|
||||
},
|
||||
{
|
||||
title: "Может быть пустым",
|
||||
accessor: "isNullable",
|
||||
render: attr => renderCheck(attr.isNullable),
|
||||
},
|
||||
{
|
||||
title: "Описаниие",
|
||||
accessor: "description",
|
||||
render: attr => <Box>{attr.description}</Box>,
|
||||
},
|
||||
] as DataTableColumn<ModuleAttributeSchema>[],
|
||||
[isMobile]
|
||||
);
|
||||
};
|
||||
|
||||
export default useAttributesInnerTableColumns;
|
||||
Reference in New Issue
Block a user