Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
tangimds committed Jun 28, 2023
1 parent 5abaf3f commit d090687
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 20 deletions.
4 changes: 3 additions & 1 deletion app/src/context/diaryData.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
STORAGE_KEY_BECK_EMOTION_LIST,
STORAGE_KEY_ONBOARDING_STEP,
STORAGE_KEY_ONBOARDING_DONE,
STORAGE_KEY_NEED_SURVEY_FEEDBACK,
} from "../utils/constants";
import {
fakeDiaryData,
Expand All @@ -31,7 +32,7 @@ import { beforeToday, formatDay, getArrayOfDates } from "../utils/date/helpers";

const wipeData = async () => {
// await AsyncStorage.removeItem(STORAGE_KEY_START_DATE);
await AsyncStorage.removeItem(STORAGE_KEY_SURVEY_RESULTS);
// await AsyncStorage.removeItem(STORAGE_KEY_SURVEY_RESULTS);
// await AsyncStorage.removeItem(STORAGE_KEY_SYMPTOMS);
// await AsyncStorage.removeItem(STORAGE_KEY_INDICATEURS);
// await AsyncStorage.removeItem(STORAGE_KEY_IS_FIRST_LAUNCH);
Expand All @@ -47,6 +48,7 @@ const wipeData = async () => {
// await AsyncStorage.removeItem(STORAGE_KEY_BECK_EMOTION_LIST);
// await AsyncStorage.removeItem(STORAGE_KEY_ONBOARDING_STEP);
// await AsyncStorage.removeItem(STORAGE_KEY_ONBOARDING_DONE);
// await AsyncStorage.removeItem(STORAGE_KEY_NEED_SURVEY_FEEDBACK);
// await AsyncStorage.removeItem("@Reminder");
};

Expand Down
3 changes: 2 additions & 1 deletion app/src/scenes/consulted/Consulted.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CloseButton from "../../components/CloseButton";
import logEvents from "../../services/logEvents";
dayjs.locale("fr");

const Consulted = ({ navigation, route, submitAnswer }) => {
const Consulted = ({ navigation, route, submitAnswer, onClose }) => {
const alertLevel = route.params.alertLevel;
const alertDate = route.params.alertDate;

Expand All @@ -20,6 +20,7 @@ const Consulted = ({ navigation, route, submitAnswer }) => {
<View className="flex flex-row-reverse space-between">
<CloseButton
onPress={() => {
onClose();
logEvents.logConsultedAnswer("close");
navigation.navigate("tabs");
}}
Expand Down
10 changes: 9 additions & 1 deletion app/src/scenes/consulted/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ConsultedResult from "./ConsultedResult";
import { ConsultedDataContext } from "../../context/consultedData";
import { formatDay } from "../../utils/date/helpers";
import logEvents from "../../services/logEvents";
import localStorage from "../../utils/localStorage";

const ConsultedRouter = ({ route }) => {
const [consultedData, setConsultedData] = useContext(ConsultedDataContext);
Expand All @@ -24,6 +25,11 @@ const ConsultedRouter = ({ route }) => {
logEvents.logConsultedDateAnswered(alertDate);
logEvents.logConsultedPreviousScreen(route.params.previousScreen ?? "");
setConsultedData(currentConsultedAnswer);
await localStorage.deleteNeedSurveyFeedbackItem({ date: alertDate });
};

const onClose = async () => {
await localStorage.deleteNeedSurveyFeedbackItem({ date: alertDate });
};

const Stack = createStackNavigator();
Expand All @@ -37,7 +43,9 @@ const ConsultedRouter = ({ route }) => {
name={"Consulted"}
initialParams={{ alertLevel, alertDate }}
>
{(p) => <Consulted {...p} submitAnswer={submitAnswer} />}
{(p) => (
<Consulted {...p} submitAnswer={submitAnswer} onClose={onClose} />
)}
</Stack.Screen>
<Stack.Screen name={"ConsultedDetails"}>
{(p) => <ConsultedDetails {...p} submitAnswer={submitAnswer} />}
Expand Down
17 changes: 8 additions & 9 deletions app/src/scenes/survey/Result.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import dayjs from "dayjs";
import "dayjs/locale/fr";
import { CommonActions } from "@react-navigation/native";
import * as SMS from "expo-sms";
import React from "react";
import { Alert, Keyboard, StyleSheet, View } from "react-native";
import { Button2 } from "../../components/Button2";
import Text from "../../components/MyText";
Expand All @@ -14,23 +14,22 @@ import AlertComponent from "../../components/alerts";

const Result = ({ navigation, route }) => {
const alertLevel = route.params?.alert;
const yesterdayAlertDate = route.params?.yesterdayAlertDate;
const yesterdayAlertLevel = route.params?.yesterdayAlertLevel;

const submitDay = async ({}) => {
if (
yesterdayAlertLevel &&
(yesterdayAlertLevel === "orange" || yesterdayAlertLevel === "red")
) {
const needSurveyFeedback = await localStorage.getNeedSurveyFeedback();
const needSurveyFeedbackItem = (needSurveyFeedback || []).find(
(e) => e.date !== dayjs().format("YYYY-MM-DD")
);
if (needSurveyFeedbackItem) {
return navigation.dispatch(
CommonActions.reset({
index: 0,
routes: [
{
name: "consulted-after-alert",
params: {
alertLevel: yesterdayAlertLevel,
alertDate: yesterdayAlertDate,
alertLevel: needSurveyFeedbackItem.data.survey_alert,
alertDate: needSurveyFeedbackItem.date,
previousScreen: "day-survey-result",
},
},
Expand Down
37 changes: 29 additions & 8 deletions app/src/scenes/survey/daySurvey.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { questions } from "../../utils/constants";
import { computeHasOxygen } from "../../utils";
import { computeResult } from "./utils";
import logEvents from "../../services/logEvents";
import localStorage from "../../utils/localStorage";

const DaySurvey = ({ navigation, route }) => {
const [diaryData, setDiaryData] = useContext(DiaryDataContext);
Expand Down Expand Up @@ -67,11 +68,10 @@ const DaySurvey = ({ navigation, route }) => {
logEvents.logSurveyValidate();
logEvents.logSurveyScore(score);
logEvents.logSurveyAlert(alert);
return navigation.push("day-survey-result", {
alert,
yesterdayAlertLevel: yesterdayAlert,
yesterdayAlertDate: formatDay(beforeToday(1)),
});
if (["orange", "red"].includes(currentSurvey.data.survey_alert)) {
await localStorage.addNeedSurveyFeedbackItem(currentSurvey);
}
return navigation.push("day-survey-result", { alert });
};

const renderTodayDate = () => {
Expand Down Expand Up @@ -111,7 +111,28 @@ const DaySurvey = ({ navigation, route }) => {
<View>
<View style={{ marginBottom: 8 }}>
{__DEV__ ? (
<View>
<View className="flex flex-row">
<TouchableOpacity
className="p-2 bg-gray-100 text-gray-700"
onPress={() =>
setAnswers({
"03e034f7-b7fa-41cb-9f07-4415ef7354ca": true,
"071ce2c0-4bf6-4b85-9931-1b0668a01646": 1,
"0c1eb277-3f09-406a-9c23-bd77acf978ba": true,
"45e77c87-8909-454f-b31f-2957e1921d8c": true,
"4734d5a4-aa44-4b3e-a292-88a08fd16923": true,
"8032ca3d-8a74-4630-b532-d8699d35a45a": 1,
"aaa71e2b-9308-4240-bac4-d0cda013017d": true,
"df328401-e88b-4226-95ea-2a6780940afb": true,
"ecb26c1a-8d4a-4b19-84eb-1ff3eefb0619": true,
"f5f58308-f78b-4ba6-a933-02979cbaf864": true,
"fe53d77d-f434-405d-96ae-d664cf92113a": true,
"a8acc717-2fdb-496d-94f8-75a7945dadfe": true,
})
}
>
<Text>MOCK data RED</Text>
</TouchableOpacity>
<TouchableOpacity
className="p-2 bg-gray-100 text-gray-700"
onPress={() =>
Expand All @@ -124,14 +145,14 @@ const DaySurvey = ({ navigation, route }) => {
"8032ca3d-8a74-4630-b532-d8699d35a45a": 1,
"aaa71e2b-9308-4240-bac4-d0cda013017d": false,
"df328401-e88b-4226-95ea-2a6780940afb": false,
"ecb26c1a-8d4a-4b19-84eb-1ff3eefb0619": true,
"ecb26c1a-8d4a-4b19-84eb-1ff3eefb0619": false,
"f5f58308-f78b-4ba6-a933-02979cbaf864": false,
"fe53d77d-f434-405d-96ae-d664cf92113a": false,
"a8acc717-2fdb-496d-94f8-75a7945dadfe": false,
})
}
>
<Text>DEVTOOLS : MOCK data</Text>
<Text>MOCK data GREEN</Text>
</TouchableOpacity>
</View>
) : null}
Expand Down
1 change: 1 addition & 0 deletions app/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export const STORAGE_KEY_USER_SEX = "@USER_SEX";
export const STORAGE_KEY_USER_BIRTHYEAR = "@USER_BIRTHYEAR";
export const STORAGE_KEY_USER_WEIGHT = "@USER_WEIGHT";
export const STORAGE_KEY_LAST_NPS_SHOWN = "@LAST_NPS_SHOWN";
export const STORAGE_KEY_NEED_SURVEY_FEEDBACK = "@NEED_SURVEY_FEEDBACK";

export const ONBOARDING_STEPS = {
STEP_PRESENTATION: "STEP_PRESENTATION",
Expand Down
32 changes: 32 additions & 0 deletions app/src/utils/localStorage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
STORAGE_KEY_USER_BIRTHYEAR,
STORAGE_KEY_USER_WEIGHT,
STORAGE_KEY_LAST_NPS_SHOWN,
STORAGE_KEY_NEED_SURVEY_FEEDBACK,
} from "../constants";
import { updateSymptomsFormatIfNeeded } from "./utils";

Expand Down Expand Up @@ -277,6 +278,34 @@ const setLastNPSShown = async (lastNPSShown) =>
JSON.stringify(lastNPSShown)
);

const getNeedSurveyFeedback = async () => {
const needSurveyFeedback = await AsyncStorage.getItem(
STORAGE_KEY_NEED_SURVEY_FEEDBACK
);
return JSON.parse(needSurveyFeedback) || [];
};

const addNeedSurveyFeedbackItem = async (needSurveyFeedbackItem) => {
const needSurveyFeedback = await getNeedSurveyFeedback();
needSurveyFeedback.push(needSurveyFeedbackItem);
await AsyncStorage.setItem(
STORAGE_KEY_NEED_SURVEY_FEEDBACK,
JSON.stringify(needSurveyFeedback)
);
return needSurveyFeedback;
};

const deleteNeedSurveyFeedbackItem = async ({ date }) => {
console.log("✍️ deleteNeedSurveyFeedbackItem date:", date);
let needSurveyFeedback = await getNeedSurveyFeedback();
needSurveyFeedback = needSurveyFeedback.filter((e) => e.date !== date);
await AsyncStorage.setItem(
STORAGE_KEY_NEED_SURVEY_FEEDBACK,
JSON.stringify(needSurveyFeedback)
);
return needSurveyFeedback;
};

export default {
getLastNPSShown,
setLastNPSShown,
Expand Down Expand Up @@ -321,4 +350,7 @@ export default {
getIndicateurs,
setIndicateurs,
addIndicateur,
getNeedSurveyFeedback,
addNeedSurveyFeedbackItem,
deleteNeedSurveyFeedbackItem,
};

0 comments on commit d090687

Please sign in to comment.