diff --git a/frontend/src/components/step-library/StepForm.tsx b/frontend/src/components/step-library/StepForm.tsx index 59a4052a..11902da2 100644 --- a/frontend/src/components/step-library/StepForm.tsx +++ b/frontend/src/components/step-library/StepForm.tsx @@ -8,6 +8,8 @@ interface StepFormProps { onSubmit: (data: StepCreate) => void onCancel: () => void initialData?: Partial + submitLabel?: string + isSubmitting?: boolean } const stepTypeOptions = [ @@ -16,7 +18,7 @@ const stepTypeOptions = [ { value: 'solution', label: 'Solution', icon: CheckCircle, description: 'Resolution endpoint' } ] as const -export function StepForm({ onSubmit, onCancel, initialData }: StepFormProps) { +export function StepForm({ onSubmit, onCancel, initialData, submitLabel, isSubmitting }: StepFormProps) { // Form state const [stepType, setStepType] = useState<'decision' | 'action' | 'solution'>( initialData?.step_type || 'action' @@ -376,9 +378,10 @@ export function StepForm({ onSubmit, onCancel, initialData }: StepFormProps) { diff --git a/frontend/src/components/step-library/StepFormModal.tsx b/frontend/src/components/step-library/StepFormModal.tsx new file mode 100644 index 00000000..58a7a95c --- /dev/null +++ b/frontend/src/components/step-library/StepFormModal.tsx @@ -0,0 +1,89 @@ +import { useState } from 'react' +import { X } from 'lucide-react' +import { stepsApi } from '@/api/steps' +import { StepForm } from './StepForm' +import type { Step, StepCreate } from '@/types/step' + +interface StepFormModalProps { + isOpen: boolean + onClose: () => void + onSuccess: (step: Step) => void + editingStep?: Step | null // full Step (parent fetches before opening), null/undefined = create mode +} + +export function StepFormModal({ isOpen, onClose, onSuccess, editingStep }: StepFormModalProps) { + const [isSubmitting, setIsSubmitting] = useState(false) + const [error, setError] = useState(null) + + if (!isOpen) return null + + const isEditMode = !!editingStep + + const handleSubmit = async (data: StepCreate) => { + setIsSubmitting(true) + setError(null) + try { + let result: Step + if (isEditMode && editingStep) { + result = await stepsApi.update(editingStep.id, data) + } else { + result = await stepsApi.create(data) + } + onSuccess(result) + } catch (err) { + console.error('Failed to save step:', err) + setError('Failed to save step. Please try again.') + } finally { + setIsSubmitting(false) + } + } + + // Build initialData from full Step including content + const initialData = editingStep ? { + title: editingStep.title, + step_type: editingStep.step_type, + content: editingStep.content, + visibility: editingStep.visibility, + category_id: editingStep.category_id, + tags: editingStep.tags, + } : undefined + + return ( +
+
+ {/* Header */} +
+

+ {isEditMode ? 'Edit Step' : 'Create Step'} +

+ +
+ + {/* Error */} + {error && ( +
+ {error} +
+ )} + + {/* Body */} +
+ +
+
+
+ ) +}