2
0

🐛 (js) Improve session remember behavior

Make sure it correctly retrieves saved variables and doesn't clash with other embedded typebots
This commit is contained in:
Baptiste Arnaud
2023-03-02 10:55:03 +01:00
parent c172a44566
commit ba253cf3e9
16 changed files with 122 additions and 42 deletions

View File

@ -1,16 +1,19 @@
const sessionStorageKey = 'resultId'
export const getExistingResultIdFromSession = () => {
export const getExistingResultIdFromSession = (typebotId?: string) => {
if (!typebotId) return
try {
return sessionStorage.getItem(sessionStorageKey) ?? undefined
return (
sessionStorage.getItem(`${sessionStorageKey}-${typebotId}`) ?? undefined
)
} catch {
/* empty */
}
}
export const setResultInSession = (resultId: string) => {
export const setResultInSession = (typebotId: string, resultId: string) => {
try {
return sessionStorage.setItem(sessionStorageKey, resultId)
return sessionStorage.setItem(`${sessionStorageKey}-${typebotId}`, resultId)
} catch {
/* empty */
}