{"version":3,"file":"useHandleSubmit-OH5vd1zr.js","sources":["../../../app/frontend/composables/helpers/useHelpers.js","../../../app/frontend/composables/useLocalStorage.js","../../../app/frontend/composables/useHandleSubmit.js"],"sourcesContent":["const constructVuelidateAttribute = (attr, vuelidateBase) => {\n // This recursive function allows to check for vuelidate method of nested attributes\n const [string, ...array] = attr.split('.');\n return array.length ? constructVuelidateAttribute(array.join('.'), vuelidateBase[string]) : vuelidateBase[string];\n};\n\nconst safeLocalStorage = (() => {\n /* eslint-disable no-unused-vars */\n const voidLocalStorage = {\n clear: () => null,\n getItem: (_key) => null,\n key: (_index) => null,\n removeItem: (_key) => null,\n setItem: (_key, _value) => null,\n };\n\n try {\n return localStorage || voidLocalStorage;\n } catch (e) {\n return voidLocalStorage;\n }\n})();\n\nconst formatAsCurrency = (value) => {\n if (typeof(value) != 'number') return '- €';\n return value.toLocaleString('fr-FR', { minimumFractionDigits: 0, maximumFractionDigits: 0, style: 'currency', currency: 'EUR' });\n};\n\nconst useHelpers = () => {\n return {\n constructVuelidateAttribute,\n safeLocalStorage,\n formatAsCurrency,\n };\n};\n\nexport default useHelpers;\n","import { onMounted, watch } from 'vue';\nimport useHelpers from './helpers/useHelpers';\nimport useObjectHelpers from './helpers/useObjectHelpers';\n\nconst useLocalStorage = ({ stateToMerge, localStorageItem }) => {\n const { safeLocalStorage } = useHelpers();\n const { merge } = useObjectHelpers();\n\n onMounted(() => {\n try {\n const data = JSON.parse(safeLocalStorage.getItem(localStorageItem));\n delete (data?.user || data)?.isMarketingCampaignOptIn; // For RGPD compliance reasons, the opt-in checkbox can never be checked by default. We thus erase it from the local storage data.\n\n merge(stateToMerge.form, data);\n } catch {\n // TO DO - implement sentry error reporting\n }\n });\n\n const updateLocalStorage = (newData) => {\n safeLocalStorage.setItem(localStorageItem, JSON.stringify(newData));\n };\n\n watch(stateToMerge.form, updateLocalStorage);\n};\n\nexport default useLocalStorage;\n","import axios from 'axios';\n\nimport useStringTransformers from './helpers/useStringTransformers';\nimport useHelpers from './helpers/useHelpers';\n\nimport i18n from '../entrypoints/i18n';\n\nconst useHandleSubmit = () => {\n const I18n = i18n;\n const { toCamel } = useStringTransformers();\n const { safeLocalStorage } = useHelpers();\n\n const post = async ({ endpoint, formattedParams }) => {\n const response = await axios.post(endpoint, formattedParams.value);\n const redirectionUrl = response.data.includes('DOCTYPE') ? response.request.responseURL : response.data;\n return { redirectionUrl };\n };\n\n const resetLocalStorage = ({ localStorageItem, redirectionUrl }) => {\n const isRedirectedToLoginForm = ['/connection', 'identification'].some((path) => redirectionUrl.includes(path));\n if (isRedirectedToLoginForm) return;\n\n setTimeout(() => safeLocalStorage.removeItem(localStorageItem), 0);\n };\n\n const redirect = (redirectionUrl) => window.location.href = redirectionUrl;\n\n const resetUserAttributes = ({ userAttributes, error }) => {\n if (error.response?.status === 400 && error?.response?.data) {\n for (const key of Object.keys(error.response.data)) {\n userAttributes[toCamel(key)] = null;\n }\n }\n };\n\n const populateFlash = ({ flash, error }) => {\n if (error.response?.status === 400 && error?.response?.data) {\n let text = '';\n for (const [key, value] of Object.entries(error.response.data)) {\n text += I18n.t(`shared.sectionProfilings.flashErrors.${toCamel(key)}`) + `: ${value[0]}
`;\n }\n if (text) flash.show = true; flash.text = text;\n }\n };\n\n const isRedirectedFromLoginForm = window?.location.search.includes('submit=true');\n\n return {\n post,\n resetLocalStorage,\n redirect,\n resetUserAttributes,\n populateFlash,\n isRedirectedFromLoginForm,\n };\n};\n\nexport default useHandleSubmit;\n"],"names":["constructVuelidateAttribute","attr","vuelidateBase","string","array","safeLocalStorage","voidLocalStorage","_key","_index","_value","formatAsCurrency","value","useHelpers","useLocalStorage","stateToMerge","localStorageItem","merge","useObjectHelpers","onMounted","data","_a","updateLocalStorage","newData","watch","useHandleSubmit","I18n","i18n","toCamel","useStringTransformers","post","endpoint","formattedParams","response","axios","resetLocalStorage","redirectionUrl","path","redirect","resetUserAttributes","userAttributes","error","_b","key","populateFlash","flash","text","isRedirectedFromLoginForm"],"mapp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