Better Form Stats (#567)

* Better Form Stats

* fix lint

* submission timer store in localstorage

* Update test case for stats

* remove extra code

* fix form stats

* on restart remove timer

* fix resetTimer function name

* Improve form timer

* Fix timer after form validation error + polish UI

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Chirag Chhatrala
2024-09-18 22:50:52 +05:30
committed by GitHub
parent a057045ef6
commit ceb0648262
14 changed files with 381 additions and 62 deletions

View File

@@ -7,6 +7,9 @@ export const pendingSubmission = (form) => {
? form.form_pending_submission_key + "-" + hash(window.location.href)
: ""
})
const formPendingSubmissionTimerKey = computed(() => {
return formPendingSubmissionKey.value + "-timer"
})
const enabled = computed(() => {
return form?.auto_save ?? false
@@ -28,10 +31,27 @@ export const pendingSubmission = (form) => {
return pendingSubmission ? JSON.parse(pendingSubmission) : defaultValue
}
const setTimer = (value) => {
if (import.meta.server) return
useStorage(formPendingSubmissionTimerKey.value).value = value
}
const removeTimer = () => {
return setTimer(null)
}
const getTimer = (defaultValue = null) => {
if (import.meta.server) return
return useStorage(formPendingSubmissionTimerKey.value).value ?? defaultValue
}
return {
enabled,
set,
get,
remove,
setTimer,
removeTimer,
getTimer,
}
}