From dd37148d3fd20728a862f7155b4d4a8e442ea8d9 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Wed, 31 May 2023 16:02:01 +0900 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E4=BB=96=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E6=99=82=E3=81=AE=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/contexts/PageContext.tsx | 23 +++++++++++++++++++++++ src/hooks/useAPICall.ts | 7 +++++++ 2 files changed, 30 insertions(+) diff --git a/src/contexts/PageContext.tsx b/src/contexts/PageContext.tsx index 74a326b..158ab15 100644 --- a/src/contexts/PageContext.tsx +++ b/src/contexts/PageContext.tsx @@ -1,3 +1,5 @@ +import { SettingsPhoneTwoTone } from "@mui/icons-material"; +import { Dialog, DialogActions, DialogContent, Button } from "@mui/material"; import { HasChildren } from "@types"; import { PageID, TabID } from "codes/page"; import { createContext, useState } from "react"; @@ -7,12 +9,14 @@ type ContextProps = { tabId: TabID; setPageId: (pageId: PageID) => void; setTabId: (tabId: TabID) => void; + openDialog: (message: string) => void; }; const contextInit: ContextProps = { pageId: PageID.NONE, tabId: TabID.NONE, setPageId: (pageId: PageID) => {}, setTabId: (tabId: TabID) => {}, + openDialog: (message: string) => {}, }; export const PageContext = createContext(contextInit); @@ -21,6 +25,18 @@ export function PageContextProvider({ children }: Props) { const [pageId, setPageId] = useState(PageID.NONE); const [tabId, setTabId] = useState(TabID.NONE); + const [open, setOpen] = useState(false); + const [dialogMessage, setDialogMessage] = useState(""); + + const openDialog = (message: string) => { + setOpen(true); + setDialogMessage(message); + }; + + const close = () => { + setOpen(false); + }; + return ( {children} + + {dialogMessage} + + + + ); } diff --git a/src/hooks/useAPICall.ts b/src/hooks/useAPICall.ts index b6e7ec6..0ebddbd 100644 --- a/src/hooks/useAPICall.ts +++ b/src/hooks/useAPICall.ts @@ -3,6 +3,7 @@ import { APICommonResponse, apiRequest, ResultCode } from "api"; import { UseFormReturn } from "react-hook-form"; import { Dictionary } from "@types"; import { useSnackbar } from "notistack"; +import usePage from "./usePage"; export const APIErrorType = { NONE: "none", @@ -38,6 +39,8 @@ export default function useAPICall< const [exclusiveError, setExclusiveError] = useState(false); const [generalErrorMessage, setGeneralErrorMessage] = useState(""); + const { openDialog } = usePage(); + const { enqueueSnackbar } = useSnackbar(); const clearErrors = () => { @@ -127,6 +130,10 @@ export default function useAPICall< if (onFailed) { onFailed(res); } + + if (res?.result === ResultCode.EXCLUSIVE_ERROR) { + openDialog("恐れ入りますが、ページを再読込後、再実行してください"); + } }; const handleValidationError = (error: any) => {