|
|
|
@ -1,6 +1,6 @@ |
|
|
|
import { createContext, useState, useEffect, useContext, use, useRef } from "react"; |
|
|
|
import { createContext, useState, useEffect, useContext, use, useRef } from "react"; |
|
|
|
import moment from "moment"; |
|
|
|
import moment from "moment"; |
|
|
|
import { updateUser } from "./backend"; |
|
|
|
import { updateUser, writeToGoogleSheet } from "./backend"; |
|
|
|
import { useData } from "./useData"; |
|
|
|
import { useData } from "./useData"; |
|
|
|
|
|
|
|
|
|
|
|
const userContext=createContext(); |
|
|
|
const userContext=createContext(); |
|
|
|
@ -27,7 +27,9 @@ export function UserProvider({children}) { |
|
|
|
|
|
|
|
|
|
|
|
const {data}=useData(); |
|
|
|
const {data}=useData(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getSessionId(){ |
|
|
|
|
|
|
|
return `${SessionTime[sessionId]!=null? SessionTime[sessionId][0].replace(':',''):'no-session'}`; |
|
|
|
|
|
|
|
} |
|
|
|
function getFileId(pass){ |
|
|
|
function getFileId(pass){ |
|
|
|
if(!userId){ |
|
|
|
if(!userId){ |
|
|
|
if(data?.id){ |
|
|
|
if(data?.id){ |
|
|
|
@ -37,12 +39,12 @@ export function UserProvider({children}) { |
|
|
|
}return `${password||pass||'0000'}_${userId}`; |
|
|
|
}return `${password||pass||'0000'}_${userId}`; |
|
|
|
} |
|
|
|
} |
|
|
|
function getDataId(){ |
|
|
|
function getDataId(){ |
|
|
|
if(!userId) return `${moment().format('YYYYMM')}/${moment().format("MMDD")}/${SessionTime[sessionId]!=null? SessionTime[sessionId][0].replace(':',''):'no-session'}/testuser_${moment().format('hhmmss')}`; |
|
|
|
if(!userId) return `${moment().format('YYYYMM')}/${moment().format("MMDD")}/${getSessionId()}/testuser_${moment().format('hhmmss')}`; |
|
|
|
return `${moment().format('YYYYMM')}/${moment().format("MMDD")}/${SessionTime[sessionId]!=null? SessionTime[sessionId][0].replace(':',''):'no-session'}/${userId}`; |
|
|
|
return `${moment().format('YYYYMM')}/${moment().format("MMDD")}/${getSessionId()}/${userId}`; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getUploadFolder(){ |
|
|
|
function getUploadFolder(){ |
|
|
|
return `${moment().format("YYYYMM")}/${moment().format("MMDD")}/${SessionTime[sessionId]!=null? SessionTime[sessionId][0].replace(':',''):'no-session'}`; |
|
|
|
return `${moment().format("YYYYMM")}/${moment().format("MMDD")}/${getSessionId()}`; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function reset(){ |
|
|
|
function reset(){ |
|
|
|
@ -68,6 +70,21 @@ export function UserProvider({children}) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function writeSheet(){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
writeToGoogleSheet( |
|
|
|
|
|
|
|
moment().format("YYYY/MM/DD"), |
|
|
|
|
|
|
|
getSessionId(), |
|
|
|
|
|
|
|
userId, |
|
|
|
|
|
|
|
password |
|
|
|
|
|
|
|
).then(() => { |
|
|
|
|
|
|
|
console.log("Data written to Google Sheet successfully"); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch((error) => { |
|
|
|
|
|
|
|
console.error("Error writing data to Google Sheet:", error); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(()=>{ |
|
|
|
useEffect(()=>{ |
|
|
|
console.log("User ID changed:", password, sessionId, userId); |
|
|
|
console.log("User ID changed:", password, sessionId, userId); |
|
|
|
@ -127,7 +144,8 @@ export function UserProvider({children}) { |
|
|
|
reset, uploadHistory: saveHistory, setChoice, |
|
|
|
reset, uploadHistory: saveHistory, setChoice, |
|
|
|
choice, |
|
|
|
choice, |
|
|
|
setSummary, summary, getDataId, |
|
|
|
setSummary, summary, getDataId, |
|
|
|
setPassword}}> |
|
|
|
setPassword, |
|
|
|
|
|
|
|
writeSheet}}> |
|
|
|
{children} |
|
|
|
{children} |
|
|
|
</userContext.Provider> |
|
|
|
</userContext.Provider> |
|
|
|
); |
|
|
|
); |
|
|
|
|