From 400c2729dc8ad284ae55a14fbb58325d22bb7251 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Wed, 27 May 2026 12:07:50 +0200 Subject: [PATCH] fix: :lock: restrict the reset password button to conceptor users --- .../ts/back/Components/BtnResetPassword.tsx | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/resources/ts/back/Components/BtnResetPassword.tsx b/resources/ts/back/Components/BtnResetPassword.tsx index cd9188b..54028ad 100644 --- a/resources/ts/back/Components/BtnResetPassword.tsx +++ b/resources/ts/back/Components/BtnResetPassword.tsx @@ -7,14 +7,20 @@ import { useState } from "react"; import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip"; import useTrans from "@/hooks/use-translations"; import { useToast } from "@/hooks/use-toast"; -import { UserModel } from "@/back/types/global"; +import { AuthProp, UserModel } from "@/back/types/global"; import { AppEnv } from "@/types/global"; export default function BtnResetPassword({ model }: { model: UserModel }) { + const { user: userModel } = usePage().props.auth as AuthProp; const { routes } = usePage().props.appEnv as AppEnv; + const enumUserRole = usePage().props.enumUserRole as UserModel["role"][]; const { toast } = useToast(); + const [isSending, setIsSending] = useState(false); + const getEnumRoleValue = (name: string) => + enumUserRole.find((role) => role.name === name)?.value; + // Translations. const transResetPassword = useTrans("auth.reset_password"); const transMailSent = useTrans("auth.mail_sent"); @@ -49,29 +55,31 @@ export default function BtnResetPassword({ model }: { model: UserModel }) { }; return ( -
{ - e.preventDefault(); - handleSendResetLink(); - }} - > - - {transResetPassword} - {isSending ? ( - - ) : ( - - )} - - } - tooltipContent={useTrans("auth.send_link")} - disabled={isSending} - variant="secondary" - size="default" - type="submit" - /> - + userModel.role.value === getEnumRoleValue("conceptor") && ( +
{ + e.preventDefault(); + handleSendResetLink(); + }} + > + + {transResetPassword} + {isSending ? ( + + ) : ( + + )} + + } + tooltipContent={useTrans("auth.send_link")} + disabled={isSending} + variant="secondary" + size="default" + type="submit" + /> + + ) ); }