fix: 🔒 restrict the reset password button to conceptor users
This commit is contained in:
parent
9e89d99177
commit
400c2729dc
1 changed files with 33 additions and 25 deletions
|
|
@ -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 (
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
handleSendResetLink();
|
||||
}}
|
||||
>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={
|
||||
<>
|
||||
{transResetPassword}
|
||||
{isSending ? (
|
||||
<LoaderCircleIcon className="animate-spin" />
|
||||
) : (
|
||||
<SendIcon />
|
||||
)}
|
||||
</>
|
||||
}
|
||||
tooltipContent={useTrans("auth.send_link")}
|
||||
disabled={isSending}
|
||||
variant="secondary"
|
||||
size="default"
|
||||
type="submit"
|
||||
/>
|
||||
</form>
|
||||
userModel.role.value === getEnumRoleValue("conceptor") && (
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
handleSendResetLink();
|
||||
}}
|
||||
>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={
|
||||
<>
|
||||
{transResetPassword}
|
||||
{isSending ? (
|
||||
<LoaderCircleIcon className="animate-spin" />
|
||||
) : (
|
||||
<SendIcon />
|
||||
)}
|
||||
</>
|
||||
}
|
||||
tooltipContent={useTrans("auth.send_link")}
|
||||
disabled={isSending}
|
||||
variant="secondary"
|
||||
size="default"
|
||||
type="submit"
|
||||
/>
|
||||
</form>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue