ldc-ovoteam/resources/ts/back/Components/Layout/Sidebar/Links/DynamicPages.tsx

87 lines
2.7 KiB
TypeScript

// * Packages
import { Link } from "@inertiajs/react";
import { StickyNoteIcon } from "lucide-react";
import { route } from "ziggy-js";
// * Components shadcn
import { Button } from "@/components/ui/button";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
// * Other
import {
filterActions,
NavListLinksProps,
} from "@/back/Components/Layout/Sidebar/AppSidebar";
import { SidebarGroupLink } from "@/back/Components/Layout/Sidebar/SidebarRegistry";
import Views from "@/back/lib/actions";
import str from "@/hooks/use-string";
import useTrans from "@/hooks/use-translations";
import { GetTranslation } from "@/lib/utils";
import container from "@/services/container";
export default function DynamicPages(): SidebarGroupLink {
const authService = container.resolve("authService");
const modelName = "dynamic-pages";
// Translations.
const transDynamicPages = GetTranslation(
`uwil-dynamic-pages::models.classes.${modelName}`,
{
choice: 2,
},
);
const transCreate = str(
useTrans(`uwil-backend::crud.actions.${Views.CREATION.label}`),
)
.ucFirst()
.value();
const transArchives = str(useTrans("uwil-backend::back.archives"))
.ucFirst()
.value();
const link: NavListLinksProps = {
title: str(transDynamicPages).ucFirst().value(),
model: modelName,
icon: StickyNoteIcon,
show: authService.canGlobal(
"viewAny",
String.raw`Uwil\LaravelDynamicPages\Models\DynamicPage`,
),
actions: (model: string) =>
filterActions({
model,
items: [
authService.canGlobal(
"create",
String.raw`Uwil\LaravelDynamicPages\Models\DynamicPage`,
) && (
<DropdownMenuItem key="create" className="p-0">
<Button variant="ghost" asChild>
<Link href={route(`back.${model}.create`)} className="w-full">
{/* eslint-disable-next-line react/jsx-pascal-case */}
<Views.CREATION.icon />
{transCreate}
</Link>
</Button>
</DropdownMenuItem>
),
authService.canGlobal(
"viewTrash",
String.raw`Uwil\LaravelDynamicPages\Models\DynamicPage`,
) && (
<DropdownMenuItem className="p-0">
<Button variant="ghost" asChild>
<Link href={route(`back.${model}.trash`)} className="w-full">
{/* eslint-disable-next-line react/jsx-pascal-case */}
<Views.ARCHIVATION.icon />
{transArchives}
</Link>
</Button>
</DropdownMenuItem>
),
],
}),
};
return { link, group: "pages" };
}