From a297f2db501214d3781d23a3a2604d84be96532e Mon Sep 17 00:00:00 2001 From: formsdev <136701234+formsdev@users.noreply.github.com> Date: Thu, 12 Oct 2023 16:56:02 +0530 Subject: [PATCH] Auto save form response based on form config (#217) * Auto save form response based on form config * Move confetti and autosave to customization --------- Co-authored-by: Julien Nahum --- app/Http/Requests/UserFormRequest.php | 1 + app/Models/Forms/Form.php | 1 + ...23_10_10_140600_add_auto_save_to_forms.php | 32 +++++++++++++++++++ .../js/components/open/forms/OpenForm.vue | 4 +-- .../form-components/FormAboutSubmission.vue | 18 ----------- .../form-components/FormCustomization.vue | 18 ++++++++++- .../forms/fields/FormFieldEditSidebar.vue | 4 +-- resources/js/mixins/form_editor/initForm.js | 1 + 8 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 database/migrations/2023_10_10_140600_add_auto_save_to_forms.php diff --git a/app/Http/Requests/UserFormRequest.php b/app/Http/Requests/UserFormRequest.php index 79d8633..1006095 100644 --- a/app/Http/Requests/UserFormRequest.php +++ b/app/Http/Requests/UserFormRequest.php @@ -74,6 +74,7 @@ abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest 'editable_submissions' => 'boolean|nullable', 'editable_submissions_button_text' => 'string|min:1|max:50', 'confetti_on_submission' => 'boolean', + 'auto_save'=> 'boolean', // Properties 'properties' => 'required|array', diff --git a/app/Models/Forms/Form.php b/app/Models/Forms/Form.php index 7ba3fcc..c932e9a 100644 --- a/app/Models/Forms/Form.php +++ b/app/Models/Forms/Form.php @@ -81,6 +81,7 @@ class Form extends Model 'editable_submissions', 'editable_submissions_button_text', 'confetti_on_submission', + 'auto_save', // Security & Privacy 'can_be_indexed', diff --git a/database/migrations/2023_10_10_140600_add_auto_save_to_forms.php b/database/migrations/2023_10_10_140600_add_auto_save_to_forms.php new file mode 100644 index 0000000..fd9f817 --- /dev/null +++ b/database/migrations/2023_10_10_140600_add_auto_save_to_forms.php @@ -0,0 +1,32 @@ +boolean('auto_save')->default(true); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('forms', function (Blueprint $table) { + $table->dropColumn('auto_save'); + }); + } +}; diff --git a/resources/js/components/open/forms/OpenForm.vue b/resources/js/components/open/forms/OpenForm.vue index 2f492d7..b0bc89b 100644 --- a/resources/js/components/open/forms/OpenForm.vue +++ b/resources/js/components/open/forms/OpenForm.vue @@ -224,7 +224,7 @@ export default { dataForm: { deep: true, handler() { - if (this.isPublicFormPage && this.form && this.dataFormValue) { + if (this.isPublicFormPage && this.form && this.form.auto_save && this.dataFormValue) { try { window.localStorage.setItem(this.formPendingSubmissionKey, JSON.stringify(this.dataFormValue)) } catch (e) { @@ -310,7 +310,7 @@ export default { } } } - if (this.isPublicFormPage) { + if (this.isPublicFormPage && this.form.auto_save) { let pendingData try { pendingData = window.localStorage.getItem(this.formPendingSubmissionKey) diff --git a/resources/js/components/open/forms/components/form-components/FormAboutSubmission.vue b/resources/js/components/open/forms/components/form-components/FormAboutSubmission.vue index 7878908..acae96d 100644 --- a/resources/js/components/open/forms/components/form-components/FormAboutSubmission.vue +++ b/resources/js/components/open/forms/components/form-components/FormAboutSubmission.vue @@ -153,10 +153,6 @@ help="This message will be shown when the form will have the maximum number of submissions" :required="false" /> - @@ -173,7 +169,6 @@ export default { return { submissionOptions: {}, isCollapseOpen: true, - isMounted: false } }, @@ -229,18 +224,5 @@ export default { } } }, - - mounted() { - this.isMounted = true - }, - - methods: { - onChangeConfettiOnSubmission(val) { - this.$set(this.form, 'confetti_on_submission', val) - if(this.isMounted && val){ - this.playConfetti() - } - } - } } diff --git a/resources/js/components/open/forms/components/form-components/FormCustomization.vue b/resources/js/components/open/forms/components/form-components/FormCustomization.vue index 99bcceb..26eb5a5 100644 --- a/resources/js/components/open/forms/components/form-components/FormCustomization.vue +++ b/resources/js/components/open/forms/components/form-components/FormCustomization.vue @@ -73,6 +73,14 @@ + + @@ -86,6 +94,7 @@ export default { }, data () { return { + isMounted: false, isCollapseOpen: true } }, @@ -104,10 +113,17 @@ export default { watch: {}, - mounted () { + mounted() { + this.isMounted = true }, methods: { + onChangeConfettiOnSubmission(val) { + this.$set(this.form, 'confetti_on_submission', val) + if(this.isMounted && val){ + this.playConfetti() + } + }, openChat () { window.$crisp.push(['do', 'chat:show']) window.$crisp.push(['do', 'chat:open']) diff --git a/resources/js/components/open/forms/fields/FormFieldEditSidebar.vue b/resources/js/components/open/forms/fields/FormFieldEditSidebar.vue index b0eb106..0a236de 100644 --- a/resources/js/components/open/forms/fields/FormFieldEditSidebar.vue +++ b/resources/js/components/open/forms/fields/FormFieldEditSidebar.vue @@ -1,6 +1,6 @@