// * Packages import { usePage } from "@inertiajs/react"; import { ExternalLinkIcon } from "lucide-react"; // * Components shadcn import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; // * Other import { AppEnv } from "@/back/types/global"; import useTrans from "@/hooks/use-translations"; import str from "@/hooks/use-string"; import { cn } from "@/lib/utils"; interface GoToFrontViewProps { /** Model Name used to translate the helper */ modelName: string; /** Field data to build path */ pathField: string; /** Additionnal segment used in the url */ additionalGroupPath?: string|null; /** Does the actual page status available in front */ isAvailable?: boolean; /** Set visually in column */ isColumn?: boolean, /** Add locale to the url */ addLocale?: boolean, } export default function GoToFrontView({ modelName, pathField, additionalGroupPath = null, isAvailable = false, isColumn = false, addLocale = true, }: GoToFrontViewProps) { const { locale, url } = usePage().props.appEnv as AppEnv; const anchorAccessPage = useTrans("back.access_model", { params: { model: modelName, }, }); const cleanUrl = url.endsWith("/") ? url.slice(0, -1) : url; const definitivePath = [ cleanUrl + (addLocale ? (locale === "fr" ? '' : '/' + locale) : ''), additionalGroupPath, pathField, ] .filter(Boolean) .join("/"); return ( {isAvailable ? ( <> {str(useTrans('back.access_to_front_page', { params: { model: modelName, }, })).ucFirst().value()}

{definitivePath}

{anchorAccessPage}
) : ( <> {str(useTrans("back.access_to_front_page_when_published", { params: { model: modelName, }, })).ucFirst().value()}: {definitivePath} )}
) }