From a0c0f7965a6c99ed258b55f5c4142018dcb1e360 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Fri, 5 Jun 2026 12:00:58 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20move=20backend=20config?= =?UTF-8?q?=20routes=20out=20of=20appEnv=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ts/back/Components/ApplicationLogo.tsx | 4 +- .../ts/back/Components/BtnResetPassword.tsx | 8 +- .../back/Components/Filters/SwitchFilter.tsx | 7 +- .../back/Components/Inputs/ImageCropper.tsx | 4 +- .../ts/back/Components/Inputs/ModelSelect.tsx | 7 +- .../ts/back/Components/Inputs/MultiSelect.tsx | 2 +- .../Wysiwyg/Extensions/Image/ImageButton.tsx | 10 +- .../Wysiwyg/Extensions/Link/LinkButton.tsx | 5 +- .../Inputs/Wysiwyg/SimpleWysiwyg.tsx | 5 +- .../Components/Inputs/Wysiwyg/Toolbar.tsx | 9 +- .../ts/back/Components/Layout/AppHeader.tsx | 5 +- .../Layout/Settings/AppSettings.tsx | 20 ++-- .../Layout/Settings/Sections/Languages.tsx | 9 +- .../Layout/Settings/SettingRegistry.tsx | 15 ++- .../Components/Layout/Sidebar/AppSidebar.tsx | 26 ++--- .../Layout/Sidebar/Links/Brands.tsx | 9 +- .../Layout/Sidebar/Links/InvoiceCompanies.tsx | 9 +- .../Layout/Sidebar/Links/InvoicePackages.tsx | 9 +- .../Layout/Sidebar/Links/Notices.tsx | 9 +- .../Components/Layout/Sidebar/Links/Sites.tsx | 9 +- .../Components/Layout/Sidebar/Links/Users.tsx | 7 +- .../Layout/Sidebar/SidebarRegistry.tsx | 17 ++-- resources/ts/back/Components/ModelActions.tsx | 14 ++- .../back/Components/Table/DataTableSearch.tsx | 2 - .../ts/back/Pages/ActivityLogs/Index.tsx | 28 +++--- resources/ts/back/Pages/ActivityLogs/Show.tsx | 21 ++-- .../ts/back/Pages/Auth/ForgotPassword.tsx | 5 +- resources/ts/back/Pages/Auth/Login.tsx | 12 ++- .../ts/back/Pages/Auth/ResetPassword.tsx | 5 +- resources/ts/back/Pages/Brands/Create.tsx | 6 +- resources/ts/back/Pages/Brands/Edit.tsx | 6 +- resources/ts/back/Pages/Brands/Index.tsx | 9 +- resources/ts/back/Pages/Brands/Show.tsx | 20 ++-- resources/ts/back/Pages/Errors/Default.tsx | 5 +- .../ts/back/Pages/InvoiceCompanies/Create.tsx | 6 +- .../ts/back/Pages/InvoiceCompanies/Edit.tsx | 6 +- .../ts/back/Pages/InvoiceCompanies/Index.tsx | 9 +- .../ts/back/Pages/InvoiceCompanies/Show.tsx | 10 +- .../ts/back/Pages/InvoicePackages/Create.tsx | 6 +- .../ts/back/Pages/InvoicePackages/Edit.tsx | 6 +- .../ts/back/Pages/InvoicePackages/Index.tsx | 9 +- .../ts/back/Pages/InvoicePackages/Show.tsx | 10 +- resources/ts/back/Pages/Notices/Create.tsx | 6 +- resources/ts/back/Pages/Notices/Edit.tsx | 6 +- resources/ts/back/Pages/Notices/Index.tsx | 11 ++- resources/ts/back/Pages/Notices/Show.tsx | 12 ++- resources/ts/back/Pages/Sites/Create.tsx | 6 +- resources/ts/back/Pages/Sites/Edit.tsx | 6 +- resources/ts/back/Pages/Sites/Index.tsx | 9 +- resources/ts/back/Pages/Sites/Show.tsx | 98 +++++-------------- resources/ts/back/Pages/Users/Create.tsx | 11 ++- resources/ts/back/Pages/Users/Edit.tsx | 11 ++- resources/ts/back/Pages/Users/Index.tsx | 14 ++- resources/ts/back/Pages/Users/Show.tsx | 29 ++++-- resources/ts/back/hooks/use-crud-submit.tsx | 16 ++- resources/ts/back/types/global.d.ts | 8 ++ 56 files changed, 347 insertions(+), 296 deletions(-) diff --git a/resources/ts/back/Components/ApplicationLogo.tsx b/resources/ts/back/Components/ApplicationLogo.tsx index 948b1a7..5d63ae3 100644 --- a/resources/ts/back/Components/ApplicationLogo.tsx +++ b/resources/ts/back/Components/ApplicationLogo.tsx @@ -6,7 +6,7 @@ import { useTheme } from "@/back/providers/ThemeProvider"; import logoUwilSupportLight from "&/images/logos/uwil-support-light.svg"; import logoUwilSupportDark from "&/images/logos/uwil-support-dark.svg"; import logoTinyUwilSupport from "&/images/logos/uwil-support-light-icon.svg"; -import { AppEnv } from "@/types/global"; +import { ConfigBackend } from "@/back/types/global"; type ApplicationLogoProps = { forceLight?: boolean; @@ -31,7 +31,7 @@ export default function ApplicationLogo({ forceLight = false, isCollapsed = false, }: ApplicationLogoProps) { - const { routes } = usePage().props.appEnv as AppEnv; + const { routes } = usePage().props.configBackend as ConfigBackend; const { theme } = useTheme(); const wrapperClasses = isCollapsed ? "h-8" : "w-full max-w-[10rem] mx-auto"; const logo = getLogo(isCollapsed, forceLight, theme); diff --git a/resources/ts/back/Components/BtnResetPassword.tsx b/resources/ts/back/Components/BtnResetPassword.tsx index 54028ad..ed6f8b2 100644 --- a/resources/ts/back/Components/BtnResetPassword.tsx +++ b/resources/ts/back/Components/BtnResetPassword.tsx @@ -7,12 +7,12 @@ import { useState } from "react"; import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip"; import useTrans from "@/hooks/use-translations"; import { useToast } from "@/hooks/use-toast"; -import { AuthProp, UserModel } from "@/back/types/global"; -import { AppEnv } from "@/types/global"; +import { AuthProp, ConfigBackend, UserModel } from "@/back/types/global"; +import { GetTranslation } from "@/lib/utils"; export default function BtnResetPassword({ model }: { model: UserModel }) { const { user: userModel } = usePage().props.auth as AuthProp; - const { routes } = usePage().props.appEnv as AppEnv; + const { routes } = usePage().props.configBackend as ConfigBackend; const enumUserRole = usePage().props.enumUserRole as UserModel["role"][]; const { toast } = useToast(); @@ -73,7 +73,7 @@ export default function BtnResetPassword({ model }: { model: UserModel }) { )} } - tooltipContent={useTrans("auth.send_link")} + tooltipContent={GetTranslation("auth.send_link")} disabled={isSending} variant="secondary" size="default" diff --git a/resources/ts/back/Components/Filters/SwitchFilter.tsx b/resources/ts/back/Components/Filters/SwitchFilter.tsx index 8967963..55c80ae 100644 --- a/resources/ts/back/Components/Filters/SwitchFilter.tsx +++ b/resources/ts/back/Components/Filters/SwitchFilter.tsx @@ -11,7 +11,12 @@ type Props = { prefixRoute: string; }; -export default function SwitchFilter({ label, fieldName, modelRoute, prefixRoute }: Props) { +export default function SwitchFilter({ + label, + fieldName, + modelRoute, + prefixRoute, +}: Props) { return ( ( field ?? null, ); - const { locale, routes } = usePage().props.appEnv as AppEnv; + const { locale } = usePage().props.appEnv as AppEnv; + const { routes } = usePage().props.configBackend as ConfigBackend; /** * Set call ajax. @@ -1223,7 +1224,7 @@ export const ModelSelect = forwardRef( "group/button flex rounded-md border min-h-10 h-auto items-center justify-between [&_svg]:pointer-events-auto gap-2 px-4 py-2", autoSize ? "w-auto" : "w-full", responsiveSettings.compactMode && "min-h-8 text-sm", - screenSize === "mobile" && "min-h-12 text-base", + screenSize === "mobile" && "min-h-10 text-base", disabled && "opacity-50 cursor-not-allowed", { "border-destructive/50": localErrors[name] }, className, diff --git a/resources/ts/back/Components/Inputs/MultiSelect.tsx b/resources/ts/back/Components/Inputs/MultiSelect.tsx index 54e5abc..a63a2c7 100644 --- a/resources/ts/back/Components/Inputs/MultiSelect.tsx +++ b/resources/ts/back/Components/Inputs/MultiSelect.tsx @@ -1034,7 +1034,7 @@ export const MultiSelect = forwardRef( "group/button flex rounded-md border min-h-10 h-auto items-center justify-between [&_svg]:pointer-events-auto gap-2 px-4 py-2", autoSize ? "w-auto" : "w-full", responsiveSettings.compactMode && "min-h-8 text-sm", - screenSize === "mobile" && "min-h-12 text-base", + screenSize === "mobile" && "min-h-10 text-base", disabled && "opacity-50 cursor-not-allowed", className, )} diff --git a/resources/ts/back/Components/Inputs/Wysiwyg/Extensions/Image/ImageButton.tsx b/resources/ts/back/Components/Inputs/Wysiwyg/Extensions/Image/ImageButton.tsx index 96980e3..308e499 100644 --- a/resources/ts/back/Components/Inputs/Wysiwyg/Extensions/Image/ImageButton.tsx +++ b/resources/ts/back/Components/Inputs/Wysiwyg/Extensions/Image/ImageButton.tsx @@ -32,6 +32,8 @@ import { GetTranslation } from "@/lib/utils"; type ImageProps = { /** Wysiwyg editor instance. */ editor: Editor; + /** Route name prefix. */ + routeName: string; /** Disable trigger button. */ disabled: boolean; }; @@ -44,7 +46,11 @@ type ImageType = { height: number; }; -export default function ImageButton({ editor, disabled }: ImageProps) { +export default function ImageButton({ + editor, + routeName, + disabled, +}: ImageProps) { // Get all editor options define with customOptions in the parent SimpleWysiwyg. const editorOptions = editor.options.editorProps?.attributes as { [name: string]: string; @@ -247,7 +253,7 @@ export default function ImageButton({ editor, disabled }: ImageProps) { data.append("tableName", editorOptions.tableName); // Get wysiwyg image route upload. - const uploadRoute = route("back.wysiwyg.upload"); + const uploadRoute = route(`${routeName}wysiwyg.upload`); try { const response = await axios.post(uploadRoute, data, { diff --git a/resources/ts/back/Components/Inputs/Wysiwyg/Extensions/Link/LinkButton.tsx b/resources/ts/back/Components/Inputs/Wysiwyg/Extensions/Link/LinkButton.tsx index 2db6f12..0328c49 100644 --- a/resources/ts/back/Components/Inputs/Wysiwyg/Extensions/Link/LinkButton.tsx +++ b/resources/ts/back/Components/Inputs/Wysiwyg/Extensions/Link/LinkButton.tsx @@ -27,6 +27,7 @@ import { ModelSelect } from "@/back/Components/Inputs/ModelSelect"; import useTrans from "@/hooks/use-translations"; import str from "@/hooks/use-string"; import { AppEnv, LaravelEnum } from "@/types/global"; +import { ConfigBackend } from "@/back/types/global"; import { cn, GetTranslation } from "@/lib/utils"; // Custom type with field entry. @@ -75,7 +76,9 @@ type LinkProps = { export default function LinkButton({ editor, disabled }: LinkProps) { // Current domain of the projet. - const { url, routes } = usePage().props.appEnv as AppEnv; + const { url } = usePage().props.appEnv as AppEnv; + // Backend configuration. + const { routes } = usePage().props.configBackend as ConfigBackend; // All models from global enum. const enumModelsList = usePage().props.enumModelsList as LaravelEnumWithField; diff --git a/resources/ts/back/Components/Inputs/Wysiwyg/SimpleWysiwyg.tsx b/resources/ts/back/Components/Inputs/Wysiwyg/SimpleWysiwyg.tsx index 9d721db..362a95a 100644 --- a/resources/ts/back/Components/Inputs/Wysiwyg/SimpleWysiwyg.tsx +++ b/resources/ts/back/Components/Inputs/Wysiwyg/SimpleWysiwyg.tsx @@ -24,6 +24,7 @@ import InputError from "@/back/Components/InputError"; import WordCounter from "@/back/Components/WordCounter"; import Toolbar from "@/back/Components/Inputs/Wysiwyg/Toolbar"; import { cn, GetTranslation } from "@/lib/utils"; +import { ConfigBackend } from "@/back/types/global"; type SimpleWysiwygProps = { className?: string; @@ -55,6 +56,8 @@ export default function SimpleWysiwyg({ parentErrors = null, setData, }: SimpleWysiwygProps) { + const routeName = (usePage().props.configBackend as ConfigBackend).routes + .name; const { errors } = usePage().props; const localErrors = parentErrors ?? errors; @@ -171,7 +174,7 @@ export default function SimpleWysiwyg({ "border-destructive/50": localErrors[name], })} > - + (0); const [docSelected, setDocSelected] = useState(false); const [headerHeight, setHeaderHeight] = useState(0); @@ -435,7 +436,11 @@ export default function Toolbar({ editor }: ToolbarProps) { size="icon" /> - +
diff --git a/resources/ts/back/Components/Layout/Settings/AppSettings.tsx b/resources/ts/back/Components/Layout/Settings/AppSettings.tsx index 4ac715a..d961fd4 100644 --- a/resources/ts/back/Components/Layout/Settings/AppSettings.tsx +++ b/resources/ts/back/Components/Layout/Settings/AppSettings.tsx @@ -12,6 +12,7 @@ import { // * Other import SettingRegistry from "@/back/Components/Layout/Settings/SettingRegistry"; import { cn, GetTranslation } from "@/lib/utils"; +import { ConfigBackend } from "@/back/types/global"; import { AppEnv } from "@/types/global"; type AppSettingsProps = { @@ -19,7 +20,10 @@ type AppSettingsProps = { }; export default function AppSettings({ className = "" }: AppSettingsProps) { - const appEnv = usePage().props.appEnv as AppEnv; + const { appEnv, configBackend } = usePage().props as unknown as { + appEnv: AppEnv; + configBackend: ConfigBackend; + }; return (
@@ -32,12 +36,14 @@ export default function AppSettings({ className = "" }: AppSettingsProps) { - {SettingRegistry.getAll(appEnv).map((Section, index, arr) => ( - <> - {Section} - {Section && index < arr.length - 1 && } - - ))} + {SettingRegistry.getAll(appEnv, configBackend).map( + (Section, index, arr) => ( + <> + {Section} + {Section && index < arr.length - 1 && } + + ), + )}
diff --git a/resources/ts/back/Components/Layout/Settings/Sections/Languages.tsx b/resources/ts/back/Components/Layout/Settings/Sections/Languages.tsx index 960f1a0..f6e6127 100644 --- a/resources/ts/back/Components/Layout/Settings/Sections/Languages.tsx +++ b/resources/ts/back/Components/Layout/Settings/Sections/Languages.tsx @@ -9,9 +9,14 @@ import { DropdownMenuItem } from "@/components/ui/dropdown-menu"; import { AppEnv } from "@/types/global"; import useTrans from "@/hooks/use-translations"; import { cn } from "@/lib/utils"; +import { ConfigBackend } from "@/back/types/global"; -export default function Languages(appEnv: AppEnv) { - const { locales, locale, routes } = appEnv; +export default function Languages( + appEnv: AppEnv, + configBackend: ConfigBackend, +) { + const { locales, locale } = appEnv; + const { routes } = configBackend; const { post, setData } = useForm({ lang: "system", }); diff --git a/resources/ts/back/Components/Layout/Settings/SettingRegistry.tsx b/resources/ts/back/Components/Layout/Settings/SettingRegistry.tsx index 7d64959..1b92f40 100644 --- a/resources/ts/back/Components/Layout/Settings/SettingRegistry.tsx +++ b/resources/ts/back/Components/Layout/Settings/SettingRegistry.tsx @@ -1,10 +1,15 @@ // * Packages import { ReactNode } from "react"; // * Other +import { ConfigBackend } from "@/back/types/global"; import { AppEnv } from "@/types/global"; -// eslint-disable-next-line no-unused-vars -type SettingResolver = (appEnv: AppEnv) => ReactNode; +/* eslint-disable no-unused-vars */ +type SettingResolver = ( + appEnv: AppEnv, + configBackend: ConfigBackend, +) => ReactNode; +/* eslint-enable no-unused-vars */ export default class SettingRegistry { private static resolvers: SettingResolver[] = []; @@ -13,8 +18,8 @@ export default class SettingRegistry { this.resolvers.push(resolver); } - static getAll(appEnv: AppEnv): ReactNode[] { - return this.resolvers.map((resolver) => resolver(appEnv)); + static getAll(appEnv: AppEnv, configBackend: ConfigBackend): ReactNode[] { + return this.resolvers.map((resolver) => resolver(appEnv, configBackend)); } } @@ -26,7 +31,7 @@ const modules = import.meta.glob("./Sections/*.tsx", { string, { // eslint-disable-next-line no-unused-vars - default: (appEnv: AppEnv) => ReactNode; + default: (appEnv: AppEnv, configBackend: ConfigBackend) => ReactNode; } >; diff --git a/resources/ts/back/Components/Layout/Sidebar/AppSidebar.tsx b/resources/ts/back/Components/Layout/Sidebar/AppSidebar.tsx index 1fa9166..e8e56c5 100644 --- a/resources/ts/back/Components/Layout/Sidebar/AppSidebar.tsx +++ b/resources/ts/back/Components/Layout/Sidebar/AppSidebar.tsx @@ -45,9 +45,9 @@ import { SidebarRegistry } from "@/back/Components/Layout/Sidebar/SidebarRegistr import Views from "@/back/lib/actions"; import str from "@/hooks/use-string"; import useTrans from "@/hooks/use-translations"; -import { AppEnv } from "@/types/global"; -import { AuthProp, UserModel } from "@/back/types/global"; +import { AuthProp, UserModel, ConfigBackend } from "@/back/types/global"; import { GetTranslation } from "@/lib/utils"; +import { AppEnv } from "@/types/global"; export type NavListLinksProps = { /** Title of the button. */ @@ -85,12 +85,12 @@ export type NavListProps = Array<{ */ export const filterActions = ({ auth, - appEnv, + configBackend, items, model, }: { auth: AuthProp; - appEnv: AppEnv; + configBackend: ConfigBackend; items?: ReactNode[]; model?: string; }): ReactNode => { @@ -108,7 +108,7 @@ export const filterActions = ({