import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { AppEnv, Model } from "../types/global"; import useTrans from "@/hooks/use-translations"; import { usePage } from "@inertiajs/react"; import { ExternalLinkIcon } from "lucide-react"; import str from "@/hooks/use-string"; interface Props { /** Current Model being edited */ model?: Model; /** Model Name used to translate the helper */ modelName: string; /** Field data to build path */ pathField: string; /** additionnal segment used in the url */ additionalGroupPath?: string; /** Does the actual page status available in front */ isAvailable: boolean; } const GoToFrontView = (props: Props) => { const { model, modelName, pathField, additionalGroupPath = null, isAvailable = false } = props; if(!model) return; const { locale, url } = usePage().props.appEnv as AppEnv; const anchorAccessPage = useTrans("back.access_model", { params: { model: useTrans(`models.classes.${modelName}`, { choice: 1 }), }, }); const definitivePath = [ url + (locale === "fr" ? '' : '/' + locale), additionalGroupPath, pathField, ] .filter(Boolean) .join("/"); return ( {model && isAvailable ? ( <> {str(useTrans('back.access_to_front_page')).ucFirst().value()} {definitivePath}{" "} {anchorAccessPage} ) : ( <> {str(useTrans("back.access_to_front_page_when_published")).ucFirst().value()}: {definitivePath} )} ) } export default GoToFrontView;