import { yupResolver } from "@hookform/resolvers/yup"; import { Box, Button, Stack, Typography } from "@mui/material"; import { HasChildren } from "@types"; import { startPasswordSetting } from "api/auth"; import RequireChip from "components/chip/RequireChip"; import { FormProvider, RHFTextField } from "components/hook-form"; import StackRow from "components/stack/StackRow"; import useAPICall from "hooks/useAPICall"; import useNavigateCustom from "hooks/useNavigateCustom"; import { PageID } from "pages"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { getPath } from "routes/path"; import { object as YupObject, string as YupString } from "yup"; type AreaBoxProps = { label: string; require?: boolean; } & HasChildren; function AreaBox({ label, children, require }: AreaBoxProps) { return ( 〇{label} {children} ); } type FormProps = { email: string; retype_email: string; }; export default function PasswordSettingStart() { const { navigateWhenChanged } = useNavigateCustom(); const [done, setDone] = useState(null); const form = useForm({ defaultValues: { email: "", retype_email: "", }, resolver: yupResolver( YupObject().shape({ email: YupString().required("必須項目です"), retype_email: YupString() .required("必須項目です") .test("retype", "一致しません", function (value) { return value === this.parent.email; }), }) ), }); const { callAPI: callStartPasswordSetting } = useAPICall({ apiMethod: startPasswordSetting, backDrop: true, form, onSuccess: () => { setDone(true); }, onFailed: () => {}, }); const handleSubmit = (data: FormProps) => { callStartPasswordSetting({ ...data }); }; const toLogin = () => { navigateWhenChanged(getPath(PageID.LOGIN)); }; if (done === true) { return ( メールアドレスに設定手続きのご案内を送信しました。 ご確認ください。 ); } return ( 登録済みのメールアドレスへ変更用のURLを送信します。 8-20文字で設定可能です。 半角英数字と記号(@.-)が使えます。 確認のため再度同じパスワードを入力してください。 ); }