|
|
|
@@ -1,10 +1,10 @@ |
|
|
|
import { HasChildren } from "@types"; |
|
|
|
import { checkToken } from "api/app"; |
|
|
|
import { CheckTokenRequest, CheckTokenResponse, checkToken } from "api/app"; |
|
|
|
import { AppReceiptIssuingOrder } from "api/app/receipt-issuing-order"; |
|
|
|
import { PageID } from "codes/page"; |
|
|
|
import useAPICall from "hooks/useAPICall"; |
|
|
|
import useNavigateCustom from "hooks/useNavigateCustom"; |
|
|
|
import { createContext, useEffect, useState } from "react"; |
|
|
|
import { createContext, useCallback, useEffect, useState } from "react"; |
|
|
|
import { useParams } from "react-router-dom"; |
|
|
|
import { getPath } from "routes/path"; |
|
|
|
import { StoreId, getStore, setStore } from "storage/localstorage"; |
|
|
|
@@ -42,9 +42,8 @@ export function AppContextProvider({ children }: Props) { |
|
|
|
"cheking" |
|
|
|
); |
|
|
|
|
|
|
|
const checkTokenAPI = useAPICall({ |
|
|
|
apiMethod: checkToken, |
|
|
|
onSuccess: (res, sendData) => { |
|
|
|
const handleSuccess = useCallback( |
|
|
|
(res: CheckTokenResponse, sendData: CheckTokenRequest) => { |
|
|
|
if (receiptIssuingOrder === null) { |
|
|
|
setTokenResult("ok"); |
|
|
|
_setToken(sendData.access_token); |
|
|
|
@@ -53,11 +52,18 @@ export function AppContextProvider({ children }: Props) { |
|
|
|
|
|
|
|
// 再Fetch用 タイムスタンプが違う場合のみ取り込む |
|
|
|
const lastTimestamp = receiptIssuingOrder?.updated_at ?? ""; |
|
|
|
if (lastTimestamp !== res.data.receipt_issuing_order.updated_at) { |
|
|
|
console.info("発行依頼情報読込"); |
|
|
|
const currentTimestamp = res.data.receipt_issuing_order.updated_at; |
|
|
|
if (lastTimestamp !== currentTimestamp) { |
|
|
|
console.log("発行依頼情報読込", { lastTimestamp, currentTimestamp }); |
|
|
|
setReceiptIssuingOrder(res.data.receipt_issuing_order); |
|
|
|
} |
|
|
|
}, |
|
|
|
[receiptIssuingOrder] |
|
|
|
); |
|
|
|
|
|
|
|
const checkTokenAPI = useAPICall({ |
|
|
|
apiMethod: checkToken, |
|
|
|
onSuccess: handleSuccess, |
|
|
|
onFailed: () => { |
|
|
|
setTokenResult("ng"); |
|
|
|
navigateWhenChanged(getPath(PageID.PAGE_404)); |
|
|
|
@@ -108,7 +114,7 @@ export function AppContextProvider({ children }: Props) { |
|
|
|
clearInterval(interval); |
|
|
|
}; |
|
|
|
} |
|
|
|
}, [token]); |
|
|
|
}, [token, handleSuccess]); |
|
|
|
|
|
|
|
return ( |
|
|
|
<AppContext.Provider |
|
|
|
|