| @@ -45,11 +45,18 @@ export function AppContextProvider({ children }: Props) { | |||||
| const checkTokenAPI = useAPICall({ | const checkTokenAPI = useAPICall({ | ||||
| apiMethod: checkToken, | apiMethod: checkToken, | ||||
| onSuccess: (res, sendData) => { | onSuccess: (res, sendData) => { | ||||
| setTokenResult("ok"); | |||||
| _setToken(sendData.access_token); | |||||
| setReceiptIssuingOrder(res.data.receipt_issuing_order); | |||||
| if (receiptIssuingOrder === null) { | |||||
| setTokenResult("ok"); | |||||
| _setToken(sendData.access_token); | |||||
| setStore(StoreId.ACCESS_TOKEN, sendData.access_token); | |||||
| } | |||||
| setStore(StoreId.ACCESS_TOKEN, sendData.access_token); | |||||
| // 再Fetch用 タイムスタンプが違う場合のみ取り込む | |||||
| const lastTimestamp = receiptIssuingOrder?.updated_at ?? ""; | |||||
| if (lastTimestamp !== res.data.receipt_issuing_order.updated_at) { | |||||
| console.info("発行依頼情報読込"); | |||||
| setReceiptIssuingOrder(res.data.receipt_issuing_order); | |||||
| } | |||||
| }, | }, | ||||
| onFailed: () => { | onFailed: () => { | ||||
| setTokenResult("ng"); | setTokenResult("ng"); | ||||
| @@ -89,6 +96,20 @@ export function AppContextProvider({ children }: Props) { | |||||
| } | } | ||||
| }, [paramToken]); | }, [paramToken]); | ||||
| // 定期的にFetchする | |||||
| // 排他エラーとなる確率を下げるため | |||||
| useEffect(() => { | |||||
| if (token) { | |||||
| const interval = setInterval(() => { | |||||
| fetch(); | |||||
| }, 5 * 1000); | |||||
| return () => { | |||||
| clearInterval(interval); | |||||
| }; | |||||
| } | |||||
| }, [token]); | |||||
| return ( | return ( | ||||
| <AppContext.Provider | <AppContext.Provider | ||||
| value={{ | value={{ | ||||