31 lines
No EOL
1.2 KiB
JavaScript
31 lines
No EOL
1.2 KiB
JavaScript
import { useMainStore } from '@/store';
|
|
import { updateOrCreateISSCookie } from '@/helpers/cookie-helper';
|
|
|
|
/*
|
|
Will call API to save existing order, or create new one depending where it's called from.
|
|
This will also set Referral information in the store after saving, and then
|
|
update the cookie. To force synchronous behavior pass in 'true' for shouldAwaitSaveSessionQueue
|
|
*/
|
|
export async function saveSession({ shouldAwaitSaveSessionQueue = false }) {
|
|
const store = useMainStore();
|
|
var saveSessionPromise = store.applicationUser.saveSessionPromise
|
|
? store.applicationUser.saveSessionPromise.then(() => { return saveSessionHelper(store); })
|
|
: saveSessionHelper(store);
|
|
|
|
store.setSaveSessionPromise(saveSessionPromise);
|
|
|
|
if (!store.applicationUser.savedSessionId || shouldAwaitSaveSessionQueue) {
|
|
await saveSessionPromise;
|
|
}
|
|
}
|
|
|
|
/*
|
|
Encapsulates asynchronous Save Session logic inside a promise to allow for Save Session queuing
|
|
*/
|
|
async function saveSessionHelper(store) {
|
|
const savedSessionInfo = await store.saveSession();
|
|
if (savedSessionInfo) {
|
|
store.setSaveSessionInfo(savedSessionInfo.data);
|
|
}
|
|
updateOrCreateISSCookie();
|
|
} |