1- import React , { useState } from "react" ;
1+ import { useState } from "react" ;
22import { observer } from "mobx-react" ;
33import { Controller , useForm } from "react-hook-form" ;
44import { CircleCheck } from "lucide-react" ;
@@ -71,47 +71,46 @@ export const WorkspaceCreateStep = observer(function WorkspaceCreateStep({
7171 const handleCreateWorkspace = async ( formData : IWorkspace ) => {
7272 if ( isSubmitting ) return ;
7373
74- await workspaceService
75- . workspaceSlugCheck ( formData . slug )
76- . then ( async ( res ) => {
77- if ( res . status === true && ! RESTRICTED_URLS . includes ( formData . slug ) ) {
78- setSlugError ( false ) ;
79- await createWorkspace ( formData )
80- . then ( async ( workspaceResponse ) => {
81- setToast ( {
82- type : TOAST_TYPE . SUCCESS ,
83- title : t ( "workspace_creation.toast.success.title" ) ,
84- message : t ( "workspace_creation.toast.success.message" ) ,
85- } ) ;
86- captureSuccess ( {
87- eventName : WORKSPACE_TRACKER_EVENTS . create ,
88- payload : { slug : formData . slug } ,
89- } ) ;
90- await fetchWorkspaces ( ) ;
91- await completeStep ( workspaceResponse . id ) ;
92- onComplete ( formData . organization_size === "Just myself" ) ;
93- } )
94- . catch ( ( ) => {
95- captureError ( {
96- eventName : WORKSPACE_TRACKER_EVENTS . create ,
97- payload : { slug : formData . slug } ,
98- error : new Error ( "Error creating workspace" ) ,
99- } ) ;
100- setToast ( {
101- type : TOAST_TYPE . ERROR ,
102- title : t ( "workspace_creation.toast.error.title" ) ,
103- message : t ( "workspace_creation.toast.error.message" ) ,
104- } ) ;
105- } ) ;
106- } else setSlugError ( true ) ;
107- } )
108- . catch ( ( ) =>
109- setToast ( {
110- type : TOAST_TYPE . ERROR ,
111- title : t ( "workspace_creation.toast.error.title" ) ,
112- message : t ( "workspace_creation.toast.error.message" ) ,
113- } )
114- ) ;
74+ try {
75+ const res = ( await workspaceService . workspaceSlugCheck ( formData . slug ) ) as { status : boolean } ;
76+ if ( res . status === true && ! RESTRICTED_URLS . includes ( formData . slug ) ) {
77+ setSlugError ( false ) ;
78+ try {
79+ const workspaceResponse = await createWorkspace ( formData ) ;
80+ setToast ( {
81+ type : TOAST_TYPE . SUCCESS ,
82+ title : t ( "workspace_creation.toast.success.title" ) ,
83+ message : t ( "workspace_creation.toast.success.message" ) ,
84+ } ) ;
85+ captureSuccess ( {
86+ eventName : WORKSPACE_TRACKER_EVENTS . create ,
87+ payload : { slug : formData . slug } ,
88+ } ) ;
89+ await fetchWorkspaces ( ) ;
90+ await completeStep ( workspaceResponse . id ) ;
91+ onComplete ( formData . organization_size === "Just myself" ) ;
92+ } catch {
93+ captureError ( {
94+ eventName : WORKSPACE_TRACKER_EVENTS . create ,
95+ payload : { slug : formData . slug } ,
96+ error : new Error ( "Error creating workspace" ) ,
97+ } ) ;
98+ setToast ( {
99+ type : TOAST_TYPE . ERROR ,
100+ title : t ( "workspace_creation.toast.error.title" ) ,
101+ message : t ( "workspace_creation.toast.error.message" ) ,
102+ } ) ;
103+ }
104+ } else {
105+ setSlugError ( true ) ;
106+ }
107+ } catch {
108+ setToast ( {
109+ type : TOAST_TYPE . ERROR ,
110+ title : t ( "workspace_creation.toast.error.title" ) ,
111+ message : t ( "workspace_creation.toast.error.message" ) ,
112+ } ) ;
113+ }
115114 } ;
116115
117116 const completeStep = async ( workspaceId : string ) => {
@@ -136,7 +135,12 @@ export const WorkspaceCreateStep = observer(function WorkspaceCreateStep({
136135 ) ;
137136 }
138137 return (
139- < form className = "flex flex-col gap-10" onSubmit = { handleSubmit ( handleCreateWorkspace ) } >
138+ < form
139+ className = "flex flex-col gap-10"
140+ onSubmit = { ( e ) => {
141+ void handleSubmit ( handleCreateWorkspace ) ( e ) ;
142+ } }
143+ >
140144 < CommonOnboardingHeader title = "Create your workspace" description = "All your work — unified." />
141145 < div className = "flex flex-col gap-8" >
142146 < div className = "flex flex-col gap-2" >
@@ -181,6 +185,7 @@ export const WorkspaceCreateStep = observer(function WorkspaceCreateStep({
181185 "border-red-500" : errors . name ,
182186 }
183187 ) }
188+ // eslint-disable-next-line jsx-a11y/no-autofocus
184189 autoFocus
185190 />
186191 </ div >
0 commit comments