190 lines
7.4 KiB
TypeScript
190 lines
7.4 KiB
TypeScript
// * Packages
|
|
import { CheckIcon, Cog, XIcon } from "lucide-react";
|
|
import { usePage, Link } from "@inertiajs/react";
|
|
import { route } from "ziggy-js";
|
|
// * Components shadcn
|
|
import { Badge } from "@/components/ui/badge";
|
|
import {
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
} from "@/components/ui/table";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from "@/components/ui/tooltip";
|
|
// * Other
|
|
import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout";
|
|
import DetailsTable from "@/back/Components/Table/DetailsTable";
|
|
import ModelActions from "@/back/Components/ModelActions";
|
|
import { Views } from "@/lib/utils";
|
|
import { useFormatedDate } from "@/hooks/use-formated-value";
|
|
import {
|
|
AppEnv,
|
|
AuthProp,
|
|
DynamicPageModel,
|
|
LaravelEnum,
|
|
PageConfigModel,
|
|
SingleResource,
|
|
TranslationField,
|
|
} from "@/back/types/global";
|
|
import str from "@/hooks/use-string";
|
|
import useTrans from "@/hooks/use-translations";
|
|
|
|
const getColumns = (statusEnum: LaravelEnum) => {
|
|
const { locale } = usePage().props.appEnv as AppEnv;
|
|
const GetTranslation = (string: string) => {
|
|
return useTrans(string);
|
|
};
|
|
const GetFormatedDate = (date: string) => {
|
|
return useFormatedDate(date);
|
|
};
|
|
return [
|
|
{
|
|
accessorKey: "title",
|
|
header: str(GetTranslation("validation.attributes.title")).ucFirst().value(),
|
|
cell: ({ value }: { value: TranslationField }) => (
|
|
<p>{value[locale]}</p>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "config",
|
|
header: str(GetTranslation("validation.custom.config")).ucFirst().value(),
|
|
cell: ({ value }: { value: PageConfigModel }) => (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="secondary"
|
|
type="button"
|
|
asChild
|
|
>
|
|
<Link href={route('back.page-configs.show', value)}>
|
|
<Cog />
|
|
<span>{value.label[locale]}</span>
|
|
</Link>
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>
|
|
<p>{useTrans("back.access_model", {
|
|
params: {
|
|
model: useTrans('models.classes.page-config', { choice: 1 })
|
|
}
|
|
})}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
)
|
|
},
|
|
{
|
|
accessorKey: "content",
|
|
header: str(GetTranslation("validation.attributes.content")).ucFirst().value(),
|
|
cell: ({ value }: { value: TranslationField<object | string | boolean | number> }) => {
|
|
return typeof value[locale] === "object" ? (
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead>
|
|
{str(GetTranslation("validation.custom.reference")).ucFirst().value()}
|
|
</TableHead>
|
|
<TableHead>
|
|
{str(GetTranslation("validation.attributes.content")).ucFirst().value()}
|
|
</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{Object.entries(value[locale]).map(
|
|
([id, field]) => (
|
|
<TableRow key={id}>
|
|
<TableCell>
|
|
{id}
|
|
</TableCell>
|
|
<TableCell>
|
|
{field}
|
|
</TableCell>
|
|
</TableRow>
|
|
),
|
|
)}
|
|
</TableBody>
|
|
</Table>
|
|
) : (
|
|
<p>{value[locale]}</p>
|
|
);
|
|
}
|
|
},
|
|
{
|
|
accessorKey: "status",
|
|
header: str(GetTranslation(`validation.custom.status`)).ucFirst().value(),
|
|
cell: ({ value }: { value: number }) => (
|
|
<p>
|
|
{str(String(Object.values(statusEnum).find(
|
|
(status) => status.value === value,
|
|
)?.label)).ucFirst().value()}
|
|
</p>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "isLocked",
|
|
header: str(GetTranslation("validation.custom.locked")).ucFirst().value(),
|
|
cell: ({ value }: { value: boolean }) => (
|
|
<Badge
|
|
variant="outline"
|
|
className={`border-0 ${value ? "bg-green-200 dark:bg-green-900" : "bg-red-200 dark:bg-red-900"}`}
|
|
>
|
|
{ value ? <CheckIcon size={15} className="mr-1" /> : <XIcon size={15} className="mr-1" /> }
|
|
{str(GetTranslation(value ? "back.yes" : "back.no")).ucFirst().value()}
|
|
</Badge>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "created_at",
|
|
header: str(GetTranslation("validation.attributes.created_at")).ucFirst().value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<Badge variant="secondary">{GetFormatedDate(value)}</Badge>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "updated_at",
|
|
header: str(GetTranslation("validation.attributes.updated_at")).ucFirst().value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<Badge variant="secondary">{GetFormatedDate(value)}</Badge>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "deleted_at",
|
|
header: str(GetTranslation("validation.attributes.deleted_at")).ucFirst().value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<Badge variant="secondary">{GetFormatedDate(value)}</Badge>
|
|
),
|
|
},
|
|
];
|
|
};
|
|
|
|
export default function Show({ data }: { data: SingleResource }) {
|
|
const auth = usePage().props.auth as AuthProp;
|
|
const { viewAny } = auth.policies.users;
|
|
const dynamicPageModel = data.data as DynamicPageModel;
|
|
const enumDynamicPageStatus = usePage().props.enumDynamicPageStatus as LaravelEnum;
|
|
const actionModels = [Views.EDITION, Views.DUPLICATION, Views.DELETION];
|
|
const columns = getColumns(enumDynamicPageStatus);
|
|
return (
|
|
<AuthenticatedLayout
|
|
title={useTrans("crud.helpers.details_model", {
|
|
params: { model: useTrans("models.classes.dynamic-page", { choice: 1 }) },
|
|
})}
|
|
linkBefore={viewAny ? route("back.dynamic-pages.index") : undefined}
|
|
>
|
|
<ModelActions
|
|
actions={actionModels}
|
|
modelRoute="dynamic-pages"
|
|
model={dynamicPageModel}
|
|
modelUpdatedAt={dynamicPageModel.updated_at.toString()}
|
|
/>
|
|
{/* @ts-expect-error Weird error type on cell. */}
|
|
<DetailsTable columns={columns} model={dynamicPageModel} />
|
|
</AuthenticatedLayout>
|
|
);
|
|
}
|