Refactor VariableManager and Manage Form Page for Improved UI and Functionality

- Enhanced the VariableManager component with improved formatting and structure for better readability.
- Updated the Manage Form page to include a delete confirmation modal for form deletion, enhancing user experience and preventing accidental deletions.
- Refined the layout and styling of the Manage Form page, including adjustments to the header and search functionality for better usability.
- Improved the handling of form actions and added visual feedback for editing and deleting forms.
This commit is contained in:
Md Afiq Iskandar 2025-05-16 08:34:06 +08:00
parent f320ad759a
commit af80d368b0
2 changed files with 192 additions and 144 deletions

View File

@ -5,13 +5,17 @@
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<div> <div>
<h3 class="text-lg font-medium text-gray-900">Process Variables</h3> <h3 class="text-lg font-medium text-gray-900">Process Variables</h3>
<p class="mt-1 text-sm text-gray-500">Manage variables for your process flow</p> <p class="mt-1 text-sm text-gray-500">
Manage variables for your process flow
</p>
</div> </div>
<RsButton <RsButton
@click="() => { @click="
resetForm(); () => {
showAddVariable = true; resetForm();
}" showAddVariable = true;
}
"
variant="primary" variant="primary"
size="sm" size="sm"
> >
@ -25,40 +29,42 @@
<div class="p-4"> <div class="p-4">
<!-- Empty State --> <!-- Empty State -->
<div v-if="!variables.length" class="text-center py-8"> <div v-if="!variables.length" class="text-center py-8">
<Icon name="material-symbols:data-object" class="w-12 h-12 mx-auto mb-3 text-gray-400" /> <Icon
<h4 class="text-sm font-medium text-gray-900 mb-1">No Variables Added</h4> name="material-symbols:data-object"
<p class="text-sm text-gray-500 mb-4">Add variables to store and manage data in your process</p> class="w-12 h-12 mx-auto mb-3 text-gray-400"
<RsButton />
@click="() => { <h4 class="text-sm font-medium text-gray-900 mb-1">
resetForm(); No Variables Added
showAddVariable = true; </h4>
}" <p class="text-sm text-gray-500 mb-4">
variant="secondary" Add variables to store and manage data in your process
size="sm" </p>
>
<Icon name="material-symbols:add" class="mr-1" />
Add Your First Variable
</RsButton>
</div> </div>
<!-- Variable List --> <!-- Variable List -->
<div v-else class="space-y-2"> <div v-else class="space-y-2">
<div v-for="variable in variables" :key="variable.name" class="variable-item"> <div
<div class="flex items-center justify-between p-3 bg-white rounded-lg border border-gray-200 hover:border-blue-200 hover:shadow-sm transition-all duration-200"> v-for="variable in variables"
:key="variable.name"
class="variable-item"
>
<div
class="flex items-center justify-between p-3 bg-white rounded-lg border border-gray-200 hover:border-blue-200 hover:shadow-sm transition-all duration-200"
>
<div class="flex-1"> <div class="flex-1">
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<span class="font-medium text-gray-900">{{ variable.name }}</span> <span class="font-medium text-gray-900">{{
<RsBadge variable.name
:variant="variable.scope === 'global' ? 'primary' : 'secondary'" }}</span>
<RsBadge
:variant="
variable.scope === 'global' ? 'primary' : 'secondary'
"
size="sm" size="sm"
> >
{{ variable.scope }} {{ variable.scope }}
</RsBadge> </RsBadge>
<RsBadge <RsBadge variant="outline" size="sm" class="text-gray-500">
variant="outline"
size="sm"
class="text-gray-500"
>
{{ variable.type }} {{ variable.type }}
</RsBadge> </RsBadge>
</div> </div>
@ -67,14 +73,14 @@
</p> </p>
</div> </div>
<div class="flex items-center gap-2 ml-4"> <div class="flex items-center gap-2 ml-4">
<button <button
@click="editVariable(variable)" @click="editVariable(variable)"
class="p-1.5 text-gray-400 hover:text-blue-500 hover:bg-blue-50 rounded-md transition-colors" class="p-1.5 text-gray-400 hover:text-blue-500 hover:bg-blue-50 rounded-md transition-colors"
title="Edit variable" title="Edit variable"
> >
<Icon name="material-symbols:edit" class="w-4 h-4" /> <Icon name="material-symbols:edit" class="w-4 h-4" />
</button> </button>
<button <button
@click="deleteVariable(variable)" @click="deleteVariable(variable)"
class="p-1.5 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-md transition-colors" class="p-1.5 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-md transition-colors"
title="Delete variable" title="Delete variable"
@ -110,8 +116,9 @@
validation="required|alpha_numeric|length:3,50" validation="required|alpha_numeric|length:3,50"
:validation-messages="{ :validation-messages="{
required: 'Variable name is required', required: 'Variable name is required',
alpha_numeric: 'Variable name can only contain letters, numbers, and underscores', alpha_numeric:
length: 'Variable name must be between 3 and 50 characters' 'Variable name can only contain letters, numbers, and underscores',
length: 'Variable name must be between 3 and 50 characters',
}" }"
/> />
@ -127,11 +134,11 @@
{ label: 'Object', value: 'object' }, { label: 'Object', value: 'object' },
{ label: 'Array', value: 'array' }, { label: 'Array', value: 'array' },
{ label: 'Date', value: 'date' }, { label: 'Date', value: 'date' },
{ label: 'File', value: 'file' } { label: 'File', value: 'file' },
]" ]"
validation="required" validation="required"
:validation-messages="{ :validation-messages="{
required: 'Variable type is required' required: 'Variable type is required',
}" }"
/> />
@ -142,11 +149,11 @@
label="Scope" label="Scope"
:options="[ :options="[
{ label: 'Process', value: 'process' }, { label: 'Process', value: 'process' },
{ label: 'Global', value: 'global' } { label: 'Global', value: 'global' },
]" ]"
validation="required" validation="required"
:validation-messages="{ :validation-messages="{
required: 'Variable scope is required' required: 'Variable scope is required',
}" }"
/> />
@ -168,18 +175,11 @@
/> />
<div class="flex justify-end space-x-2 pt-4 border-t border-gray-200"> <div class="flex justify-end space-x-2 pt-4 border-t border-gray-200">
<RsButton <RsButton type="button" @click="closeModal" variant="tertiary">
type="button"
@click="closeModal"
variant="tertiary"
>
Cancel Cancel
</RsButton> </RsButton>
<FormKit <FormKit type="submit" input-class="rs-button rs-button-primary">
type="submit" {{ editingVariable ? "Update" : "Add" }}
input-class="rs-button rs-button-primary"
>
{{ editingVariable ? 'Update' : 'Add' }}
</FormKit> </FormKit>
</div> </div>
</FormKit> </FormKit>
@ -188,8 +188,8 @@
</template> </template>
<script setup> <script setup>
import { ref, computed } from 'vue'; import { ref, computed } from "vue";
import { useVariableStore } from '~/stores/variableStore'; import { useVariableStore } from "~/stores/variableStore";
const variableStore = useVariableStore(); const variableStore = useVariableStore();
@ -197,11 +197,11 @@ const variableStore = useVariableStore();
const showAddVariable = ref(false); const showAddVariable = ref(false);
const editingVariable = ref(null); const editingVariable = ref(null);
const variableForm = ref({ const variableForm = ref({
name: '', name: "",
type: 'string', type: "string",
scope: 'process', scope: "process",
description: '', description: "",
isRequired: false isRequired: false,
}); });
// Computed // Computed
@ -209,7 +209,7 @@ const variables = computed(() => {
// This was only returning process variables, let's fix it to return both process and global variables // This was only returning process variables, let's fix it to return both process and global variables
const allVars = [ const allVars = [
...variableStore.getAllVariables.process, ...variableStore.getAllVariables.process,
...variableStore.getAllVariables.global ...variableStore.getAllVariables.global,
]; ];
return allVars; return allVars;
}); });
@ -229,11 +229,11 @@ const deleteVariable = (variable) => {
const resetForm = () => { const resetForm = () => {
variableForm.value = { variableForm.value = {
name: '', name: "",
type: 'string', type: "string",
scope: 'process', scope: "process",
description: '', description: "",
isRequired: false isRequired: false,
}; };
editingVariable.value = null; editingVariable.value = null;
}; };
@ -251,7 +251,7 @@ const saveVariable = async (formData) => {
type: formData.type, type: formData.type,
scope: formData.scope, scope: formData.scope,
description: formData.description, description: formData.description,
isRequired: formData.isRequired isRequired: formData.isRequired,
}; };
if (editingVariable.value) { if (editingVariable.value) {
@ -269,7 +269,7 @@ const saveVariable = async (formData) => {
// Close modal and reset form // Close modal and reset form
closeModal(); closeModal();
} catch (error) { } catch (error) {
console.error('Error saving variable:', error); console.error("Error saving variable:", error);
// You might want to show an error message to the user here // You might want to show an error message to the user here
} }
}; };
@ -287,4 +287,4 @@ const saveVariable = async (formData) => {
.variable-item:hover { .variable-item:hover {
@apply transform -translate-y-1; @apply transform -translate-y-1;
} }
</style> </style>

View File

@ -3,7 +3,7 @@
<div class="flex flex-col h-screen bg-gray-50"> <div class="flex flex-col h-screen bg-gray-50">
<!-- Header --> <!-- Header -->
<header <header
class="bg-gray-800 p-2 flex flex-wrap items-center justify-between text-white" class="bg-gray-800 p-2 flex flex-wrap items-center justify-between text-white min-h-[70px]"
> >
<div class="flex items-center mb-2 sm:mb-0 gap-4"> <div class="flex items-center mb-2 sm:mb-0 gap-4">
<Icon <Icon
@ -18,39 +18,47 @@
/> />
</div> </div>
<div class="flex flex-wrap items-center space-x-2"> <div class="flex flex-wrap items-center space-x-2">
<RsButton @click="navigateToBuilder" variant="primary" class="mr-2">
<Icon name="material-symbols:add" class="mr-2" />
Create New Form
</RsButton>
<h1 class="text-lg font-semibold">Manage Forms</h1> <h1 class="text-lg font-semibold">Manage Forms</h1>
</div> </div>
</header> </header>
<!-- Main content --> <!-- Main content -->
<div class="flex-1 overflow-auto p-6"> <div class="flex-1 overflow-auto p-6">
<div class="container mx-auto"> <div class="container mx-auto">
<!-- Search bar --> <!-- Header with title, search and create button -->
<div class="bg-white p-4 rounded-lg shadow-sm mb-6"> <div class="bg-white p-4 rounded-lg shadow-sm mb-6">
<div <div
class="flex flex-col md:flex-row md:items-center md:justify-between gap-4" class="flex flex-col md:flex-row md:items-center md:justify-between gap-4"
> >
<h2 class="text-xl font-medium">Saved Forms</h2> <h2 class="text-xl font-medium">Saved Forms</h2>
<div class="relative w-full md:w-64"> <div class="flex space-x-4 items-center">
<input <div class="relative w-64">
type="text" <input
v-model="searchQuery" type="text"
placeholder="Search forms..." v-model="searchQuery"
class="w-full px-3 py-2 pl-9 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Search forms..."
/> class="w-full px-3 py-2 pl-9 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
<Icon />
name="material-symbols:search" <Icon
class="absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400" name="material-symbols:search"
/> class="absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400"
/>
</div>
<RsButton
@click="navigateToBuilder"
variant="primary"
class="flex items-center whitespace-nowrap"
>
<Icon name="material-symbols:add" class="mr-2" />
Create Form
</RsButton>
</div> </div>
</div> </div>
</div> </div>
<!-- Forms list --> <!-- Forms list -->
<div class="bg-white rounded-lg shadow-sm"> <div class="bg-white rounded-lg shadow-sm">
<div <div
v-if="formStore.savedForms.length === 0" v-if="formStore.savedForms.length === 0"
@ -62,47 +70,35 @@
/> />
<p class="text-lg font-medium">No forms found</p> <p class="text-lg font-medium">No forms found</p>
<p class="text-sm mb-4">Start by creating a new form</p> <p class="text-sm mb-4">Start by creating a new form</p>
<RsButton @click="navigateToBuilder" variant="primary"
>Create Form</RsButton
>
</div> </div>
<div v-else> <div v-else>
<RsTable <RsTable
:field="['Form Name', 'Created', 'Actions']"
:data="filteredForms" :data="filteredForms"
:options="{ striped: true, hover: true }" :options="{
:optionsAdvanced="{ sortable: true, responsive: true }" variant: 'default',
}"
> >
<template #cell-2="{ row, index }"> <template v-slot:formName="data">
<div class="flex space-x-2 justify-end"> <div class="font-medium">{{ data.text }}</div>
<RsButton </template>
@click="editForm(row.id)" <template v-slot:created="data">
size="sm" <div>{{ data.text }}</div>
variant="tertiary" </template>
> <template v-slot:action="data">
<template #prepend> <div class="flex space-x-2">
<Icon <Icon
name="material-symbols:edit-outline" name="material-symbols:edit-outline-rounded"
class="w-4 h-4" class="text-primary hover:text-primary/90 cursor-pointer"
/> size="22"
</template> @click="editForm(data.value.id)"
Edit ></Icon>
</RsButton> <Icon
<RsButton name="material-symbols:delete-outline"
@click="deleteForm(row.id)" class="text-red-500 hover:text-red-400 cursor-pointer"
size="sm" size="22"
variant="tertiary" @click="deleteForm(data.value.id)"
class="text-red-500" ></Icon>
>
<template #prepend>
<Icon
name="material-symbols:delete-outline"
class="w-4 h-4"
/>
</template>
Delete
</RsButton>
</div> </div>
</template> </template>
</RsTable> </RsTable>
@ -144,6 +140,33 @@
</div> </div>
</template> </template>
</RsModal> </RsModal>
<!-- Delete Confirmation Modal -->
<RsModal v-model="showDeleteModal" title="Delete Form" size="md">
<div class="p-4">
<div class="flex items-center mb-4">
<Icon
name="material-symbols:delete-forever-outline"
class="text-red-500 w-8 h-8 mr-3"
/>
<div>
<h3 class="font-medium text-lg">Delete Form</h3>
<p class="text-gray-600">
Are you sure you want to delete this form? This action cannot be
undone.
</p>
</div>
</div>
</div>
<template #footer>
<div class="flex justify-end gap-2">
<RsButton @click="cancelDelete" variant="tertiary"> Cancel </RsButton>
<RsButton @click="confirmDelete" variant="danger">
Delete Form
</RsButton>
</div>
</template>
</RsModal>
</div> </div>
</template> </template>
@ -168,15 +191,17 @@ try {
} catch (error) { } catch (error) {
// Create a simple toast object if composable is not available // Create a simple toast object if composable is not available
toast = { toast = {
success: (msg) => console.log('Success:', msg), success: (msg) => console.log("Success:", msg),
error: (msg) => console.error('Error:', msg), error: (msg) => console.error("Error:", msg),
info: (msg) => console.info('Info:', msg), info: (msg) => console.info("Info:", msg),
warning: (msg) => console.warn('Warning:', msg) warning: (msg) => console.warn("Warning:", msg),
}; };
} }
const searchQuery = ref(""); const searchQuery = ref("");
const showUnsavedChangesModal = ref(false); const showUnsavedChangesModal = ref(false);
const showDeleteModal = ref(false);
const formToDelete = ref(null);
// Initialize and load forms // Initialize and load forms
onMounted(async () => { onMounted(async () => {
@ -191,11 +216,13 @@ onMounted(async () => {
// Format date for display // Format date for display
const formatDate = (dateString) => { const formatDate = (dateString) => {
const date = new Date(dateString); const date = new Date(dateString);
return date.toLocaleDateString("en-US", { return date
year: "numeric", .toLocaleDateString("en-US", {
month: "short", year: "numeric",
day: "numeric", month: "short",
}); day: "numeric",
})
.replace(",", "");
}; };
// Filtered and formatted forms for table display // Filtered and formatted forms for table display
@ -205,11 +232,19 @@ const filteredForms = computed(() => {
if (!searchQuery.value) return true; if (!searchQuery.value) return true;
return form.name.toLowerCase().includes(searchQuery.value.toLowerCase()); return form.name.toLowerCase().includes(searchQuery.value.toLowerCase());
}) })
.map((form) => ({ .map((form) => {
id: form.id, console.log(form);
"Form Name": form.name,
Created: formatDate(form.createdAt), // Get form name or fallback to the ID if name is not available
})); const formName = form.name ? form.name : form.id;
return {
id: form.id,
formName: formName,
created: form.createdAt ? formatDate(form.createdAt) : "New Form",
action: { id: form.id }, // Pass the ID to the action slot
};
});
}); });
// Navigation and action handlers // Navigation and action handlers
@ -242,20 +277,33 @@ const editForm = async (formId) => {
} }
}; };
const deleteForm = async (formId) => { const deleteForm = (formId) => {
if (confirm("Are you sure you want to delete this form?")) { formToDelete.value = formId;
try { showDeleteModal.value = true;
// Call the API to delete the form };
await formStore.deleteForm(formId);
const cancelDelete = () => {
// Refresh the forms list showDeleteModal.value = false;
await formStore.loadSavedForms(); formToDelete.value = null;
};
toast.success("Form deleted successfully");
} catch (error) { const confirmDelete = async () => {
console.error("Error deleting form:", error); if (!formToDelete.value) return;
toast.error("Failed to delete form: " + (error.message || "Unknown error"));
} try {
// Call the API to delete the form
await formStore.deleteForm(formToDelete.value);
// Refresh the forms list
await formStore.loadSavedForms();
toast.success("Form deleted successfully");
} catch (error) {
console.error("Error deleting form:", error);
toast.error("Failed to delete form: " + (error.message || "Unknown error"));
} finally {
showDeleteModal.value = false;
formToDelete.value = null;
} }
}; };
</script> </script>