|
|
|
@@ -1,15 +1,17 @@ |
|
|
|
import { yupResolver } from "@hookform/resolvers/yup"; |
|
|
|
import { Box, Button, Card, Stack, Typography } from "@mui/material"; |
|
|
|
import { Box, Button, Stack, Typography } from "@mui/material"; |
|
|
|
import { HasChildren } from "@types"; |
|
|
|
import { createLoginUser } from "api/login-user"; |
|
|
|
import { PageID, TabID } from "codes/page"; |
|
|
|
import { FormProvider, RHFTextField } from "components/hook-form"; |
|
|
|
import { UserRole } from "codes/user"; |
|
|
|
import { FormProvider, RHFSelect, RHFTextField } from "components/hook-form"; |
|
|
|
import { SelectOptionProps } from "components/hook-form/RHFSelect"; |
|
|
|
import useAPICall from "hooks/useAPICall"; |
|
|
|
import useAuth from "hooks/useAuth"; |
|
|
|
import useDashboard from "hooks/useDashBoard"; |
|
|
|
import useNavigateCustom from "hooks/useNavigateCustom"; |
|
|
|
import useSnackbarCustom from "hooks/useSnackbarCustom"; |
|
|
|
import { useSnackbar } from "notistack"; |
|
|
|
import { useEffect } from "react"; |
|
|
|
import { useEffect, useMemo } from "react"; |
|
|
|
import { useForm } from "react-hook-form"; |
|
|
|
import { getPath } from "routes/path"; |
|
|
|
import * as Yup from "yup"; |
|
|
|
@@ -31,6 +33,7 @@ type FormProps = { |
|
|
|
email: string; |
|
|
|
password: string; |
|
|
|
password_retype: string; |
|
|
|
role: string; |
|
|
|
}; |
|
|
|
|
|
|
|
export default function LoginUserCreate() { |
|
|
|
@@ -39,6 +42,8 @@ export default function LoginUserCreate() { |
|
|
|
TabID.NONE |
|
|
|
); |
|
|
|
|
|
|
|
const { role } = useAuth(); |
|
|
|
|
|
|
|
const { success, error } = useSnackbarCustom(); |
|
|
|
const { navigateWhenChanged } = useNavigateCustom(); |
|
|
|
|
|
|
|
@@ -48,6 +53,7 @@ export default function LoginUserCreate() { |
|
|
|
email: "", |
|
|
|
password: "", |
|
|
|
password_retype: "", |
|
|
|
role: "", |
|
|
|
}, |
|
|
|
resolver: yupResolver( |
|
|
|
Yup.object().shape({ |
|
|
|
@@ -59,10 +65,27 @@ export default function LoginUserCreate() { |
|
|
|
.test("retype", "入力が一致しません", function (value) { |
|
|
|
return this.parent.password === value; |
|
|
|
}), |
|
|
|
role: |
|
|
|
role === UserRole.SUPER_ADMIN |
|
|
|
? Yup.string().required("必須項目です") |
|
|
|
: Yup.string(), |
|
|
|
}) |
|
|
|
), |
|
|
|
}); |
|
|
|
|
|
|
|
const roleOptions: SelectOptionProps[] = useMemo(() => { |
|
|
|
return [ |
|
|
|
{ |
|
|
|
label: "一般", |
|
|
|
value: String(UserRole.NORMAL_ADMIN), |
|
|
|
}, |
|
|
|
{ |
|
|
|
label: "管理者", |
|
|
|
value: String(UserRole.CONTRACT_ADMIN), |
|
|
|
}, |
|
|
|
]; |
|
|
|
}, []); |
|
|
|
|
|
|
|
const { callAPI } = useAPICall({ |
|
|
|
apiMethod: createLoginUser, |
|
|
|
backDrop: true, |
|
|
|
@@ -105,6 +128,11 @@ export default function LoginUserCreate() { |
|
|
|
<AreaBox title="ログインパスワード(再入力)"> |
|
|
|
<RHFTextField name="password_retype" type="password" /> |
|
|
|
</AreaBox> |
|
|
|
{role === UserRole.SUPER_ADMIN && ( |
|
|
|
<AreaBox title="権限"> |
|
|
|
<RHFSelect name="role" options={roleOptions} size="small" /> |
|
|
|
</AreaBox> |
|
|
|
)} |
|
|
|
<Stack direction="row"> |
|
|
|
<Button variant="contained" type="submit"> |
|
|
|
登録 |
|
|
|
|