Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2021
Kelas D
PT Gizi Sehat - Dietela
Dietela Mobile
Commits
83d913dc
Commit
83d913dc
authored
May 09, 2021
by
Doan Andreas Nathanael
Browse files
[GREEN] added nutritionist admin login
parent
5849c9d0
Pipeline
#75943
passed with stages
in 28 minutes and 1 second
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/scenes/auth/NutritionistAdminLogin/index.tsx
View file @
83d913dc
import
React
,
{
FC
}
from
'
react
'
;
import
{
Text
}
from
'
react-native
'
;
import
React
,
{
FC
,
useContext
,
useState
}
from
'
react
'
;
import
{
ScrollView
,
StyleSheet
,
Text
}
from
'
react-native
'
;
import
{
UserContext
}
from
'
provider
'
;
import
{
useForm
}
from
'
hooks
'
;
const
NutritionistAdminLogin
:
FC
=
()
=>
<
Text
>
Hello there
</
Text
>;
import
{
BigButton
,
Link
,
Toast
}
from
'
components/core
'
;
import
{
fieldValidation
,
initialValues
,
radioButtonGroups
,
textField
,
}
from
'
./schema
'
;
import
{
generateValidationSchema
}
from
'
utils/form
'
;
import
{
layoutStyles
}
from
'
styles
'
;
import
{
RadioButtonGroup
,
TextField
}
from
'
components/form
'
;
import
{
Section
}
from
'
components/layout
'
;
import
{
useNavigation
}
from
'
@react-navigation/core
'
;
import
*
as
ROUTES
from
'
constants/routes
'
;
const
isPasswordField
=
(
name
:
string
)
=>
name
===
'
password
'
;
const
NutritionistAdminLogin
:
FC
=
()
=>
{
const
{
login
}
=
useContext
(
UserContext
);
const
[
nonFieldError
,
setNonFieldError
]
=
useState
<
string
|
null
>
();
const
navigation
=
useNavigation
();
const
{
getTextInputProps
,
getFormFieldProps
,
handleSubmit
,
isSubmitting
,
setFieldError
,
}
=
useForm
({
initialValues
,
validationSchema
:
generateValidationSchema
(
fieldValidation
),
onSubmit
:
async
(
values
)
=>
{
const
response
=
await
login
(
values
);
if
(
!
response
.
success
)
{
const
error
=
response
.
error
;
setFieldError
(
'
email
'
,
error
.
email
);
setFieldError
(
'
password
'
,
error
.
password
);
setNonFieldError
(
error
.
non_field_errors
);
Toast
.
show
({
type
:
'
error
'
,
text1
:
'
Gagal login akun
'
,
text2
:
'
Terjadi kesalahan login. Silakan coba lagi
'
,
});
}
},
});
return
(
<
ScrollView
contentContainerStyle
=
{
layoutStyles
}
>
{
textField
.
map
(({
name
,
label
,
required
,
placeholder
},
i
)
=>
(
<
TextField
key
=
{
`field
${
i
}
`
}
label
=
{
label
}
required
=
{
required
}
placeholder
=
{
placeholder
}
{
...
getTextInputProps
(
name
)
}
secureTextEntry
=
{
isPasswordField
(
name
)
}
/>
))
}
{
radioButtonGroups
.
map
((
fieldProps
,
i
)
=>
(
<
RadioButtonGroup
{
...
fieldProps
}
{
...
getFormFieldProps
(
fieldProps
.
name
)
}
key
=
{
`radiobuttongroup
${
i
}
`
}
/>
))
}
{
nonFieldError
&&
(
<
Text
style
=
{
styles
.
nonfieldError
}
>
{
nonFieldError
}
</
Text
>
)
}
<
Section
>
<
BigButton
title
=
"login"
onPress
=
{
handleSubmit
}
loading
=
{
isSubmitting
}
testID
=
"timDietelaLogin"
/>
</
Section
>
<
Section
>
<
Link
title
=
"Login sebagai Pengguna"
onPress
=
{
()
=>
navigation
.
navigate
(
ROUTES
.
login
)
}
/>
</
Section
>
</
ScrollView
>
);
};
const
styles
=
StyleSheet
.
create
({
nonfieldError
:
{
color
:
'
red
'
},
});
export
default
NutritionistAdminLogin
;
Write
Preview
Supports
Markdown
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