Merge branch 'fix/goToFrontView' into 'develop'
fix: 🐛 fix GoToFrontView in dynamicpage form
See merge request ldc-web/projets/ldc!135
This commit is contained in:
commit
706c129f44
2 changed files with 9 additions and 61 deletions
|
|
@ -154,6 +154,7 @@ class DynamicPageController extends Controller
|
|||
'enumElementPosition' => ElementPositionEnum::toArray(),
|
||||
'enumContactFormType' => ContactFormType::toArray(),
|
||||
'modelName' => $this->modelName,
|
||||
'dynamicPageUrl' => DynamicPage::getAccessModel($dynamic_page->id),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import {
|
|||
ShieldAlertIcon,
|
||||
} from "lucide-react";
|
||||
import { route } from "ziggy-js";
|
||||
import { useState } from "react";
|
||||
// * Components shadcn
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
|
|
@ -58,15 +57,15 @@ export default function Form({
|
|||
action: string;
|
||||
method: number;
|
||||
}) {
|
||||
|
||||
/** Global */
|
||||
const { locale } = usePage().props.appEnv as AppEnv;
|
||||
const { locale, url } = usePage().props.appEnv as AppEnv;
|
||||
const dynamicPageUrl = usePage().props.dynamicPageUrl as string;
|
||||
const userModel = (usePage().props.auth as AuthProp).user;
|
||||
const enumUserRole = usePage().props.enumUserRole as LaravelEnum;
|
||||
const enumDynamicPageStatus = usePage().props
|
||||
.enumDynamicPageStatus as LaravelEnum;
|
||||
const dynamicPageModels = usePage().props
|
||||
.dynamicPageModels as DynamicPageModel[];
|
||||
const [selectedGroup, setSelectedGroup] = useState<string | null>(null);
|
||||
|
||||
const isConceptor = userModel.role === enumUserRole.conceptor.value;
|
||||
|
||||
const pageConfigModels = usePage().props
|
||||
|
|
@ -137,7 +136,7 @@ export default function Form({
|
|||
|
||||
const getConfig = (id: number) =>
|
||||
configOptions.find((objet) => objet.id === id)?.config[
|
||||
locale
|
||||
locale
|
||||
] as ConfigField[];
|
||||
|
||||
/** Form section */
|
||||
|
|
@ -163,43 +162,6 @@ export default function Form({
|
|||
data,
|
||||
});
|
||||
|
||||
function getFullSlugPath(
|
||||
targetModels: DynamicPageModel[],
|
||||
currentSelectedGroup: string | null,
|
||||
currentLocale: string = "fr",
|
||||
): string | null {
|
||||
if (!currentSelectedGroup) return null;
|
||||
|
||||
// Trouver le modèle sélectionné à partir de son title
|
||||
const current = targetModels.find(
|
||||
(targetModel) =>
|
||||
targetModel.title[currentLocale]?.toLowerCase() ===
|
||||
currentSelectedGroup.toLowerCase(),
|
||||
);
|
||||
|
||||
if (!current) return null;
|
||||
|
||||
// Fonction récursive pour reconstruire le chemin
|
||||
const buildPath = (modelParent: DynamicPageModel): string => {
|
||||
const parent = modelParent.page_id
|
||||
? targetModels.find(
|
||||
(targetModel) => targetModel.id === modelParent.page_id,
|
||||
)
|
||||
: null;
|
||||
|
||||
const currentTranslatedModelSlug =
|
||||
modelParent.slug[currentLocale] ?? "";
|
||||
|
||||
if (!parent) return currentTranslatedModelSlug;
|
||||
|
||||
return [buildPath(parent), currentTranslatedModelSlug]
|
||||
.filter(Boolean)
|
||||
.join("/");
|
||||
};
|
||||
|
||||
return buildPath(current);
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={submit}>
|
||||
<InputError all />
|
||||
|
|
@ -252,7 +214,6 @@ export default function Form({
|
|||
name="isRoot"
|
||||
checked={data.isRoot}
|
||||
setData={(name, value) => {
|
||||
setSelectedGroup(null);
|
||||
setData("page_id", null);
|
||||
setData("slug", "");
|
||||
// @ts-expect-error TS2345: 'name' type is dynamic, TypeScript cannot infer the correct key
|
||||
|
|
@ -277,15 +238,6 @@ export default function Form({
|
|||
exclude={model?.id}
|
||||
required={false}
|
||||
setData={setData}
|
||||
onModelChange={(value) =>
|
||||
setSelectedGroup(
|
||||
value && value.length > 0
|
||||
? (value[0] as DynamicPageModel).title[
|
||||
locale
|
||||
]
|
||||
: null,
|
||||
)
|
||||
}
|
||||
disabled={data.isRoot}
|
||||
/>
|
||||
<Slugifycator
|
||||
|
|
@ -301,14 +253,9 @@ export default function Form({
|
|||
modelName={useTrans(`models.classes.${modelName}`, {
|
||||
choice: 1,
|
||||
})}
|
||||
pathField={!data.isRoot ? data.slug : ""}
|
||||
additionalGroupPath={
|
||||
getFullSlugPath(
|
||||
dynamicPageModels,
|
||||
selectedGroup,
|
||||
locale,
|
||||
) ?? undefined
|
||||
}
|
||||
pathField={data.isRoot ? "" : dynamicPageUrl
|
||||
.replace(url, "")
|
||||
.replace(/^\/+/, "")}
|
||||
isAvailable={
|
||||
model?.status ===
|
||||
enumDynamicPageStatus.published.value
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue