@@ -28,15 +28,16 @@ import { Input } from '@/components/ui/input';
2828import type { CreateWebsiteData , Website } from '@/hooks/use-websites' ;
2929import { useCreateWebsite , useUpdateWebsite } from '@/hooks/use-websites' ;
3030
31+ const domainRegex =
32+ / ^ (?: [ a - z A - Z 0 - 9 ] (?: [ a - z A - Z 0 - 9 - ] { 0 , 61 } [ a - z A - Z 0 - 9 ] ) ? \. ) + [ a - z A - Z ] { 2 , 63 } $ / ;
33+ const wwwRegex = / ^ w w w \. / ;
34+
3135const formSchema = z . object ( {
3236 name : z . string ( ) . min ( 1 , 'Name is required' ) ,
3337 domain : z
3438 . string ( )
3539 . min ( 1 , 'Domain is required' )
36- . regex (
37- / ^ (?: [ a - z A - Z 0 - 9 ] (?: [ a - z A - Z 0 - 9 - ] { 0 , 61 } [ a - z A - Z 0 - 9 ] ) ? \. ) + [ a - z A - Z ] { 2 , 63 } $ / ,
38- 'Invalid domain format'
39- ) ,
40+ . regex ( domainRegex , 'Invalid domain format' ) ,
4041} ) ;
4142
4243type FormData = z . infer < typeof formSchema > ;
@@ -90,15 +91,19 @@ export function WebsiteDialog({
9091 id : website . id ,
9192 name : formData . name ,
9293 } ) ;
93- if ( onSave ) onSave ( result ) ;
94+ if ( onSave ) {
95+ onSave ( result ) ;
96+ }
9497 toast . success ( 'Website updated successfully!' ) ;
9598 } else {
9699 const result = await createWebsiteMutation . mutateAsync ( submissionData ) ;
97- if ( onSave ) onSave ( result ) ;
100+ if ( onSave ) {
101+ onSave ( result ) ;
102+ }
98103 toast . success ( 'Website created successfully!' ) ;
99104 }
100105 onOpenChange ( false ) ;
101- } catch ( error : any ) {
106+ } catch ( error ) {
102107 const message =
103108 error . data ?. code === 'CONFLICT'
104109 ? 'A website with this domain already exists.'
@@ -165,9 +170,11 @@ export function WebsiteDialog({
165170 ) {
166171 try {
167172 domain = new URL ( domain ) . hostname ;
168- } catch { }
173+ } catch {
174+ // Do nothing
175+ }
169176 }
170- field . onChange ( domain . replace ( / ^ w w w \. / , '' ) ) ;
177+ field . onChange ( domain . replace ( wwwRegex , '' ) ) ;
171178 } }
172179 />
173180 </ div >
0 commit comments