(e: React.FormEvent)
| 60 | } |
| 61 | |
| 62 | const handleSubmit = async (e: React.FormEvent) => { |
| 63 | e.preventDefault() |
| 64 | |
| 65 | const nameValidationError = validateName(formData.name) |
| 66 | if (nameValidationError) { |
| 67 | setNameError(nameValidationError) |
| 68 | toast({ |
| 69 | title: 'Error', |
| 70 | description: nameValidationError, |
| 71 | variant: 'destructive', |
| 72 | }) |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | setIsLoading(true) |
| 77 | try { |
| 78 | const response = await fetch('/api/orgs', { |
| 79 | method: 'POST', |
| 80 | headers: { |
| 81 | 'Content-Type': 'application/json', |
| 82 | }, |
| 83 | body: JSON.stringify({ |
| 84 | name: formData.name, |
| 85 | description: formData.description, |
| 86 | }), |
| 87 | }) |
| 88 | |
| 89 | if (!response.ok) { |
| 90 | const error = await response.json() |
| 91 | throw new Error(error.error || 'Failed to create organization') |
| 92 | } |
| 93 | |
| 94 | const organization = await response.json() |
| 95 | |
| 96 | // Show success modal first, then navigate when user clicks "Get Started" |
| 97 | setCreatedOrganization(organization) |
| 98 | setSuccessModalOpen(true) |
| 99 | } catch (error) { |
| 100 | toast({ |
| 101 | title: 'Error', |
| 102 | description: |
| 103 | error instanceof Error |
| 104 | ? error.message |
| 105 | : 'Failed to create organization', |
| 106 | variant: 'destructive', |
| 107 | }) |
| 108 | } finally { |
| 109 | setIsLoading(false) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | const handleContinueToOrganization = () => { |
| 114 | if (createdOrganization) { |
no test coverage detected