Fakultas Ilmu Komputer UI

Commit 131bf7ae authored by Nandhika Prayoga's avatar Nandhika Prayoga
Browse files

Merge branch 'coldfix-sprint_2' into 'staging'

Coldfix sprint 2

See merge request ppl-fasilkom-ui/2020/ppl-c/ppti-mobile-apps-monitoring-wabah-tuberkolosis/neza-mobile!23
parents 64dbd0d9 401f3743
......@@ -99,6 +99,7 @@ function cacheReducer(oldCache: CacheType, action: CacheAction): CacheType {
}
const App = () => {
console.disableYellowBox = true;
const [cache, cacheDispatch] = useReducer(cacheReducer, initialCacheState);
const [token, setToken] = useState();
const [user, setUser] = useState();
......@@ -134,10 +135,10 @@ const App = () => {
if (response.status === 200) {
// Token is valid
setUser(response.data)
// navigatorRef.current?.reset({
// index: 0,
// routes: [{name: 'home'}]
// });
navigatorRef.current?.reset({
index: 0,
routes: [{name: 'home'}]
});
} else {
// Token is not valid
setToken('')
......@@ -145,10 +146,10 @@ const App = () => {
}
getUser()
} else if (token === '') {
// navigatorRef.current?.reset({
// index: 0,
// routes: [{name: 'login'}]
// });
navigatorRef.current?.reset({
index: 0,
routes: [{name: 'login'}]
});
}
}, [token])
......
......@@ -63,12 +63,6 @@ function Field({
const { colors } = useContext(ThemeContext) || {};
const [innerValue, setInnerValue] = useState(value);
useEffect(() => {
if (values && values.length > 0 && type === Type.Dropdown) {
setInnerValue(values[0].value)
}
}, [])
useEffect(() => {
updateValue(innerValue);
}, [innerValue]);
......@@ -77,6 +71,12 @@ function Field({
setInnerValue(value)
}, [value])
useEffect(() => {
if (values && values.length > 0 && type === Type.Dropdown) {
setInnerValue(values[0].value)
}
}, [])
return (
<Box
axis={Box.Axis.Vertical}
......
......@@ -185,7 +185,7 @@ exports[`renders correctly 1`] = `
Array [
Object {
"alignItems": "center",
"backgroundColor": "#00000080",
"backgroundColor": "#00000070",
"flexBasis": 0,
"flexDirection": "column",
"flexGrow": 1,
......@@ -420,7 +420,7 @@ exports[`successfully call edit log callback 1`] = `
Array [
Object {
"alignItems": "center",
"backgroundColor": "#00000080",
"backgroundColor": "#00000070",
"flexBasis": 0,
"flexDirection": "column",
"flexGrow": 1,
......@@ -655,7 +655,7 @@ exports[`successfully change log page 1`] = `
Array [
Object {
"alignItems": "center",
"backgroundColor": "#00000080",
"backgroundColor": "#00000070",
"flexBasis": 0,
"flexDirection": "column",
"flexGrow": 1,
......@@ -890,7 +890,7 @@ exports[`successfully fetch log data 1`] = `
Array [
Object {
"alignItems": "center",
"backgroundColor": "#00000080",
"backgroundColor": "#00000070",
"flexBasis": 0,
"flexDirection": "column",
"flexGrow": 1,
......
......@@ -30,17 +30,26 @@ mockedAxios.request.mockImplementation(
count: 0,
previous: true,
next: true,
case_subject: {
id: 'f18cb059-c52e-49b1-8bb8-b066a946af4e',
name: 'Raden Logy Ajeng',
age: 22,
is_male: false,
address: 'Jl. Mahajapit Selatan 29',
district: 'Beji',
sub_district: 'Beji',
created_at: '2020-04-21T15:28:04.205152+07:00',
},
results: [
{
id: 'id',
model_name: 'InvestigationCase',
model_name: 'Investigation Case',
revision_id: 'rev-id',
object_id: 'obj-id',
latest_version: 'latest-id',
action_type: 'Create',
created_at: '2020-04-09T13:48:39.677670+07:00',
recorded_at: '2020-04-09T13:48:39.677670+07:00',
author: null,
case_object: null,
latest: true,
},
],
},
......
......@@ -16,6 +16,7 @@ const Log = () => {
const [isMax, setIsMax] = useState<boolean>(false);
const [isMin, setIsMin] = useState<boolean>(true);
const [page, setPage] = useState<number>(1);
const [modalLatest, setModalLatest] = useState<boolean[]>([]);
const verticalLineHeight = ((logList.length - 1) / logList.length) * 100;
const global = useContext(AppContext);
const {
......@@ -30,21 +31,28 @@ const Log = () => {
height: ${verticalLineHeight}%;
`;
const onLogSelect = (value: LogType) => {
const onLogSelect = async (value: LogType) => {
setIsLoaded(false);
global.setCache(initialCacheState);
global.setCache({
investigationCaseFormData: {
is_edit: true,
reference_case: value.case_object.reference_case,
reference_case_id: value.case_object.reference_case_id,
revision_id: value.case_object.revision_id,
subject_id: value.case_object.subject_id,
reference_case: value.case_object.reference_case.case_subject.name,
reference_case_id:
value.case_object.reference_case !== undefined
? value.case_object.reference_case.id
: null,
id: value.case_object.id,
case_relation: value.case_object.case_relation,
medical_symptoms: value.case_object.medical_symptoms,
risk_factors: value.case_object.risk_factors,
is_referral_needed: value.case_object.is_referral_needed,
medical_facility_reference:
value.case_object.medical_facility_reference,
// medical_facility_district: value.case_object.medical_facility_reference.split(
// 'Kec. ',
// )[1],
// medical_facility_reference:
// value.case_object.medical_facility_reference,
author: value.author,
case_subject: value.case_object.case_subject
? {
......@@ -54,6 +62,12 @@ const Log = () => {
: null,
},
});
setIsLoaded(true);
let newModalLatest = [...modalLatest];
newModalLatest.forEach((_v, index, arr) => {
arr[index] = false;
});
setModalLatest(newModalLatest);
navigation.navigate('contact-investigation-form/2');
};
......@@ -61,24 +75,37 @@ const Log = () => {
setIsLoaded(false);
const getLog = main.getLog(page);
getLog.then(logRes => {
getLog.then(async logRes => {
logRes.data.previous === null ? setIsMin(true) : setIsMin(false);
logRes.data.next === null ? setIsMax(true) : setIsMax(false);
const tempLogList = logRes.data.results.filter((log: LogType) => {
return (
log.model_name === 'InvestigationCase' && log.latest_version !== null
);
return log.model_name === 'Investigation Case';
});
let latestObjects: LogType[] = [];
tempLogList.forEach((log: LogType) => {
const getCase = main.getInvestigationCase(log.latest_version);
getCase.then(caseRes => {
log.case_object = caseRes.data;
});
});
for (let log of tempLogList) {
setModalLatest(prevArray => [...prevArray, false]);
let currentObj = latestObjects.find(
obj => obj.object_id === log.object_id,
);
setIsLoaded(true);
if (currentObj) {
if (new Date(currentObj.recorded_at) < new Date(log.recorded_at)) {
latestObjects = latestObjects.filter(item => item !== currentObj);
tempLogList.find(item => item === currentObj).latest = false;
}
} else {
latestObjects.push(log);
log.latest = true;
}
}
for (let log of tempLogList) {
const caseResponse = await main.getInvestigationCase(log.object_id);
log.case_object = caseResponse.data;
}
setLogList(tempLogList);
setIsLoaded(true);
});
}, [page]);
......@@ -87,11 +114,7 @@ const Log = () => {
<Container>
<Modal animationType="fade" transparent={true} visible={true}>
<ModalContainer>
<ActivityIndicator
animating={true}
size="large"
color="#fff"
/>
<ActivityIndicator animating={true} size="large" color="#fff" />
</ModalContainer>
</Modal>
</Container>
......@@ -116,28 +139,67 @@ const Log = () => {
<VerticalLine />
{logList.map((log: LogType, index: number) => {
return (
<Box width="100%">
<Circle />
<LogDetail
id={'log-' + index}
onPress={() => {
onLogSelect(log);
}}>
<Text isBold={true}>
{new Date(log.created_at).toLocaleString('id-ID', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
})}
</Text>
<Text>
Melakukan {log.action_type.toLowerCase()} investigasi kontak
pada {/* {log.case_object.case_subject.name} */}
dengan rev ID {log.revision_id}
</Text>
</LogDetail>
</Box>
<>
<Modal
animationType="fade"
transparent={true}
visible={modalLatest[index]}>
<ModalContainer>
<ModalInner>
<Text fontSize={20} align={'center'} isBold={true}>
Log ini bukan merupakan perubahan terakhir.
</Text>
<Gap axis={2} gap={10} />
<Text fontSize={18} align={'center'}>
Apakah anda ingin mengubah perubahan terakhir?
</Text>
<Gap axis={2} gap={20} />
<Box axis={1}>
<Button
onPress={() => {
let newModalLatest = [...modalLatest];
newModalLatest[index] = false;
setModalLatest(newModalLatest);
}}
type={2}>
Tidak
</Button>
<Gap axis={1} gap={10} />
<Button onPress={() => onLogSelect(log)} type={1}>
Ya
</Button>
</Box>
</ModalInner>
</ModalContainer>
</Modal>
<Box width="100%">
<Circle />
<LogDetail
id={'log-' + index}
onPress={() => {
if (log.latest) {
onLogSelect(log);
} else {
let newModalLatest = [...modalLatest];
newModalLatest[index] = true;
setModalLatest(newModalLatest);
}
}}>
<Text isBold={true}>
{new Date(log.recorded_at).toLocaleString('id-ID', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
})}
</Text>
<Text>
Melakukan {log.action_type.toLowerCase()} investigasi kontak
pada {log.case_object.case_subject.name}
</Text>
</LogDetail>
</Box>
</>
);
})}
</Box>
......@@ -170,7 +232,18 @@ const ModalContainer = styled.View`
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #00000080;
background-color: #00000070;
`;
const ModalInner = styled.View`
flex-direction: column;
align-items: center;
justify-content: center;
background-color: #fff;
padding: 15%;
width: 80%;
height: ${props => props.theme.vh * 0.3};
border-radius: 10px;
`;
const Container = styled.View`
......@@ -190,9 +263,9 @@ const Circle = styled.View`
`;
const LogDetail = styled.TouchableOpacity`
width: 100%;
height: 90px;
max-height: 90px;
width: 95%;
height: 80px;
max-height: 80px;
`;
export default Log;
......@@ -32,9 +32,8 @@ exports[`renders correctly 1`] = `
"overflow": "hidden",
},
Object {
"backgroundColor": "gray",
"borderRadius": 100,
"padding": 4,
"backgroundColor": "white",
"height": 40,
},
]
}
......@@ -53,7 +52,7 @@ exports[`renders correctly 1`] = `
undefined,
undefined,
Object {
"flex": 1,
"flex": 1.5,
},
false,
undefined,
......@@ -89,7 +88,7 @@ exports[`renders correctly 1`] = `
undefined,
undefined,
Object {
"flex": 2,
"flex": 3,
},
false,
undefined,
......@@ -125,7 +124,7 @@ exports[`renders correctly 1`] = `
undefined,
undefined,
Object {
"flex": 1,
"flex": 2,
},
false,
undefined,
......@@ -161,7 +160,7 @@ exports[`renders correctly 1`] = `
undefined,
undefined,
Object {
"flex": 1,
"flex": 1.5,
},
false,
undefined,
......@@ -197,7 +196,7 @@ exports[`renders correctly 1`] = `
undefined,
undefined,
Object {
"flex": 2,
"flex": 3,
},
false,
undefined,
......@@ -231,10 +230,10 @@ exports[`renders correctly 1`] = `
},
Array [
Object {
"backgroundColor": "lightgrey",
"backgroundColor": "#F5F5F5",
"borderRadius": 100,
"marginBottom": 2,
"marginTop": 2,
"marginBottom": 3,
"marginTop": 3,
"padding": 4,
},
0,
......@@ -298,12 +297,12 @@ exports[`renders correctly 1`] = `
"alignItems": "center",
"alignSelf": "center",
"borderColor": "#747070",
"borderRadius": 10,
"borderRadius": 12.5,
"borderWidth": 3,
"height": 20,
"height": 25,
"justifyContent": "center",
"opacity": 1,
"width": 20,
"width": 25,
}
}
>
......@@ -346,6 +345,7 @@ exports[`renders correctly 1`] = `
}
>
<Text
onPress={[Function]}
style={
Array [
Object {
......@@ -380,6 +380,7 @@ exports[`renders correctly 1`] = `
}
>
<Text
onPress={[Function]}
style={
Array [
Object {
......@@ -416,6 +417,7 @@ exports[`renders correctly 1`] = `
}
>
<Text
onPress={[Function]}
style={
Array [
Object {
......@@ -450,6 +452,7 @@ exports[`renders correctly 1`] = `
}
>
<Text
onPress={[Function]}
style={
Array [
Object {
......@@ -474,10 +477,10 @@ exports[`renders correctly 1`] = `
},
Array [
Object {
"backgroundColor": "lightgrey",
"backgroundColor": "#F5F5F5",
"borderRadius": 100,
"marginBottom": 2,
"marginTop": 2,
"marginBottom": 3,
"marginTop": 3,
"padding": 4,
},
Object {
......@@ -543,12 +546,12 @@ exports[`renders correctly 1`] = `
"alignItems": "center",
"alignSelf": "center",
"borderColor": "#747070",
"borderRadius": 10,
"borderRadius": 12.5,
"borderWidth": 3,
"height": 20,
"height": 25,
"justifyContent": "center",
"opacity": 1,
"width": 20,
"width": 25,
}
}
>
......@@ -591,6 +594,7 @@ exports[`renders correctly 1`] = `
}
>
<Text
onPress={[Function]}
style={
Array [
Object {
......@@ -625,6 +629,7 @@ exports[`renders correctly 1`] = `
}
>
<Text
onPress={[Function]}
style={
Array [
Object {
......@@ -661,6 +666,7 @@ exports[`renders correctly 1`] = `
}
>
<Text
onPress={[Function]}
style={
Array [
Object {
......@@ -695,6 +701,7 @@ exports[`renders correctly 1`] = `
}
>
<Text
onPress={[Function]}
style={
Array [
Object {
......@@ -719,10 +726,10 @@ exports[`renders correctly 1`] = `
},
Array [
Object {
"backgroundColor": "lightgrey",
"backgroundColor": "#F5F5F5",
"borderRadius": 100,
"marginBottom": 2,
"marginTop": 2,
"marginBottom": 3,
"marginTop": 3,
"padding": 4,
},
0,
......@@ -786,12 +793,12 @@ exports[`renders correctly 1`] = `
"alignItems": "center",
"alignSelf": "center",
"borderColor": "#747070",
"borderRadius": 10,
"borderRadius": 12.5,
"borderWidth": 3,
"height": 20,
"height": 25,
"justifyContent": "center",
"opacity": 1,
"width": 20,
"width": 25,
}
}
>
......@@ -834,6 +841,7 @@ exports[`renders correctly 1`] = `
}
>
<Text
onPress={[Function]}
style={
Array [
Object {
......@@ -868,6 +876,7 @@ exports[`renders correctly 1`] = `
}
>
<Text
onPress={[Function]}
style={
Array [
Object {
......@@ -904,6 +913,7 @@ exports[`renders correctly 1`] = `
}
>
<Text
onPress={[Function]}
style={
Array [
Object {
......@@ -938,6 +948,7 @@ exports[`renders correctly 1`] = `
}
>
<Text
onPress={[Function]}
style={
Array [
Object {
......@@ -962,10 +973,10 @@ exports[`renders correctly 1`] = `
},
Array [
Object {
"backgroundColor": "lightgrey",
"backgroundColor": "#F5F5F5",
"borderRadius": 100,
"marginBottom": 2,
"marginTop": 2,
"marginBottom": 3,
"marginTop": 3,
"padding": 4,
},
Object {
......@@ -1031,12 +1042,12 @@ exports[`renders correctly 1`] = `
"alignItems": "center",
"alignSelf": "center",
"borderColor": "#747070",
"borderRadius": 10,
"borderRadius": 12.5,