diff --git a/src/pages/admin/AdminRegistrationBuilder.js b/src/pages/admin/AdminRegistrationBuilder.js
index a119297..5a11d0d 100644
--- a/src/pages/admin/AdminRegistrationBuilder.js
+++ b/src/pages/admin/AdminRegistrationBuilder.js
@@ -19,12 +19,6 @@ import {
DialogTitle,
DialogFooter,
} from '../../components/ui/dialog';
-import {
- Accordion,
- AccordionContent,
- AccordionItem,
- AccordionTrigger,
-} from '../../components/ui/accordion';
import { toast } from 'sonner';
import api from '../../utils/api';
import {
@@ -45,13 +39,9 @@ import {
AlignLeft,
Upload,
Lock,
- ChevronUp,
- ChevronDown,
Settings,
Zap,
- Copy,
- X,
- Grip
+ X
} from 'lucide-react';
// Field type icons
@@ -192,6 +182,7 @@ const AdminRegistrationBuilder = () => {
// Get current step
const currentStep = sortedSteps.find((s) => s.id === selectedStep);
+ const currentStepIndex = sortedSteps.findIndex((s) => s.id === selectedStep);
// Get sections for current step
const sortedSections = currentStep?.sections?.sort((a, b) => a.order - b.order) || [];
@@ -335,13 +326,13 @@ const AdminRegistrationBuilder = () => {
};
// Add field
- const handleAddField = () => {
- if (!selectedSection) {
+ const handleAddField = (sectionId = selectedSection) => {
+ if (!sectionId) {
toast.error('Please select a section first');
return;
}
- const section = currentStep?.sections?.find((s) => s.id === selectedSection);
+ const section = currentStep?.sections?.find((s) => s.id === sectionId);
const fieldCount = section?.fields?.length || 0;
const newField = {
@@ -364,7 +355,7 @@ const AdminRegistrationBuilder = () => {
? {
...s,
sections: s.sections.map((sec) =>
- sec.id === selectedSection
+ sec.id === sectionId
? { ...sec, fields: [...(sec.fields || []), newField] }
: sec
),
@@ -373,13 +364,14 @@ const AdminRegistrationBuilder = () => {
),
}));
+ setSelectedSection(sectionId);
setSelectedField(newField.id);
setAddFieldDialogOpen(false);
};
// Delete field
- const handleDeleteField = (fieldId) => {
- const section = currentStep?.sections?.find((s) => s.id === selectedSection);
+ const handleDeleteField = (sectionId, fieldId) => {
+ const section = currentStep?.sections?.find((s) => s.id === sectionId);
const field = section?.fields?.find((f) => f.id === fieldId);
if (field?.is_fixed) {
@@ -398,7 +390,7 @@ const AdminRegistrationBuilder = () => {
? {
...s,
sections: s.sections.map((sec) =>
- sec.id === selectedSection
+ sec.id === sectionId
? {
...sec,
fields: sec.fields
@@ -418,7 +410,7 @@ const AdminRegistrationBuilder = () => {
};
// Update field
- const handleUpdateField = (fieldId, updates) => {
+ const handleUpdateField = (sectionId, fieldId, updates) => {
updateSchema((prev) => ({
...prev,
steps: prev.steps.map((s) =>
@@ -426,7 +418,7 @@ const AdminRegistrationBuilder = () => {
? {
...s,
sections: s.sections.map((sec) =>
- sec.id === selectedSection
+ sec.id === sectionId
? {
...sec,
fields: sec.fields.map((f) =>
@@ -441,10 +433,7 @@ const AdminRegistrationBuilder = () => {
}));
};
- // Get selected field data
- const selectedFieldData = currentStep?.sections
- ?.find((s) => s.id === selectedSection)
- ?.fields?.find((f) => f.id === selectedField);
+
if (loading) {
return (
@@ -493,66 +482,40 @@ const AdminRegistrationBuilder = () => {
)}
{/* Main Builder Layout */}
- {/* Left Sidebar - Steps & Sections */}
-
-
-
-
Steps
-
-
+
+
+
+
+
Steps
+
+
-
- {sortedSteps.map((step, index) => (
-
{
- setSelectedStep(step.id);
- setSelectedSection(null);
- setSelectedField(null);
- }}
- >
-
-
- {/* Mod Buttons */}
-
- {/*
+
+ {sortedSteps.map((step, index) => (
+
{
+ setSelectedStep(step.id);
+ setSelectedSection(null);
+ setSelectedField(null);
+ }}
+ >
+
+
+ Step {index + 1}
+ {/* {step.title || 'Untitled Step'} */}
+
*/}
-
-
-
- ))}
-
+ ))}
- {/* Sections for selected step */}
- {currentStep && (
- <>
-
-
Sections
-
-
+ {sortedSteps.length === 0 && (
+
+ No steps yet. Click "Add Step" to get started.
+
+ )}
+
-
- {sortedSections.map((section) => {
- const sortedFields = section.fields?.sort((a, b) => a.order - b.order) || [];
+ {/* Sections for selected step */}
+ {currentStep && (
+
+
+
+
+ Step {currentStepIndex + 1}: {currentStep?.title || 'Untitled Step'}
+
+ {currentStep.description && (
+
{currentStep.description}
+ )}
+
+
+
- return (
{
- setSelectedSection(section.id);
- setSelectedField(null);
- }}
- >
-
-
-
{section.title}
- {section.description && (
-
{section.description}
- )}
-
+
+ {sortedSections.map((section) => {
+ const sortedFields = section.fields?.sort((a, b) => a.order - b.order) || [];
-
-
-
- {/* Right Sidebar - Field Properties */}
-
-
- Edit Options
-
- {selectedFieldData ? (
-
- {/* Field ID */}
-
-
-
- {selectedFieldData.id}
-
+ )}
-
- {/* Label */}
-
-
- handleUpdateField(selectedField, { label: e.target.value })}
- disabled={selectedFieldData.is_fixed}
- />
-
-
- {/* Type */}
-
-
-
-
-
- {/* Required */}
-
-
- handleUpdateField(selectedField, { required: checked })
- }
- disabled={selectedFieldData.is_fixed}
- />
-
-
-
- {/* Width */}
-
-
-
-
-
- {/* Placeholder */}
- {['text', 'email', 'phone', 'textarea'].includes(selectedFieldData.type) && (
-
-
-
- handleUpdateField(selectedField, { placeholder: e.target.value })
- }
- />
-
- )}
-
- {/* Options for dropdown/radio/multiselect */}
- {['dropdown', 'radio', 'multiselect'].includes(selectedFieldData.type) && (
-
-
-
- {(selectedFieldData.options || []).map((option, idx) => (
-
- {
- const newOptions = [...selectedFieldData.options];
- newOptions[idx] = {
- ...newOptions[idx],
- label: e.target.value,
- value: e.target.value.toLowerCase().replace(/\s+/g, '_'),
- };
- handleUpdateField(selectedField, { options: newOptions });
- }}
- placeholder="Option label"
- />
- {
- const newOptions = selectedFieldData.options.filter(
- (_, i) => i !== idx
- );
- handleUpdateField(selectedField, { options: newOptions });
- }}
- >
-
-
-
- ))}
-
{
- const newOptions = [
- ...(selectedFieldData.options || []),
- { value: `option_${Date.now()}`, label: 'New Option' },
- ];
- handleUpdateField(selectedField, { options: newOptions });
- }}
- >
-
- Add Option
-
-
-
- )}
-
- {/* Mapping */}
-
-
-
- handleUpdateField(selectedField, { mapping: e.target.value })
- }
- placeholder="Leave empty for custom data"
- disabled={selectedFieldData.is_fixed}
- />
-
- Maps to User model field. Empty = stored in custom_registration_data
-
-
-
- {selectedFieldData.is_fixed && (
-
- This is a fixed field and cannot be removed or have its core properties changed.
-
- )}
-
- ) : (
-
- Select a field to edit its properties
)}
- {/* Conditional Rules */}
-
+
+
+
+
@@ -897,6 +848,7 @@ const AdminRegistrationBuilder = () => {
{/* Add Step Dialog */}
+