import {
Box,
Button,
Divider,
Paper,
Stack,
Step,
StepLabel,
Stepper,
Table,
TableBody,
TableCell,
TableRow,
Typography,
} from "@mui/material";
import { HasChildren } from "@types";
import { getPrefName } from "codes/prefcode";
import useApp from "hooks/useApp";
import useNavigateCustom from "hooks/useNavigateCustom";
import { useMemo, useState } from "react";
import useInputMailStep from "./hooks/useInputMailStep";
import useAPICall from "hooks/useAPICall";
import { mailRequest } from "api/app/receipt-issuing-order";
import useSnackbarCustom from "hooks/useSnackbarCustom";
type TableRowCustomProps = {
title: string;
value: string;
};
const TableRowCustom = ({ title, value }: TableRowCustomProps) => {
return (
{title}
{value}
);
};
type SectionProps = {
title: string;
subtitle?: string;
} & HasChildren;
const Section = ({ title, subtitle, children }: SectionProps) => {
return (
{title}
{subtitle && {subtitle}}
{children}
);
};
export default function MailOrder() {
const {
tokenResult,
navigateToHome,
fetch,
receiptIssuingOrder: order,
} = useApp();
const { success, error } = useSnackbarCustom();
const { navigate } = useNavigateCustom();
const [mode, setMode] = useState<"input" | "confirm" | "done">("input");
const input = useInputMailStep({
onNext: () => {
setMode("confirm");
},
onPrev: () => {
navigate(-1);
},
});
const requestMailAPI = useAPICall({
apiMethod: mailRequest,
onSuccess: () => {
fetch();
setMode("done");
},
onFailed: () => {
error("登録失敗");
},
});
const currentStep = useMemo(() => {
if (mode === "input") return 0;
if (mode === "confirm") return 1;
if (mode === "done") return 2;
}, [mode]);
const handleConfirm = () => {
if (!order) return;
requestMailAPI.callAPI({
id: order.id,
timestamp: order.updated_at,
...input.values(),
});
};
if (tokenResult !== "ok") {
return null;
}
return (
<>
領収証郵送依頼
郵送先情報入力
確認
完了
{mode === "input" && input.element}
{mode === "confirm" && (
郵送先情報確認
郵送先に間違いがないか確認してください。
投函まで数営業日を要しますのでご了承ください。
)}
{mode === "done" && (
郵送依頼を受付いたしました。
到着までしばらくお待ちください。
)}
>
);
}