121 lines
4.1 KiB
TypeScript
121 lines
4.1 KiB
TypeScript
// * Packages
|
|
import { Row } from "@tanstack/react-table";
|
|
import { Building2Icon, CheckIcon, XIcon } 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 { CompanyModel } from "@/back/types/others";
|
|
import { GetFormatedDate, GetTranslation, Views } from "@/lib/utils";
|
|
import useTrans from "@/hooks/use-translations";
|
|
import str from "@/hooks/use-string";
|
|
|
|
interface Props {
|
|
companies: Resource;
|
|
}
|
|
|
|
const getColumns = () => {
|
|
return [
|
|
{
|
|
accessorKey: "name",
|
|
header: ({ column }: { column: { id: string } }) => (
|
|
<DataTableFilterButton
|
|
label={str(
|
|
GetTranslation(`validation.attributes.${column.id}`),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
field={column.id}
|
|
/>
|
|
),
|
|
cell: ({ row }: { row: Row<CompanyModel> }) => {
|
|
return row.getValue("name");
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "published",
|
|
header: ({ column }: { column: { id: string } }) => (
|
|
<DataTableFilterButton
|
|
label={str(GetTranslation(`validation.custom.${column.id}`))
|
|
.ucFirst()
|
|
.value()}
|
|
field={column.id}
|
|
/>
|
|
),
|
|
cell: ({ row }: { row: Row<CompanyModel> }) => (
|
|
<Badge
|
|
variant="outline"
|
|
className={`border-0 ${
|
|
row.getValue("published")
|
|
? "bg-green-200 dark:bg-green-900"
|
|
: "bg-red-200 dark:bg-red-900"
|
|
}`}
|
|
>
|
|
{row.getValue("published") ? (
|
|
<CheckIcon size={15} className="mr-1" />
|
|
) : (
|
|
<XIcon size={15} className="mr-1" />
|
|
)}
|
|
{str(
|
|
GetTranslation(
|
|
row.getValue("published") ? "back.yes" : "back.no",
|
|
),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
</Badge>
|
|
),
|
|
},
|
|
{
|
|
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<CompanyModel> }) => (
|
|
<Badge variant="secondary">
|
|
{GetFormatedDate(row.getValue("updated_at"))}
|
|
</Badge>
|
|
),
|
|
},
|
|
];
|
|
};
|
|
|
|
export default function AssociatedCompaniesList(props: Props) {
|
|
const { companies } = props;
|
|
const columns = getColumns();
|
|
|
|
return (
|
|
<>
|
|
<h3 className="text-2xl font-semibold leading-none tracking-tight flex flex-row w-full items-start my-4">
|
|
<Building2Icon className="me-2" />
|
|
{str(
|
|
useTrans("back.associated_model", {
|
|
params: {
|
|
model: useTrans("models.classes.company", {
|
|
choice: 2,
|
|
}),
|
|
},
|
|
choice: 2,
|
|
}),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
</h3>
|
|
<DataTable
|
|
columns={columns}
|
|
modelRoute="companies"
|
|
modelsPaginate={companies}
|
|
actions={[Views.VISUALIZATION, Views.EDITION]}
|
|
/>
|
|
</>
|
|
);
|
|
}
|