'use client'; import { zodResolver } from '@hookform/resolvers/zod'; import { Alert, AlertDescription, Button, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, Input, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Stepper, StepperItem, Textarea, } from '@sonr.io/ui'; import { Loader2 } from 'lucide-react'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; import * as z from 'zod'; const serviceSchema = z.object({ name: z.string().min(3, 'Service name must be at least 3 characters'), description: z.string().min(10, 'Description must be at least 10 characters'), domain: z.string().url('Must be a valid domain'), category: z.string().min(1, 'Please select a category'), permissions: z.array(z.string()).min(1, 'Select at least one permission'), }); type ServiceFormData = z.infer; interface ServiceRegistrationFormProps { onSuccess?: () => void; } export function ServiceRegistrationForm({ onSuccess }: ServiceRegistrationFormProps) { const [isSubmitting, setIsSubmitting] = useState(false); const [currentStep, setCurrentStep] = useState(0); const [error, setError] = useState(null); const form = useForm({ resolver: zodResolver(serviceSchema), defaultValues: { name: '', description: '', domain: '', category: '', permissions: [], }, }); const onSubmit = async (data: ServiceFormData) => { setIsSubmitting(true); setError(null); try { // TODO: Implement actual service registration API call const response = await fetch('/api/services', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data), }); if (!response.ok) { throw new Error('Failed to register service'); } onSuccess?.(); } catch (err) { setError(err instanceof Error ? err.message : 'An error occurred'); } finally { setIsSubmitting(false); } }; const steps = [ { title: 'Basic Info', description: 'Service name and description' }, { title: 'Domain', description: 'Configure domain verification' }, { title: 'Permissions', description: 'Set required permissions' }, ]; return (
{error && ( {error} )}
{/* Step 1: Basic Info */}
( Service Name A unique name for your service )} /> ( Description