- Updated translation utility to improve consistency and reduce redundancy. - Removed deprecated useTrans hook and related code. - Introduced a new Zustand store for managing translations and locale settings. - Cleaned up unused hooks and files related to localization.
142 lines
4.4 KiB
TypeScript
142 lines
4.4 KiB
TypeScript
import { usePage } from "@inertiajs/react";
|
|
import { ArrowLeftIcon } from "lucide-react";
|
|
|
|
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
|
|
import ModelActions from "@/back/Components/ModelActions";
|
|
import ConfigDetails from "@/back/Components/PageConfigs/ConfigDetails";
|
|
import DetailsTable from "@/back/Components/Table/DetailsTable";
|
|
import RenderTranslationCell from "@/back/Components/Table/RenderTranslationCell";
|
|
import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout";
|
|
import { Views } from "@/back/lib/actions";
|
|
import type { ConfigField, PageConfigModel } from "@/back/types/dynamic-pages";
|
|
import type {
|
|
AuthProp,
|
|
ConfigBackend,
|
|
SingleResource,
|
|
} from "@/back/types/global";
|
|
import type { TranslationField } from "@/back/types/i18n";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import str from "@/hooks/use-string";
|
|
import trans from "@/hooks/use-translations";
|
|
import { formatDate } from "@/lib/utils";
|
|
|
|
const getColumns = (appEnv: AppEnv) => {
|
|
return [
|
|
{
|
|
accessorKey: "label",
|
|
header: str(trans("uwil-dynamic-pages::trans.attributes.label"))
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: TranslationField }) => (
|
|
<RenderTranslationCell value={value} />
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "view",
|
|
header: str(trans("uwil-dynamic-pages::trans.attributes.view"))
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: string | null }) => <code>{value}</code>,
|
|
},
|
|
{
|
|
accessorKey: "config",
|
|
header: str(trans("uwil-dynamic-pages::trans.attributes.config"))
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({
|
|
value,
|
|
}: {
|
|
value: TranslationField<ConfigField[] | undefined>;
|
|
}) => {
|
|
const config = value[appEnv.locale];
|
|
return config ? (
|
|
<ConfigDetails config={config} />
|
|
) : (
|
|
<p className="text-muted-foreground italic m-0">
|
|
{trans("uwil-backend::back.table_not_known")}
|
|
</p>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "created_at",
|
|
header: str(trans("uwil-dynamic-pages::trans.attributes.created_at"))
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<Badge variant="secondary">{formatDate(value)}</Badge>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "updated_at",
|
|
header: str(trans("uwil-dynamic-pages::trans.attributes.updated_at"))
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<Badge variant="secondary">{formatDate(value)}</Badge>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "deleted_at",
|
|
header: str(trans("uwil-dynamic-pages::trans.attributes.deleted_at"))
|
|
.ucFirst()
|
|
.value(),
|
|
cell: ({ value }: { value: string }) => (
|
|
<Badge variant="secondary">{formatDate(value)}</Badge>
|
|
),
|
|
},
|
|
];
|
|
};
|
|
|
|
export default function Show({
|
|
data,
|
|
modelName,
|
|
}: Readonly<{
|
|
data: SingleResource;
|
|
modelName: string;
|
|
}>) {
|
|
const { auth, appEnv, configBackend } = usePage().props as unknown as {
|
|
auth: AuthProp;
|
|
appEnv: AppEnv;
|
|
configBackend: ConfigBackend;
|
|
};
|
|
const { viewAny } = auth.policies.pageConfigs;
|
|
const pageConfigModel = data.data as PageConfigModel;
|
|
const actionModels = [Views.EDITION, Views.DUPLICATION, Views.ARCHIVATION];
|
|
const transTitle = trans("uwil-backend::crud.helpers.visualization_model", {
|
|
params: {
|
|
model: trans(`uwil-dynamic-pages::models.classes.${modelName}`, {
|
|
choice: 1,
|
|
}),
|
|
},
|
|
});
|
|
const columns = getColumns(appEnv);
|
|
|
|
const transCrudBackToList = trans("uwil-backend::back.crud_back_to_list");
|
|
const beforeNode = () => {
|
|
return (
|
|
viewAny && (
|
|
<div className="flex justify-end items-center gap-x-1.5">
|
|
<BtnOptionnalLinkWithTooltip
|
|
link={route(`${configBackend.routes.name}${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>
|
|
);
|
|
}
|