11import React , { useState } from 'react' ;
22import { Database } from 'cbl-reactnative' ;
3- import { SafeAreaView , ScrollView , StyleSheet , Text } from 'react-native' ;
3+ import { SafeAreaView , ScrollView , StyleSheet } from 'react-native' ;
44import { useStyleScheme } from '@/components/Themed/Themed' ;
55import ReplicatorConfigGeneralForm from '@/components/ReplicationConfigGeneralForm/ReplicatorConfigGeneralForm' ;
66import ReplicatorAuthenticationForm from '@/components/ReplicatorAuthenticationForm/ReplicatorAuthenticationForm' ;
77import ReplicatorConfigCollectionForm from '@/components/ReplicationConfigCollectionForm/ReplicatorConfigCollectionForm' ;
88import ResultListView from '@/components/ResultsListView/ResultsListView' ;
99import { useNavigation } from '@react-navigation/native' ;
10- import { useRouter } from 'expo-router' ;
1110import useNavigationBarTitleOption from '@/hooks/useNativgationBarTitle' ;
1211
1312export default function ReplicationConfigCreateScreen ( ) {
13+ const styles = useStyleScheme ( ) ;
1414 const navigation = useNavigation ( ) ;
1515 useNavigationBarTitleOption ( 'Add Replicator Config' , navigation ) ;
16- //general form
1716 const [ replicatorType , setReplicatorType ] = useState < string > ( '' ) ;
1817 const [ connectionString , setConnectionString ] = useState < string > ( '' ) ;
1918 const [ heartbeat , setHeartbeat ] = useState < string > ( '300' ) ;
@@ -25,19 +24,16 @@ export default function ReplicationConfigCreateScreen() {
2524 useState < boolean > ( false ) ;
2625 const [ acceptOnlySelfSignedCerts , setAcceptOnlySelfSignedCerts ] =
2726 useState < boolean > ( false ) ;
28- //used for authentication type and authentication fields
2927 const [ selectedAuthenticationType , setSelectedAuthenticationType ] =
3028 useState < string > ( '' ) ;
3129 const [ username , setUsername ] = useState < string > ( '' ) ;
3230 const [ password , setPassword ] = useState < string > ( '' ) ;
3331 const [ sessionId , setSessionId ] = useState < string > ( '' ) ;
3432 const [ cookieName , setCookieName ] = useState < string > ( '' ) ;
35- //used for displaying result messages
3633 const [ resultMessages , setResultMessages ] = useState < string [ ] > ( [ ] ) ;
3734
3835 function reset ( ) {
3936 setConnectionString ( '' ) ;
40- //setHeaders('');
4137 setHeartbeat ( '60' ) ;
4238 setMaxAttempts ( '0' ) ;
4339 setMaxWaitTime ( '300' ) ;
@@ -62,18 +58,31 @@ export default function ReplicationConfigCreateScreen() {
6258 collections : string [ ]
6359 ) : Promise < void > {
6460 try {
65- //const collection = await defaultCollection(database);
66- //return [
67- // `Found Collection: <${collection.fullName()}> in Database: <${collection.database.getName()}>`,
68- //];
61+ if ( replicatorType === '' ) {
62+ setResultMessages ( [ 'Replicator Type is required' ] ) ;
63+ return ;
64+ }
65+ if ( selectedAuthenticationType === '' ) {
66+ setResultMessages ( [ 'Authentication Type is required' ] ) ;
67+ return ;
68+ }
69+ if ( scopeName === '' ) {
70+ setResultMessages ( [ 'Scope Name is required' ] ) ;
71+ return ;
72+ }
73+ if ( collections . length === 0 ) {
74+ setResultMessages ( [ 'At least one collection is required' ] ) ;
75+ return ;
76+ }
6977 } catch ( error ) {
7078 // @ts -ignore
7179 return [ error . message ] ;
7280 }
7381 }
7482
75- function updateResultMessage ( messages : string [ ] ) { }
76- const styles = useStyleScheme ( ) ;
83+ function updateResultMessage ( messages : string [ ] ) {
84+ setResultMessages ( ( prev ) => [ ...prev , ...messages ] ) ;
85+ }
7786
7887 return (
7988 < SafeAreaView style = { styles . container } >
0 commit comments