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
2020
PPL-C
PPTI-Mobile Apps Monitoring Wabah Tuberkolosis
Neza-Mobile
Commits
64dbd0d9
Commit
64dbd0d9
authored
Apr 16, 2020
by
Nandhika Prayoga
Browse files
Merge branch 'coldfix-sprint_2' into 'staging'
Coldfix sprint 2 See merge request
!21
parents
8934e142
b34d72b5
Pipeline
#40676
passed with stage
in 4 minutes and 44 seconds
Changes
9
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/App/index.tsx
View file @
64dbd0d9
...
...
@@ -20,7 +20,7 @@ import {Dimensions} from 'react-native';
import
initialCacheState
,
{
CacheType
}
from
'
contexts/AppContext/cache
'
;
import
{
useMainService
,
LocalStorage
}
from
'
services
'
import
{
useMainService
}
from
'
services
'
import
Log
from
'
components/Log
'
;
const
StyledApp
=
styled
.
SafeAreaView
`
...
...
@@ -89,15 +89,13 @@ type CacheAction =
}
function
cacheReducer
(
oldCache
:
CacheType
,
action
:
CacheAction
):
CacheType
{
switch
(
action
.
type
)
{
case
CacheActionType
.
Update
:
return
{
...
oldCache
,
...
action
.
data
,
}
default
:
return
oldCache
if
(
action
.
type
===
CacheActionType
.
Update
)
{
return
{
...
oldCache
,
...
action
.
data
,
}
}
return
oldCache
}
const
App
=
()
=>
{
...
...
@@ -130,27 +128,16 @@ const App = () => {
};
useEffect
(()
=>
{
const
startFromHomePage
=
()
=>
{
navigatorRef
.
current
?.
reset
({
index
:
0
,
routes
:
[{
name
:
'
home
'
}]
})
}
const
startFromLoginPage
=
()
=>
{
navigatorRef
.
current
?.
reset
({
index
:
0
,
routes
:
[{
name
:
'
login
'
}]
})
}
if
(
token
)
{
const
getUser
=
async
()
=>
{
const
response
=
await
mainService
.
me
()
if
(
response
.
status
===
200
)
{
// Token is valid
setUser
(
response
.
data
)
startFromHomePage
()
// navigatorRef.current?.reset({
// index: 0,
// routes: [{name: 'home'}]
// });
}
else
{
// Token is not valid
setToken
(
''
)
...
...
@@ -158,7 +145,10 @@ const App = () => {
}
getUser
()
}
else
if
(
token
===
''
)
{
startFromLoginPage
()
// navigatorRef.current?.reset({
// index: 0,
// routes: [{name: 'login'}]
// });
}
},
[
token
])
...
...
src/components/CategoryButton/index.tsx
View file @
64dbd0d9
...
...
@@ -13,7 +13,7 @@ interface CategoryButtonProps {
name
:
string
,
value
?:
Value
,
options
:
Array
<
Option
>
,
onClick
?:
(
v
alue
:
Value
)
=>
void
,
onClick
?:
(
newV
alue
:
Value
)
=>
void
,
}
function
setIndex
(
options
:
Array
<
Option
>
,
value
:
Value
):
number
{
...
...
@@ -30,7 +30,7 @@ const CategoryButton = ({
name
,
value
,
options
,
onClick
=
(
value
:
Value
)
=>
{}
onClick
=
()
=>
{}
}:
CategoryButtonProps
)
=>
{
const
[
position
,
setPosition
]
=
useState
<
number
>
(
setIndex
(
options
,
value
))
...
...
@@ -63,7 +63,7 @@ const CategoryButton = ({
bold
=
{
true
}
borderRadius
=
{
4
}
height
=
{
30
}
onPress
=
{
value
=>
setPosition
(
setIndex
(
options
,
value
))
}
onPress
=
{
newValueFromSwitchSelector
=>
setPosition
(
setIndex
(
options
,
newValueFromSwitchSelector
))
}
></
SwitchSelector
>
</
Box
>
...
...
src/components/Log/index.tsx
View file @
64dbd0d9
...
...
@@ -85,10 +85,10 @@ const Log = () => {
if
(
!
isLoaded
)
{
return
(
<
Container
>
<
Modal
animationType
=
"fade"
transparent
=
{
true
}
visible
=
{
!
isLoaded
}
>
<
Modal
animationType
=
"fade"
transparent
=
{
true
}
visible
=
{
true
}
>
<
ModalContainer
>
<
ActivityIndicator
animating
=
{
!
isLoaded
}
animating
=
{
true
}
size
=
"large"
color
=
"#fff"
/>
...
...
src/helpers/hooks/useFormState/index.tsx
View file @
64dbd0d9
...
...
@@ -19,10 +19,10 @@ function selectFieldPattern(
return
/^
[
a-zA-Z
]
+$/
;
case
'
TEXTAREA
'
:
return
/^
[
a-zA-Z
\s\.]
+$/
;
case
'
EMAIL
'
:
return
/^
[\w
-.
]{1,}\@([\w]{1,}
.
){1,}[
a-z
]{2,4}
$/
;
case
'
PASSWORD
'
:
return
/
(?=
.*
\d)(?=
.*
[
a-z
])(?=
.*
[
A-Z
])\w{8,}
/
;
//
case 'EMAIL':
//
return /^[\w-.]{1,}\@([\w]{1,}.){1,}[a-z]{2,4}$/;
//
case 'PASSWORD':
//
return /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{8,}/;
case
'
NUMBER
'
:
return
/^
[
0-9
]
+$/
;
case
'
PHONE
'
:
...
...
src/scenes/ContactInvestigationFormStep1/index.tsx
View file @
64dbd0d9
...
...
@@ -12,7 +12,7 @@ import React, {useState, useEffect, useContext} from 'react';
import
styled
from
'
styled-components/native
'
;
import
{
useNavigation
}
from
'
@react-navigation/native
'
;
import
{
Field
,
Gap
,
Button
,
Table
,
Header
,
Text
,
Box
}
from
'
components
'
;
import
{
Field
,
Gap
,
Button
,
Table
,
Header
,
Box
}
from
'
components
'
;
import
{
AppContext
}
from
'
contexts
'
;
import
{
PositiveCase
}
from
'
contexts/AppContext/types
'
;
...
...
@@ -60,9 +60,8 @@ const ContactInvestigationFormStep1 = () => {
}
},
[
searchQuery
,
masterData
]);
const
fetchCases
=
async
(
page
:
number
)
=>
{
const
resp
=
await
global
.
services
.
main
.
listPositiveCases
(
page
);
console
.
log
(
resp
.
status
);
const
fetchCases
=
async
(
pageNumber
:
number
)
=>
{
const
resp
=
await
global
.
services
.
main
.
listPositiveCases
(
pageNumber
);
if
(
resp
.
status
==
200
)
{
const
data
=
resp
.
data
;
setNext
(
data
.
next
);
...
...
src/scenes/ContactInvestigationFormStep4/index.tsx
View file @
64dbd0d9
...
...
@@ -135,6 +135,7 @@ const ContactInvestigationFormStep4 = () => {
const
investigationResponse
=
formData
.
is_edit
?
await
main
.
editInvestigationCase
(
investigationCaseData
,
formData
.
revision_id
)
:
await
main
.
createInvestigationCase
(
investigationCaseData
);
console
.
log
(
investigationResponse
)
setIsLoading
(
false
);
global
.
setCache
(
initialCacheState
);
navigation
.
navigate
(
'
contact-investigation-finish
'
);
...
...
src/scenes/Home/index.tsx
View file @
64dbd0d9
import
React
,
{
useContext
,
useState
,
useEffect
}
from
'
react
'
;
import
React
,
{
useContext
}
from
'
react
'
;
import
{
useNavigation
}
from
'
@react-navigation/native
'
;
import
styled
from
'
styled-components/native
'
;
...
...
@@ -16,7 +16,6 @@ const Home = () => {
const
global
=
useContext
(
AppContext
);
const
headerFont
=
global
.
vh
*
0.033
;
const
subHeaderFont
=
global
.
vh
*
0.026
;
const
subContentFont
=
global
.
vh
*
0.022
;
return
(
<
Container
>
...
...
src/scenes/OfficerSignupForm/index.test.tsx
View file @
64dbd0d9
...
...
@@ -320,8 +320,8 @@ describe("OfficerSignupForm", () => {
expect
(
nameField
.
props
.
information
).
toBe
(
'
Nama tidak boleh kosong
'
);
expect
(
usernameField
.
props
.
information
).
toBe
(
'
Username tidak boleh kosong
'
);
expect
(
passwordField
.
props
.
information
).
toBe
(
'
Minimal 8 karakter dan mengandung huruf besar, kecil, dan angka
'
);
expect
(
emailField
.
props
.
information
).
toBe
(
'
Email harus memiliki format yang valid: example@mail.com
'
);
//
expect(passwordField.props.information).toBe('Minimal 8 karakter dan mengandung huruf besar, kecil, dan angka');
//
expect(emailField.props.information).toBe('Email harus memiliki format yang valid: example@mail.com');
expect
(
phoneField
.
props
.
information
).
toBe
(
'
No. HP harus terdiri dari 10-15 angka
'
);
expect
(
areaField
.
props
.
information
).
toBe
(
'
Lokasi cabang tidak boleh kosong
'
);
});
...
...
src/services/hooks/useMainService/index.tsx
View file @
64dbd0d9
...
...
@@ -4,12 +4,11 @@ import { API_MAIN_URL } from 'react-native-dotenv';
const
END_POINTS
=
{
SIGNUP
:
'
/signup
'
,
ME
:
'
/accounts/me/
'
,
ACCOUNT
:
'
/accounts/
'
,
CREATE_CASE_SUBJECT
:
"
/cases/case-subjects
"
,
CREATE_INVESTIGATION_CASE
:
"
/cases/investigation-cases
"
,
GET_LOG
:
"
/logs
"
,
LIST_POSITIVE_CASE
:
"
/cases/positive-cases
"
,
ACCOUNTS
:
createEndpoint
([
"
accounts
"
]),
CASE_SUBJECTS
:
createEndpoint
([
"
cases
"
,
"
case-subjects
"
]),
INVESTIGATION_CASES
:
createEndpoint
([
"
cases
"
,
"
investigation-cases
"
]),
LIST_POSITIVE_CASES
:
createEndpoint
([
"
cases
"
,
"
positive-cases
"
]),
LOGS
:
createEndpoint
([
"
logs
"
]),
LOGIN
:
'
/auth/token/
'
,
};
...
...
@@ -21,15 +20,6 @@ enum Method {
PUT
=
'
PUT
'
,
}
// const form = (obj: Object) => {
// const form = new FormData();
// Object.keys(obj).forEach(key => {
// form.append(key, obj[key]);
// });
// return form;
// };
export
default
function
useMainService
(
token
:
string
)
{
// Private functions
async
function
fetchWithoutAuthentication
(
...
...
@@ -74,8 +64,10 @@ export default function useMainService(token: string) {
}
async
function
me
()
{
console
.
log
(
API_MAIN_URL
)
return
fetchWithAuthentication
(
END_POINTS
.
ME
,
Method
.
GET
);
const
endPoint
=
END_POINTS
.
ACCOUNTS
([
"
me
"
,
])
return
fetchWithAuthentication
(
endPoint
,
Method
.
GET
);
}
interface
UserFormType
{
...
...
@@ -88,70 +80,103 @@ export default function useMainService(token: string) {
}
async
function
createUser
(
body
:
UserFormType
)
{
return
fetchWithoutAuthentication
(
END_POINTS
.
ACCOUNT
,
Method
.
POST
,
body
);
const
endPoint
=
END_POINTS
.
ACCOUNTS
([
null
,
])
return
fetchWithoutAuthentication
(
endPoint
,
Method
.
POST
,
body
);
}
async
function
createCaseSubject
(
body
:
object
)
{
const
endPoint
=
END_POINTS
.
CASE_SUBJECTS
([
null
,
null
,
])
return
fetchWithAuthentication
(
END_POINTS
.
CREATE_CASE_SUBJECT
+
'
/
'
,
endPoint
,
Method
.
POST
,
body
,
);
}
async
function
createInvestigationCase
(
body
:
object
)
{
const
endPoint
=
END_POINTS
.
INVESTIGATION_CASES
([
null
,
null
,
])
return
fetchWithAuthentication
(
END_POINTS
.
CREATE_INVESTIGATION_CASE
+
'
/
'
,
endPoint
,
Method
.
POST
,
body
,
);
}
async
function
editCaseSubject
(
body
:
object
,
subject_id
:
string
)
{
const
endPoint
=
END_POINTS
.
CASE_SUBJECTS
([
null
,
subject_id
,
])
return
fetchWithAuthentication
(
END_POINTS
.
CREATE_CASE_SUBJECT
+
`/
${
subject_id
}
/`
,
endPoint
,
Method
.
PUT
,
body
,
);
}
async
function
editInvestigationCase
(
body
:
object
,
case_id
:
string
)
{
const
endPoint
=
END_POINTS
.
INVESTIGATION_CASES
([
null
,
case_id
,
])
return
fetchWithAuthentication
(
END_POINTS
.
CREATE_INVESTIGATION_CASE
+
`/
${
case_id
}
/`
,
endPoint
,
Method
.
PUT
,
body
,
);
}
async
function
getInvestigationCase
(
case_id
:
string
)
{
console
.
log
(
END_POINTS
.
CREATE_INVESTIGATION_CASE
+
`/
${
case_id
}
/`
);
const
endPoint
=
END_POINTS
.
INVESTIGATION_CASES
([
null
,
case_id
,
])
return
fetchWithAuthentication
(
END_POINTS
.
CREATE_INVESTIGATION_CASE
+
`/
${
case_id
}
/`
,
endPoint
,
Method
.
GET
,
);
}
async
function
getLog
(
page
:
number
)
{
console
.
log
(
API_MAIN_URL
+
END_POINTS
.
GET_LOG
);
if
(
page
===
1
)
{
return
fetchWithAuthentication
(
END_POINTS
.
GET_LOG
,
Method
.
GET
);
}
else
{
return
fetchWithAuthentication
(
END_POINTS
.
GET_LOG
+
`/?page=
${
page
}
`
,
Method
.
GET
,
);
const
endPoint
=
END_POINTS
.
LOGS
([
null
,
])
return
fetchWithAuthentication
(
endPoint
,
Method
.
GET
);
}
const
endPointWithPaging
=
END_POINTS
.
LOGS
([
`?page=
${
page
}
`
,
])
return
fetchWithAuthentication
(
endPointWithPaging
,
Method
.
GET
,
);
}
async
function
listPositiveCases
(
page
:
number
)
{
if
(
page
===
1
)
{
return
fetchWithAuthentication
(
END_POINTS
.
LIST_POSITIVE_CASE
,
Method
.
GET
);
}
else
{
return
fetchWithAuthentication
(
END_POINTS
.
LIST_POSITIVE_CASE
+
`/?page=
${
page
}
`
,
Method
.
GET
,
);
const
endPoint
=
END_POINTS
.
LIST_POSITIVE_CASES
([
null
,
null
,
])
return
fetchWithAuthentication
(
endPoint
,
Method
.
GET
);
}
const
endPointWithPaging
=
END_POINTS
.
LIST_POSITIVE_CASES
([
null
,
`?page=
${
page
}
`
,
])
return
fetchWithAuthentication
(
endPointWithPaging
,
Method
.
GET
,
);
}
return
{
...
...
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