From 72a70972fb4685b856092d699842d5befd4cc43b Mon Sep 17 00:00:00 2001 From: Afiq Date: Thu, 7 Aug 2025 20:37:28 +0800 Subject: [PATCH] Implement Duplicate Component Feature and Enhance Delete Confirmation in FormBuilder - Added a duplicate component button in FormBuilderCanvas.vue, allowing users to easily duplicate existing components. - Introduced a delete confirmation modal in both FormBuilderCanvas.vue and FormBuilderFieldSettingsModal.vue to prevent accidental deletions, enhancing user experience. - Updated delete functionality to utilize the confirmation modal, ensuring users are aware of the consequences of their actions. - Refactored related methods to support the new duplication and confirmation features, maintaining clean and organized code. - Enhanced user feedback with toast notifications upon successful deletion and duplication of components. --- components/FormBuilderCanvas.vue | 77 ++++- components/FormBuilderFieldSettingsModal.vue | 42 ++- components/RsCodeMirror.vue | 15 + pages/form-builder/index.vue | 294 +++++++++++++++---- 4 files changed, 363 insertions(+), 65 deletions(-) diff --git a/components/FormBuilderCanvas.vue b/components/FormBuilderCanvas.vue index d6a0bb2..b3daeb1 100644 --- a/components/FormBuilderCanvas.vue +++ b/components/FormBuilderCanvas.vue @@ -64,16 +64,23 @@ + @@ -101,6 +108,32 @@ + + + +
+
+ +
+

Delete Component

+

+ Are you sure you want to delete this component? This action cannot be undone and will permanently remove the component from your form. +

+
+
+
+ +
@@ -115,7 +148,7 @@ const props = defineProps({ } }); -const emit = defineEmits(['select-component', 'move-component', 'delete-component', 'update-component', 'optimize-layout', 'select-nested-component', 'insert-component-at-index']); +const emit = defineEmits(['select-component', 'move-component', 'delete-component', 'update-component', 'optimize-layout', 'select-nested-component', 'insert-component-at-index', 'duplicate-component']); const selectedComponentId = ref(null); const resizeMode = ref(false); @@ -123,6 +156,10 @@ const resizing = ref(false); const initialWidth = ref(0); const initialX = ref(0); +// Delete modal state +const showDeleteConfirmModal = ref(false); +const componentToDelete = ref(null); + // Watch for changes in formComponents watch(() => props.formComponents, (newComponents) => { // If the currently selected component is no longer in the list, deselect it @@ -155,13 +192,35 @@ const selectComponent = (component) => { emit('select-component', componentCopy); }; -// Handle component deletion -const deleteComponent = (id) => { - if (selectedComponentId.value === id) { - selectedComponentId.value = null; - resizeMode.value = false; +// Handle component duplication +const duplicateComponent = (component) => { + emit('duplicate-component', component); +}; + +// Show delete confirmation modal +const showDeleteModal = (id) => { + componentToDelete.value = id; + showDeleteConfirmModal.value = true; +}; + +// Cancel delete operation +const cancelDelete = () => { + showDeleteConfirmModal.value = false; + componentToDelete.value = null; +}; + +// Confirm delete operation +const confirmDelete = () => { + if (componentToDelete.value) { + const id = componentToDelete.value; + if (selectedComponentId.value === id) { + selectedComponentId.value = null; + resizeMode.value = false; + } + emit('delete-component', id); } - emit('delete-component', id); + showDeleteConfirmModal.value = false; + componentToDelete.value = null; }; // Handle nested component selection from sections diff --git a/components/FormBuilderFieldSettingsModal.vue b/components/FormBuilderFieldSettingsModal.vue index 2533b5b..2fc94fd 100644 --- a/components/FormBuilderFieldSettingsModal.vue +++ b/components/FormBuilderFieldSettingsModal.vue @@ -2918,7 +2918,7 @@ if (this.element.querySelector('.file-upload')) {
@@ -2937,6 +2937,32 @@ if (this.element.querySelector('.file-upload')) { + + +
+
+ +
+

Reset to Default Settings

+

+ Are you sure you want to reset this component to its default settings? This action will overwrite all current configuration and cannot be undone. +

+
+
+
+ +
+