118 lines
3.9 KiB
TypeScript
118 lines
3.9 KiB
TypeScript
// * Packages
|
|
import { Row } from "@tanstack/react-table";
|
|
import { NewspaperIcon } from "lucide-react";
|
|
// * Components shadcn
|
|
import { Badge } from "@/components/ui/badge";
|
|
// * Other
|
|
import DataTable from "@/back/Components/Table/DataTable";
|
|
import DataTableFilterButton from "@/back/Components/Table/DataTableFilterButton";
|
|
import { Resource } from "@/back/types/global";
|
|
import { NewsModel } from "@/back/types/others";
|
|
import NewsStatusBadge from "@/back/Components/News/NewsStatusBadge";
|
|
import RenderTranslationCell from "@/back/Components/Table/RenderTranslationCell";
|
|
import { Views } from "@/lib/utils";
|
|
import { useFormatedDate } from "@/hooks/use-formated-value";
|
|
import useTrans, { UseTransOptions } from "@/hooks/use-translations";
|
|
import str from "@/hooks/use-string";
|
|
|
|
interface Props {
|
|
news: Resource;
|
|
}
|
|
|
|
const getColumns = () => {
|
|
const GetTranslation = (name: string, options?: UseTransOptions) => {
|
|
return useTrans(name, options);
|
|
};
|
|
const GetFormatedDate = (
|
|
date: string,
|
|
timezone?: string,
|
|
time?: boolean,
|
|
) => {
|
|
return useFormatedDate(date, timezone, time);
|
|
};
|
|
return [
|
|
{
|
|
accessorKey: "title",
|
|
header: ({ column }: { column: { id: string } }) => (
|
|
<DataTableFilterButton
|
|
label={str(
|
|
GetTranslation(`validation.attributes.${column.id}`),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
field={column.id}
|
|
/>
|
|
),
|
|
cell: ({ row }: { row: Row<NewsModel> }) => (
|
|
<RenderTranslationCell value={row.getValue("title")} />
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "status",
|
|
header: ({ column }: { column: { id: string } }) => (
|
|
<DataTableFilterButton
|
|
label={str(GetTranslation(`validation.custom.${column.id}`))
|
|
.ucFirst()
|
|
.value()}
|
|
field={column.id}
|
|
/>
|
|
),
|
|
cell: ({ row }: { row: Row<NewsModel> }) => {
|
|
return (
|
|
<NewsStatusBadge value={Number(row.getValue("status"))} />
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "updated_at",
|
|
header: ({ column }: { column: { id: string } }) => (
|
|
<DataTableFilterButton
|
|
label={str(
|
|
GetTranslation(`validation.attributes.${column.id}`),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
field={column.id}
|
|
/>
|
|
),
|
|
cell: ({ row }: { row: Row<NewsModel> }) => (
|
|
<Badge variant="secondary">
|
|
{GetFormatedDate(row.getValue("updated_at"))}
|
|
</Badge>
|
|
),
|
|
},
|
|
];
|
|
};
|
|
function AssociatedNewsList(props: Props) {
|
|
const { news } = props;
|
|
|
|
const columns = getColumns();
|
|
|
|
return (
|
|
<>
|
|
<h3 className="text-2xl font-semibold leading-none tracking-tight flex flex-row w-full items-start my-4">
|
|
<NewspaperIcon className="me-2" />
|
|
{str(
|
|
useTrans("back.associated_model", {
|
|
params: {
|
|
model: useTrans("models.classes.news", {
|
|
choice: 2,
|
|
}),
|
|
},
|
|
choice: 2,
|
|
}),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
</h3>
|
|
<DataTable
|
|
columns={columns}
|
|
modelRoute="news"
|
|
modelsPaginate={news}
|
|
actions={[Views.VISUALIZATION, Views.EDITION]}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default AssociatedNewsList;
|