diff --git a/app/src/context/diaryData.js b/app/src/context/diaryData.js index f3dce38..24d862f 100644 --- a/app/src/context/diaryData.js +++ b/app/src/context/diaryData.js @@ -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, @@ -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); @@ -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"); }; diff --git a/app/src/scenes/consulted/Consulted.js b/app/src/scenes/consulted/Consulted.js index 1ad5635..2545aed 100644 --- a/app/src/scenes/consulted/Consulted.js +++ b/app/src/scenes/consulted/Consulted.js @@ -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; @@ -20,6 +20,7 @@ const Consulted = ({ navigation, route, submitAnswer }) => { { + onClose(); logEvents.logConsultedAnswer("close"); navigation.navigate("tabs"); }} diff --git a/app/src/scenes/consulted/index.js b/app/src/scenes/consulted/index.js index dba0955..a356ac7 100644 --- a/app/src/scenes/consulted/index.js +++ b/app/src/scenes/consulted/index.js @@ -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); @@ -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(); @@ -37,7 +43,9 @@ const ConsultedRouter = ({ route }) => { name={"Consulted"} initialParams={{ alertLevel, alertDate }} > - {(p) => } + {(p) => ( + + )} {(p) => } diff --git a/app/src/scenes/survey/Result.js b/app/src/scenes/survey/Result.js index 3398ad8..d989bbc 100644 --- a/app/src/scenes/survey/Result.js +++ b/app/src/scenes/survey/Result.js @@ -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"; @@ -14,14 +14,13 @@ 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, @@ -29,8 +28,8 @@ const Result = ({ navigation, route }) => { { name: "consulted-after-alert", params: { - alertLevel: yesterdayAlertLevel, - alertDate: yesterdayAlertDate, + alertLevel: needSurveyFeedbackItem.data.survey_alert, + alertDate: needSurveyFeedbackItem.date, previousScreen: "day-survey-result", }, }, diff --git a/app/src/scenes/survey/daySurvey.js b/app/src/scenes/survey/daySurvey.js index 83ab325..c1fe5ae 100644 --- a/app/src/scenes/survey/daySurvey.js +++ b/app/src/scenes/survey/daySurvey.js @@ -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); @@ -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 = () => { @@ -111,7 +111,28 @@ const DaySurvey = ({ navigation, route }) => { {__DEV__ ? ( - + + + 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, + }) + } + > + MOCK data RED + @@ -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, }) } > - DEVTOOLS : MOCK data + MOCK data GREEN ) : null} diff --git a/app/src/utils/constants.js b/app/src/utils/constants.js index e91878d..9fda072 100644 --- a/app/src/utils/constants.js +++ b/app/src/utils/constants.js @@ -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", diff --git a/app/src/utils/localStorage/index.js b/app/src/utils/localStorage/index.js index e8939d1..2dae64d 100644 --- a/app/src/utils/localStorage/index.js +++ b/app/src/utils/localStorage/index.js @@ -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"; @@ -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, @@ -321,4 +350,7 @@ export default { getIndicateurs, setIndicateurs, addIndicateur, + getNeedSurveyFeedback, + addNeedSurveyFeedbackItem, + deleteNeedSurveyFeedbackItem, };