@@ -129,6 +129,18 @@ const EditProfileScreen = () => {
129129 }
130130 } ;
131131
132+ const isValidUrl = ( url ?: string | null ) => {
133+ if ( ! url ) {
134+ return false ;
135+ }
136+ try {
137+ new URL ( url ) ;
138+ return true ;
139+ } catch {
140+ return false ;
141+ }
142+ } ;
143+
132144 // const takePhoto = async () => {
133145 // const hasPermission = await requestCameraPermissions();
134146 // if (!hasPermission) return;
@@ -150,6 +162,13 @@ const EditProfileScreen = () => {
150162 } ;
151163
152164 const handleFormSubmit = useCallback ( async ( ) => {
165+ if ( ! isValidUrl ( formData . websiteUrl ) && formData . websiteUrl ) {
166+ const errorMessage = 'Please enter a valid website URL' ;
167+ setError ( errorMessage ) ;
168+ setLoading ( false ) ;
169+ return ;
170+ }
171+
153172 try {
154173 setLoading ( true ) ;
155174 clearError ( ) ;
@@ -224,14 +243,6 @@ const EditProfileScreen = () => {
224243 ) ;
225244 }
226245
227- if ( error ) {
228- return (
229- < View style = { styles . centerContainer } >
230- < Text style = { styles . errorContainer } > Error: { error } </ Text >
231- </ View >
232- ) ;
233- }
234-
235246 return (
236247 < KeyboardAvoidingView
237248 behavior = "padding"
@@ -296,9 +307,11 @@ const EditProfileScreen = () => {
296307 value = { formData . websiteUrl }
297308 label = "Website"
298309 onChangeText = { ( value ) => {
299- setFormData ( ( prev ) => ( { ...prev , [ 'displayName ' ] : value } ) ) ;
310+ setFormData ( ( prev ) => ( { ...prev , [ 'websiteUrl ' ] : value } ) ) ;
300311 setFormDataChanged ( true ) ;
301312 } }
313+ autoCapitalize = "none"
314+ error = { error || undefined }
302315 />
303316 < Pressable onPress = { openDatePicker } >
304317 < TextInput
@@ -381,6 +394,14 @@ const EditProfileScreen = () => {
381394 themeVariant = { theme }
382395 />
383396 ) }
397+
398+ { error && (
399+ < View style = { styles . centerContainer } >
400+ < Text style = { styles . errorContainer } className = "text-destructive" >
401+ Error: { error }
402+ </ Text >
403+ </ View >
404+ ) }
384405 </ ScrollView >
385406 </ View >
386407 </ KeyboardAvoidingView >
0 commit comments