99 lines
3.2 KiB
TypeScript
99 lines
3.2 KiB
TypeScript
// * Packages
|
|
import { Row } from "@tanstack/react-table";
|
|
// * Components shadcn
|
|
import { Badge } from "@/components/ui/badge";
|
|
// * Other
|
|
import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout";
|
|
import DataTable from "@/back/Components/Table/DataTable";
|
|
import { LaravelEnum, Resource } from "@/back/types/global";
|
|
import { ContactCountModel } from "@/back/types/others";
|
|
import str from "@/hooks/use-string";
|
|
import useTrans from "@/hooks/use-translations";
|
|
import { GetFormatedDate, GetTranslation } from "@/lib/utils";
|
|
|
|
const getColumns = (contactFormType: LaravelEnum) => {
|
|
return [
|
|
{
|
|
accessorKey: "type",
|
|
header: ({ column }: { column: { id: string } }) => (
|
|
<p className="text-center">
|
|
{str(
|
|
GetTranslation(
|
|
`validation.custom.contact_count.${column.id}`,
|
|
),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
</p>
|
|
),
|
|
cell: ({ row }: { row: Row<ContactCountModel> }) => {
|
|
const type = Object.values(contactFormType).find(
|
|
(item) => item.value === row.getValue("type"),
|
|
);
|
|
if (!type) return "";
|
|
return (
|
|
<p className="text-muted-foreground italic m-0">
|
|
{str(type.label).ucFirst().value()}
|
|
</p>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "submissions",
|
|
header: ({ column }: { column: { id: string } }) => (
|
|
<p className="text-center">
|
|
{str(
|
|
GetTranslation(
|
|
`validation.custom.contact_count.${column.id}`,
|
|
),
|
|
)
|
|
.ucFirst()
|
|
.value()}
|
|
</p>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "updated_at",
|
|
header: ({ column }: { column: { id: string } }) => (
|
|
<p className="text-center">
|
|
{str(GetTranslation(`validation.attributes.${column.id}`))
|
|
.ucFirst()
|
|
.value()}
|
|
</p>
|
|
),
|
|
cell: ({ row }: { row: Row<ContactCountModel> }) => (
|
|
<Badge variant="secondary">
|
|
{GetFormatedDate(row.getValue("updated_at"))}
|
|
</Badge>
|
|
),
|
|
},
|
|
];
|
|
};
|
|
|
|
export default function Index({
|
|
contactCountModels,
|
|
contactFormType,
|
|
modelName,
|
|
}: {
|
|
contactCountModels: Resource;
|
|
contactFormType: LaravelEnum;
|
|
modelName: string;
|
|
}) {
|
|
const columns = getColumns(contactFormType);
|
|
|
|
const transModel = useTrans(
|
|
`models.classes.${str(modelName).singular().value()}`,
|
|
);
|
|
const transTitle = str(transModel).ucFirst().value();
|
|
|
|
return (
|
|
<AuthenticatedLayout title={transTitle}>
|
|
<DataTable
|
|
actions={[]}
|
|
columns={columns}
|
|
modelRoute={modelName}
|
|
modelsPaginate={contactCountModels}
|
|
/>
|
|
</AuthenticatedLayout>
|
|
);
|
|
}
|