68 lines
2.6 KiB
TypeScript
68 lines
2.6 KiB
TypeScript
import str from "@/hooks/use-string"
|
|
import DataTable from "./Table/DataTable"
|
|
import useTrans from "@/hooks/use-translations"
|
|
import DataTableFilterButton from "./Table/DataTableFilterButton";
|
|
import { AppEnv, DocumentModel, Resource, TranslationField } from "../types/global";
|
|
import { Row } from "@tanstack/react-table";
|
|
import { usePage } from "@inertiajs/react";
|
|
import { Views } from "@/lib/utils";
|
|
import { renderTranslationCell } from "@/lib/translationCellFallback";
|
|
|
|
interface Props {
|
|
documents: Resource
|
|
}
|
|
const AssociatedDocumentList = (props: Props) => {
|
|
const { documents } = props;
|
|
const { appEnv } = usePage().props as unknown as {
|
|
appEnv: AppEnv;
|
|
};
|
|
const documentColumns = [
|
|
{
|
|
accessorKey: "name",
|
|
header: ({ column }: { column: { id: string } }) => (
|
|
<DataTableFilterButton
|
|
label={str(useTrans(`validation.attributes.${column.id}`)).ucFirst().value()}
|
|
field={column.id}
|
|
/>
|
|
),
|
|
cell: ({ row }: { row: Row<DocumentModel> }) => {
|
|
return renderTranslationCell(
|
|
row.getValue("name")
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "path",
|
|
header: ({ column }: { column: { id: string } }) => (
|
|
<DataTableFilterButton
|
|
label={str(useTrans(`validation.attributes.${column.id}`)).ucFirst().value()}
|
|
field={column.id}
|
|
/>
|
|
),
|
|
cell: ({ row }: { row: Row<DocumentModel> }) => {
|
|
return (row.getValue("path") as TranslationField)[appEnv.locale] ? (
|
|
(<a target="_blank" className="text-blue-500 underline" href={appEnv.url + '/' + (row.getValue("path") as TranslationField)[appEnv.locale]}>
|
|
{appEnv.url + '/' + (row.getValue("path") as TranslationField)[appEnv.locale]}
|
|
</a>)
|
|
) : (<p className="text-muted-foreground italic m-0">{useTrans('back.table_not_known')}</p>);
|
|
},
|
|
},
|
|
];
|
|
|
|
return (
|
|
<>
|
|
<h3 className="mt-5 mb-1 text-xl font-medium">{str(useTrans("validation.custom.documentTag.documents")).ucFirst().value()}</h3>
|
|
<DataTable
|
|
columns={documentColumns}
|
|
modelRoute={"documents"}
|
|
modelsPaginate={documents}
|
|
actions={[
|
|
Views.VISUALIZATION,
|
|
Views.EDITION
|
|
]}
|
|
/>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default AssociatedDocumentList;
|