Skip to content

Commit

Permalink
feat: offline forms have identifier in list views
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-mccombs committed Dec 13, 2020
1 parent 5694698 commit c68bf31
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 50 deletions.
17 changes: 15 additions & 2 deletions components/FindResidents/Resident/ResidentCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ResidentCard = ({
resident, onSelectPerson
}) => {
const {
fname, lname, nickname, city, picture, communityname
fname, lname, nickname, city, picture, communityname, objectId
} = resident;
const [pictureUrl, setPictureUrl] = useState();
useEffect(() => {
Expand All @@ -35,6 +35,9 @@ const ResidentCard = ({
>
<View style={styles.nameConatiner}>
<Title style={styles.name}>{`${fname} ${lname}`}</Title>
{objectId.includes('PatientID-') && (
<View style={styles.redCircle}></View>
)}
</View>
<Text style={styles.nickname}>{`"${nickname}"`}</Text>
<Image
Expand Down Expand Up @@ -66,7 +69,8 @@ const styles = StyleSheet.create({
nameConatiner: {
backgroundColor: theme.colors.primary,
marginTop: 15,
height: 30
height: 30,
flexDirection: 'row'
},
name: {
color: '#FFFFFF',
Expand Down Expand Up @@ -113,6 +117,15 @@ const styles = StyleSheet.create({
color: '#606060',
fontSize: 15
},
redCircle: {
backgroundColor: '#f8380e',
width: 15,
height: 15,
marginLeft: 10,
marginTop: 'auto',
marginBottom: 'auto',
borderRadius: 20
}

});

Expand Down
31 changes: 21 additions & 10 deletions components/FindResidents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ const FindResidents = ({
const [query, setQuery] = useState('');
const [residents, setResidents] = useState([]);
const [loading, setLoading] = useState(false);
const [offlineData, setOfflineData] = useState(getData('offlineIDForms'));
const [didMount, setDidMount] = useState(false);
const [offline, setOffline] = useState(false);
useEffect(() => {
fetchAsyncData();
}, [organization, didMount]);
}, [organization, offline]);

const fetchAsyncData = () => {
setLoading(true);
Expand All @@ -36,10 +35,13 @@ const FindResidents = ({
if (residentData) {
let offlineData = [];
getData('offlineIDForms').then((offlineResidentData) => {
Object.entries(offlineResidentData).forEach(([key, value]) => {
offlineData = offlineData.concat(value.localObject);
})
console.log("OFFLINE", offlineData)
console.log(offlineResidentData);
if (offlineResidentData !== null) {
Object.entries(offlineResidentData).forEach(([key, value]) => {
offlineData = offlineData.concat(value.localObject);
})
console.log("OFFLINE", offlineData)
}
const allData = residentData.concat(offlineData);
console.log("ALL", allData);
setData(allData || []);
Expand All @@ -63,9 +65,18 @@ const FindResidents = ({
const records = await residentQuery(queryParams);

storeData(records, 'residentData');

setData(records);
setResidents(records.slice());

let offlineData = [];
await getData('offlineIDForms').then((offlineResidentData) => {
if (offlineResidentData !== null) {
Object.entries(offlineResidentData).forEach(([key, value]) => {
offlineData = offlineData.concat(value.localObject);
})
}
})
const allData = records.concat(offlineData);
setData(allData);
setResidents(allData.slice());
setLoading(false);
};

Expand Down
48 changes: 41 additions & 7 deletions components/ResidentIdSearchbar/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
import { View, FlatList } from 'react-native';
import { View, FlatList, Text } from 'react-native';
import { Headline, Button, Searchbar } from 'react-native-paper';
import { Spinner } from 'native-base';

Expand All @@ -26,8 +26,18 @@ const ResidentIdSearchbar = ({ surveyee, setSurveyee, surveyingOrganization }) =
setLoading(true);
getData('residentData').then((residentData) => {
if (residentData) {
setData(residentData || []);
setResidents(residentData.slice() || [].slice());
let offlineData = [];
getData('offlineIDForms').then((offlineResidentData) => {
if (offlineResidentData !== null) {
Object.entries(offlineResidentData).forEach(([key, value]) => {
offlineData = offlineData.concat(value.localObject);
})
}
console.log("OFFLINE", offlineData)
const allData = residentData.concat(offlineData);
setData(allData || []);
setResidents(allData.slice() || [].slice());
})
}
setLoading(false);
});
Expand All @@ -43,9 +53,17 @@ const ResidentIdSearchbar = ({ surveyee, setSurveyee, surveyingOrganization }) =
parseParam: surveyingOrganization,
};
const records = await residentQuery(queryParams);

setData(records);
setResidents(records.slice());
let offlineData = [];
await getData('offlineIDForms').then((offlineResidentData) => {
if (offlineResidentData !== null) {
Object.entries(offlineResidentData).forEach(([key, value]) => {
offlineData = offlineData.concat(value.localObject);
})
}
})
const allData = records.concat(offlineData);
setData(allData);
setResidents(allData.slice());
setLoading(false);
};

Expand Down Expand Up @@ -75,7 +93,23 @@ const ResidentIdSearchbar = ({ surveyee, setSurveyee, surveyingOrganization }) =
};

const renderItem = ({ item }) => (
<Button onPress={() => onSelectSurveyee(item)}>{`${item?.fname} ${item?.lname}`}</Button>
<View>
<Button onPress={() => onSelectSurveyee(item)} contentStyle={{ marginRight: 5 }}>
<Text style={{ marginRight: 10 }}>{`${item?.fname} ${item?.lname}`}</Text>
{/* offline IDform */}
{item.objectId.includes('PatientID-') && (
<View style={{
backgroundColor: '#f8380e',
width: 1,
height: 10,
paddingLeft: 10,
marginTop: 'auto',
marginBottom: 'auto',
borderRadius: 20
}}></View>
)}
</Button>
</View>
);

return (
Expand Down
71 changes: 40 additions & 31 deletions modules/cached-resources/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,40 @@ function postSupplementaryForm(postParams) {
}

function postOfflineForms() {
return new Promise(async (resolve, reject) => {
let idForms = await getData('offlineIDForms');
let supForms = await getData('offlineSupForms');
return new Promise((resolve, reject) => {
checkOnlineStatus().then(async (connected) => {
if (connected) {
let idForms = await getData('offlineIDForms');
let supForms = await getData('offlineSupForms');

idForms.forEach((postParams) => {
const offlineObjectID = postParams.localObject.objectId;
console.log("Offline O ID", offlineObjectID);
delete postParams.localObject['objectId']
console.log('postparmas after objectId deleted', postParams)
postObjectsToClass(postParams).then((surveyee) => {
console.log("Posted ID Form")
const surveyeeSanitized = JSON.parse(JSON.stringify(surveyee));
const parseObjectID = surveyeeSanitized.objectId;
supForms.forEach((supForm) => {
if (supForm.parseParentClassID === offlineObjectID) {
supForm.parseParentClassID = parseObjectID;
postObjectsToClassWithRelation(supForm).then(() => {
console.log("Posted Supplementary Form")
}, (error) => {
console.log("Failed to post supp form");
reject(error);
});
}
})
}, (error) => {
reject(error);
});
});

idForms.forEach((postParams) => {
const offlineObjectID = postParams.localObject.objectId;
console.log("Offline O ID", offlineObjectID);
delete postParams.localObject['objectId']
console.log('postparmas after objectId deleted', postParams)
postObjectsToClass(postParams).then((surveyee) => {
console.log("Posted ID Form")
const surveyeeSanitized = JSON.parse(JSON.stringify(surveyee));
const parseObjectID = surveyeeSanitized.objectId;
supForms.forEach((supForm) => {
if (supForm.parseParentClassID === offlineObjectID) {
supForm.parseParentClassID = parseObjectID;
// supplementary forms not tied to an offline ID form
if (!supForm.parseParentClassID.includes('PatientID-')) {
postObjectsToClassWithRelation(supForm).then(() => {
console.log("Posted Supplementary Form")
}, (error) => {
Expand All @@ -103,25 +121,16 @@ function postOfflineForms() {
});
}
})
}, (error) => {
reject(error);
});
});

supForms.forEach((supForm) => {
// supplementary forms not tied to an offline ID form
if (!supForm.parseParentClassID.includes('PatientID-')) {
postObjectsToClassWithRelation(supForm).then(() => {
console.log("Posted Supplementary Form")
}, (error) => {
console.log("Failed to post supp form");
reject(error);
});
await deleteData('offlineIDForms');
await deleteData('offlineSupforms');
resolve('success');
}
else {
reject('No connection');
}
}, (error) => {
reject(error);
})
await deleteData('offlineIDForms');
await deleteData('offlineSupforms');
resolve('success');
})
}

Expand Down

0 comments on commit c68bf31

Please sign in to comment.