206 lines
8 KiB
TypeScript
206 lines
8 KiB
TypeScript
// * Packages
|
|
import { ArrowLeft, 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";
|
|
import BtnTooltip from "@/back/Components/BtnTooltip";
|
|
|
|
export default function Show({ data }: { data: SingleResource }) {
|
|
const { auth, appEnv } = usePage().props as unknown as {
|
|
auth: AuthProp;
|
|
appEnv: AppEnv;
|
|
};
|
|
const { viewAny } = auth.policies.dynamicPages;
|
|
const dynamicPageModel = data.data as DynamicPageModel;
|
|
const enumDynamicPageStatus = usePage().props.enumDynamicPageStatus as LaravelEnum;
|
|
const actionModels = [
|
|
Views.EDITION,
|
|
Views.DUPLICATION,
|
|
Views.ARCHIVATION,
|
|
];
|
|
const columns = [
|
|
{
|
|
accessorKey: "title",
|
|
header: str(useTrans("validation.attributes.title")).ucFirst().value(),
|
|
cell: ({ value }: { value: TranslationField }) => (
|
|
<p>{value[appEnv.locale]}</p>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "config",
|
|
header: str(useTrans("validation.custom.config")).ucFirst().value(),
|
|
cell: ({ value }: { value: PageConfigModel }) => auth.policies.pageConfigs.viewAny ? (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="secondary"
|
|
type="button"
|
|
asChild
|
|
>
|
|
<Link href={route('back.page-configs.show', value)}>
|
|
<Cog />
|
|
<span>{value.label[appEnv.locale]}</span>
|
|
</Link>
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>
|
|
<p>{useTrans("back.access_model", {
|
|
params: {
|
|
model: useTrans('models.classes.page-config', { choice: 1 })
|
|
}
|
|
})}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
) : <span>{value.label[appEnv.locale]}</span>
|
|
},
|
|
{
|
|
accessorKey: "content",
|
|
header: str(useTrans("validation.attributes.content")).ucFirst().value(),
|
|
cell: ({ value }: { value: TranslationField<object | string> }) => {
|
|
if (typeof value[appEnv.locale] === "object") {
|
|
return <Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead>
|
|
{str(useTrans("validation.custom.reference")).ucFirst().value()}
|
|
</TableHead>
|
|
<TableHead>
|
|
{str(useTrans("validation.attributes.content")).ucFirst().value()}
|
|
</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{Object.entries(value[appEnv.locale]).map(
|
|
([id, field]) => (
|
|
<TableRow key={id}>
|
|
<TableCell>
|
|
{id}
|
|
</TableCell>
|
|
<TableCell>
|
|
{field}
|
|
</TableCell>
|
|
</TableRow>
|
|
),
|
|
)}
|
|
</TableBody>
|
|
</Table>
|
|
} else if (typeof value[appEnv.locale] === "string" && String(value[appEnv.locale]).trim().length > 0) {
|
|
return <p>{String(value[appEnv.locale])}</p>
|
|
};
|
|
return (
|
|
<span className="text-sm italic text-muted-foreground">
|
|
{tableNotKnownTrans}
|
|
</span>
|
|
);
|
|
}
|
|
},
|
|
{
|
|
accessorKey: "status",
|
|
header: str(useTrans(`validation.custom.status`)).ucFirst().value(),
|
|
cell: ({ value }: { value: number }) => (
|
|
<p>
|
|
{str(String(Object.values(enumDynamicPageStatus).find(
|
|
(status) => status.value === value,
|
|
)?.label)).ucFirst().value()}
|
|
</p>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "isLocked",
|
|
header: str(useTrans("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(useTrans(value ? "back.yes" : "back.no")).ucFirst().value()}
|
|
</Badge>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "created_at",
|
|
header: str(useTrans("validation.attributes.created_at")).ucFirst().value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<Badge variant="secondary">{useFormatedDate(value)}</Badge>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "updated_at",
|
|
header: str(useTrans("validation.attributes.updated_at")).ucFirst().value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<Badge variant="secondary">{useFormatedDate(value)}</Badge>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "deleted_at",
|
|
header: str(useTrans("validation.attributes.deleted_at")).ucFirst().value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<Badge variant="secondary">{useFormatedDate(value)}</Badge>
|
|
),
|
|
},
|
|
];
|
|
const tableNotKnownTrans = useTrans("back.table_not_known");
|
|
|
|
const beforeNode = () => {
|
|
return viewAny && (
|
|
<div className="flex justify-end items-center gap-x-1.5">
|
|
<BtnTooltip
|
|
link={route("back.dynamic-pages.index")}
|
|
content={<p>{useTrans("back.crud_back_to_list")}</p>}
|
|
icon={<ArrowLeft />}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
return (
|
|
<AuthenticatedLayout
|
|
title={useTrans("crud.helpers.visualization_model", {
|
|
params: { model: useTrans("models.classes.dynamic-page", { choice: 1 }) },
|
|
})}
|
|
beforeNode={beforeNode()}
|
|
>
|
|
<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>
|
|
);
|
|
}
|