134 lines
4.9 KiB
TypeScript
134 lines
4.9 KiB
TypeScript
// * Packages
|
|
import { usePage } from "@inertiajs/react";
|
|
import { route } from "ziggy-js";
|
|
import { ArrowLeftIcon } from "lucide-react";
|
|
// * Components shadcn
|
|
import { Badge } from "@/components/ui/badge";
|
|
// * Other
|
|
import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout";
|
|
import DetailsTable from "@/back/Components/Table/DetailsTable";
|
|
import ModelActions from "@/back/Components/ModelActions";
|
|
import ConfigDetails from "@/back/Components/PageConfigs/ConfigDetails";
|
|
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
|
|
import RenderTranslationCell from "@/back/Components/Table/RenderTranslationCell";
|
|
import { GetFormatedDate, GetTranslation, Views } from "@/lib/utils";
|
|
import { AppEnv, AuthProp, SingleResource } from "@/back/types/global";
|
|
import { ConfigField, PageConfigModel } from "@/back/types/dynamic-pages";
|
|
import { TranslationField } from "@/back/types/i18n";
|
|
import str from "@/hooks/use-string";
|
|
import useTrans from "@/hooks/use-translations";
|
|
|
|
const getColumns = (appEnv: AppEnv) => {
|
|
return [
|
|
{
|
|
accessorKey: "label",
|
|
header: str(GetTranslation("validation.custom.label"))
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: TranslationField }) => (
|
|
<RenderTranslationCell value={value} />
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "view",
|
|
header: str(GetTranslation("validation.custom.view"))
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: string | null }) => <code>{value}</code>,
|
|
},
|
|
{
|
|
accessorKey: "config",
|
|
header: str(GetTranslation("validation.custom.config"))
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: TranslationField<ConfigField[]> }) =>
|
|
value[appEnv.locale] ? (
|
|
<ConfigDetails config={value[appEnv.locale]} />
|
|
) : (
|
|
<p className="text-muted-foreground italic m-0">
|
|
{GetTranslation("back.table_not_known")}
|
|
</p>
|
|
),
|
|
},
|
|
{
|
|
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,
|
|
modelName,
|
|
}: {
|
|
data: SingleResource;
|
|
modelName: string;
|
|
}) {
|
|
const { auth, appEnv } = usePage().props as unknown as {
|
|
auth: AuthProp;
|
|
appEnv: AppEnv;
|
|
};
|
|
const { viewAny } = auth.policies.pageConfigs;
|
|
const pageConfigModel = data.data as PageConfigModel;
|
|
const actionModels = [Views.EDITION, Views.DUPLICATION, Views.ARCHIVATION];
|
|
const singularModelName = str(modelName).singular().value();
|
|
const transTitle = useTrans("crud.helpers.visualization_model", {
|
|
params: {
|
|
model: useTrans(`models.classes.${singularModelName}`, {
|
|
choice: 1,
|
|
}),
|
|
},
|
|
});
|
|
const columns = getColumns(appEnv);
|
|
|
|
const transCrudBackToList = useTrans("back.crud_back_to_list");
|
|
const beforeNode = () => {
|
|
return (
|
|
viewAny && (
|
|
<div className="flex justify-end items-center gap-x-1.5">
|
|
<BtnOptionnalLinkWithTooltip
|
|
link={route(`back.${modelName}.index`)}
|
|
content={<ArrowLeftIcon />}
|
|
tooltipContent={<p>{transCrudBackToList}</p>}
|
|
/>
|
|
</div>
|
|
)
|
|
);
|
|
};
|
|
|
|
return (
|
|
<AuthenticatedLayout title={transTitle} beforeNode={beforeNode()}>
|
|
<ModelActions
|
|
actions={actionModels}
|
|
modelRoute={modelName}
|
|
model={pageConfigModel}
|
|
modelUpdatedAt={pageConfigModel.updated_at.toString()}
|
|
/>
|
|
{/* @ts-expect-error Weird error type on cell. */}
|
|
<DetailsTable columns={columns} model={pageConfigModel} />
|
|
</AuthenticatedLayout>
|
|
);
|
|
}
|