Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
21_22-J 38
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 38
21_22-J 38
Commits
f183a4f7
Commit
f183a4f7
authored
Mar 25, 2022
by
W.D.R.P. Sandeepa
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'it18218640' into 'master'
It18218640 See merge request
!134
parents
3b48cb23
6b30a2aa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
7 deletions
+71
-7
frontend/src/screen/auth/Login.js
frontend/src/screen/auth/Login.js
+71
-7
No files found.
frontend/src/screen/auth/Login.js
View file @
f183a4f7
import
{
useNavigation
}
from
"
@react-navigation/native
"
;
import
Orientation
from
'
react-native-orientation-locker
'
;
import
React
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
SafeAreaView
,
ScrollView
,
View
,
StyleSheet
,
ImageBackground
,
Text
,
TextInput
,
TouchableOpacity
,
Image
}
from
"
react-native
"
;
const
isValidObjectField
=
(
obj
)
=>
{
return
Object
.
values
(
obj
).
every
(
value
=>
value
.
trim
());
}
const
updateError
=
(
error
,
stateUpdater
)
=>
{
stateUpdater
(
error
);
setTimeout
(
()
=>
{
stateUpdater
(
''
)
},
2500
);
}
const
isValidEmail
=
(
value
)
=>
{
const
regex
=
/^
\w
+@
[
a-zA-Z_
]
+
?\.[
a-zA-Z
]{2,3}
$/
;
return
regex
.
test
(
value
);
}
const
Login
=
()
=>
{
const
navigation
=
useNavigation
();
...
...
@@ -15,6 +31,46 @@ const Login = () => {
return
unsubscribe
;
},
[
navigation
]);
const
[
userInfo
,
setUserInfo
]
=
useState
({
email
:
''
,
password
:
''
,
});
const
{
email
,
password
}
=
userInfo
;
const
handleOnChangeText
=
(
value
,
fieldName
)
=>
{
setUserInfo
({
...
userInfo
,
[
fieldName
]:
value
});
// console.log(value, fieldName);
};
const
[
error
,
setError
]
=
useState
(
''
);
const
isValidForm
=
()
=>
{
if
(
!
isValidObjectField
(
userInfo
))
{
return
updateError
(
'
Required all fields!
'
,
setError
);
}
if
(
!
isValidEmail
(
email
)){
return
updateError
(
'
Invalid email !
'
,
setError
);
}
if
(
!
password
.
trim
()
||
password
.
length
<
8
){
return
updateError
(
'
Password is less than 8 characters !
'
,
setError
);
}
return
true
;
}
const
submitForm
=
()
=>
{
if
(
isValidForm
()){
()
=>
{
navigation
.
navigate
(
"
Start
"
)}
console
.
log
(
userInfo
);
}
}
return
(
<
SafeAreaView
>
<
ScrollView
>
...
...
@@ -25,16 +81,19 @@ const Login = () => {
<
/View
>
<
View
elevation
=
{
5
}
style
=
{
styles
.
main_container
}
>
<
Text
style
=
{
styles
.
main_title
}
>
Sign
In
<
/Text
>
{
error
?
(
<
Text
style
=
{{
color
:
'
red
'
,
fontSize
:
18
,
textAlign
:
'
center
'
}}
>
{
error
}
<
/Text>
)
: null
}
<
View
style
=
{
styles
.
form_input
}
>
<
TextInput
style
=
{
styles
.
text_input
}
placeholder
=
"
Enter Email
"
><
/TextInput
>
<
TextInput
value
=
{
email
}
autoCapitalize
=
"
none
"
onChangeText
=
{
value
=>
handleOnChangeText
(
value
,
'
email
'
)}
style
=
{
styles
.
text_input
}
placeholder
=
"
Enter Email
"
><
/TextInput
>
<
/View
>
<
View
style
=
{
styles
.
form_input
}
>
<
TextInput
keyboardType
=
"
visible-password
"
style
=
{
styles
.
text_input
}
placeholder
=
"
Enter Password
"
><
/TextInput
>
<
TextInput
value
=
{
password
}
autoCapitalize
=
"
none
"
secureTextEntry
onChangeText
=
{
value
=>
handleOnChangeText
(
value
,
'
password
'
)}
keyboardType
=
"
visible-password
"
style
=
{
styles
.
text_input
}
placeholder
=
"
Enter Password
"
><
/TextInput
>
<
/View
>
<
View
style
=
{
styles
.
form_input
}
>
<
TouchableOpacity
onPress
=
{
()
=>
{
navigation
.
navigate
(
"
Start
"
)}
}
style
=
{
styles
.
btn
}
>
<
TouchableOpacity
onPress
=
{
submitForm
}
style
=
{
styles
.
btn
}
>
<
Text
style
=
{
styles
.
btn_text
}
>
Sign
In
<
/Text
>
...
...
@@ -42,8 +101,8 @@ const Login = () => {
<
/View
>
<
View
style
=
{
styles
.
text_if
}
>
<
TouchableOpacity
onPress
=
{()
=>
{
navigation
.
navigate
(
"
Register
"
)}}
>
<
Text
style
=
{
styles
.
btn_text
}
>
<
TouchableOpacity
onPress
=
{()
=>
{
navigation
.
navigate
(
"
Register
"
)}}
>
<
Text
style
=
{
styles
.
btn_text
2
}
>
If
you
don
'
t have account? Sign Up
</Text>
</TouchableOpacity>
...
...
@@ -115,7 +174,12 @@ const styles = StyleSheet.create({
btn_text:{
fontSize: 20,
fontWeight:
'
bold
'
,
color:
'
#
000000
'
color:
'
#
000000
'
,
},btn_text2:{
fontSize: 20,
fontWeight:
'
bold
'
,
color:
'
#
000000
'
,
marginTop:-10
},
text_if:{
fontSize: 20,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment