From 6ea7c40b758a499a1070a30f0c9aea810adb140a Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Mon, 31 Jul 2023 13:41:36 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=91=E3=82=B9=E3=83=AF=E3=83=BC=E3=83=89?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=80=80=E5=88=B6=E5=BE=A1=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/login-user/change-password.tsx | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/pages/dashboard/login-user/change-password.tsx b/src/pages/dashboard/login-user/change-password.tsx index 2507cb0..3e2a93e 100644 --- a/src/pages/dashboard/login-user/change-password.tsx +++ b/src/pages/dashboard/login-user/change-password.tsx @@ -1,22 +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 { - changeLoginPassword, - createLoginUser, - getLoginUsers, -} from "api/login-user"; +import { changeLoginPassword, getLoginUsers } from "api/login-user"; import { PageID, TabID } from "codes/page"; +import { UserRole } from "codes/user"; import { FormProvider, RHFTextField } from "components/hook-form"; 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, useState } from "react"; import { useForm } from "react-hook-form"; import { useParams } from "react-router-dom"; -import { getPath } from "routes/path"; import * as Yup from "yup"; type AreaBoxProps = { @@ -42,6 +37,8 @@ export default function ChangePassword() { TabID.NONE ); + const { initialized, userId, role } = useAuth(); + const { success, error } = useSnackbarCustom(); const { id: paramUserId } = useParams(); @@ -76,7 +73,7 @@ export default function ChangePassword() { }, }); - const { callAPI: callChangeLoginPassword } = useAPICall({ + const { callAPI: callChangeLoginPassword, makeSendData } = useAPICall({ apiMethod: changeLoginPassword, backDrop: true, form, @@ -96,13 +93,25 @@ export default function ChangePassword() { }; const handleSubmt = (data: FormProps) => { - callChangeLoginPassword({ ...data, timestamp }); + const sendData = makeSendData({ ...data, timestamp }); + + if (userId === paramUserId) { + // 自身の場合はパラメータなしで送信する + } else { + sendData.id = paramUserId ?? ""; + } + + callChangeLoginPassword(sendData); }; + useEffect(() => { + if (initialized) { + fetch(); + } + }, [initialized]); useEffect(() => { setHeaderTitle("パスワード変更"); setTabs(null); - fetch(); }, []); return (