-
Notifications
You must be signed in to change notification settings - Fork 8
feat(status-item): integrate new status-item design #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
d53f1fe
0caec0e
a961254
59240cb
a5b1a43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,230 @@ | ||||||||||||||||||||||||||||||||||||||
import React, { useEffect, useState, useRef } from "react"; | ||||||||||||||||||||||||||||||||||||||
import { StyleSheet, View, TouchableOpacity, Text } from "react-native"; | ||||||||||||||||||||||||||||||||||||||
import PatientStateItem from "./patient-state-item"; | ||||||||||||||||||||||||||||||||||||||
import { displayedCategories, TW_COLORS } from "../../utils/constants"; | ||||||||||||||||||||||||||||||||||||||
import Notes from "./notes"; | ||||||||||||||||||||||||||||||||||||||
import localStorage from "../../utils/localStorage"; | ||||||||||||||||||||||||||||||||||||||
import Posology from "./posology"; | ||||||||||||||||||||||||||||||||||||||
import { canEdit } from "./utils/index.js"; | ||||||||||||||||||||||||||||||||||||||
import Button from "../../components/RoundButtonIcon"; | ||||||||||||||||||||||||||||||||||||||
import Toxic from "./toxic"; | ||||||||||||||||||||||||||||||||||||||
import Context from "./context"; | ||||||||||||||||||||||||||||||||||||||
import logEvents from "../../services/logEvents"; | ||||||||||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||||||||||
GENERIC_INDICATOR_SUBSTANCE, | ||||||||||||||||||||||||||||||||||||||
INDICATEURS_HUMEUR, | ||||||||||||||||||||||||||||||||||||||
INDICATEURS_LIST, | ||||||||||||||||||||||||||||||||||||||
STATIC_UUID_FOR_INSTANCE_OF_GENERIC_INDICATOR_SUBSTANCE, | ||||||||||||||||||||||||||||||||||||||
} from "../../utils/liste_indicateurs.1"; | ||||||||||||||||||||||||||||||||||||||
import { GoalsStatus } from "../goals/status/GoalsStatus"; | ||||||||||||||||||||||||||||||||||||||
import { Card } from "../../components/Card"; | ||||||||||||||||||||||||||||||||||||||
import { GoalsStatusNoData } from "../goals/status/GoalsStatusNoData"; | ||||||||||||||||||||||||||||||||||||||
import { generateIndicatorFromPredefinedIndicator, Indicator } from "@/entities/Indicator"; | ||||||||||||||||||||||||||||||||||||||
import { DiaryDataAnswer, DiaryEntry } from "@/entities/DiaryData"; | ||||||||||||||||||||||||||||||||||||||
import { GoalRecordsData, GoalsData } from "@/entities/Goal"; | ||||||||||||||||||||||||||||||||||||||
import { BasicIcon } from "@/components/CircledIcon"; | ||||||||||||||||||||||||||||||||||||||
import { answers as emojis } from "../survey-v2/utils"; | ||||||||||||||||||||||||||||||||||||||
import { typography } from "@/utils/typography"; | ||||||||||||||||||||||||||||||||||||||
import { mergeClassNames } from "@/utils/className"; | ||||||||||||||||||||||||||||||||||||||
import { formatRelativeDate } from "@/utils/date/helpers"; | ||||||||||||||||||||||||||||||||||||||
import ArrowIcon from "@assets/svg/icon/Arrow"; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
export default ({ | ||||||||||||||||||||||||||||||||||||||
navigation, | ||||||||||||||||||||||||||||||||||||||
indicateurs = [], | ||||||||||||||||||||||||||||||||||||||
patientState, | ||||||||||||||||||||||||||||||||||||||
goalsData, | ||||||||||||||||||||||||||||||||||||||
date, | ||||||||||||||||||||||||||||||||||||||
}: { | ||||||||||||||||||||||||||||||||||||||
navigation: any; | ||||||||||||||||||||||||||||||||||||||
indicateurs: Indicator[]; | ||||||||||||||||||||||||||||||||||||||
patientState: DiaryEntry; | ||||||||||||||||||||||||||||||||||||||
goalsData: GoalsData; | ||||||||||||||||||||||||||||||||||||||
date: Date; | ||||||||||||||||||||||||||||||||||||||
}) => { | ||||||||||||||||||||||||||||||||||||||
const [customs, setCustoms] = useState([]); | ||||||||||||||||||||||||||||||||||||||
const [oldCustoms, setOldCustoms] = useState([]); | ||||||||||||||||||||||||||||||||||||||
let mounted = useRef(true); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||||||||||
(async () => { | ||||||||||||||||||||||||||||||||||||||
const c = await localStorage.getCustomSymptoms(); | ||||||||||||||||||||||||||||||||||||||
if (c && mounted) setCustoms(c); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
//retrocompatibility | ||||||||||||||||||||||||||||||||||||||
const t = c.map((e) => `${e}_FREQUENCE`); | ||||||||||||||||||||||||||||||||||||||
if (t && mounted) setOldCustoms(t); | ||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||
})(); | ||||||||||||||||||||||||||||||||||||||
return () => (mounted = false); | ||||||||||||||||||||||||||||||||||||||
}, [patientState]); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const handleEdit = (tab, editingSurvey = false, toGoals) => { | ||||||||||||||||||||||||||||||||||||||
if (!canEdit(date)) return; | ||||||||||||||||||||||||||||||||||||||
const currentSurvey = { | ||||||||||||||||||||||||||||||||||||||
date, | ||||||||||||||||||||||||||||||||||||||
answers: patientState, | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
navigation.navigate(tab, { | ||||||||||||||||||||||||||||||||||||||
currentSurvey, | ||||||||||||||||||||||||||||||||||||||
editingSurvey, | ||||||||||||||||||||||||||||||||||||||
toGoals, | ||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const hasAnswerSurvey = () => | ||||||||||||||||||||||||||||||||||||||
patientStateRecordKeys.some((key) => patientState[key]?.value !== undefined) || goalsData?.records?.byDate?.[date]?.length > 0; | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+75
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function calls
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const handlePressItem = ({ editingSurvey, toGoals } = {}) => { | ||||||||||||||||||||||||||||||||||||||
if (!canEdit(date)) return navigation.navigate("too-late", { date }); | ||||||||||||||||||||||||||||||||||||||
logEvents.logFeelingEditButtonClick(); | ||||||||||||||||||||||||||||||||||||||
handleEdit("day-survey", editingSurvey, toGoals); | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// DiaryDataAnswer; | ||||||||||||||||||||||||||||||||||||||
const patientStateRecordKeys = patientState | ||||||||||||||||||||||||||||||||||||||
? Object.keys(patientState) | ||||||||||||||||||||||||||||||||||||||
.filter((key) => { | ||||||||||||||||||||||||||||||||||||||
return !["CONTEXT", "POSOLOGY", "NOTES", "PRISE_DE_TRAITEMENT", "PRISE_DE_TRAITEMENT_SI_BESOIN", "becks"].includes(key); | ||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||
.filter((key) => !!patientState[key]) | ||||||||||||||||||||||||||||||||||||||
.filter((key) => key) | ||||||||||||||||||||||||||||||||||||||
.sort((_a, _b) => { | ||||||||||||||||||||||||||||||||||||||
const a = patientState[_a]; | ||||||||||||||||||||||||||||||||||||||
const b = patientState[_b]; | ||||||||||||||||||||||||||||||||||||||
const aIndex = indicateurs?.findIndex?.((indicateur) => indicateur?.uuid === a?._indicateur?.uuid) || 0; | ||||||||||||||||||||||||||||||||||||||
const bIndex = indicateurs?.findIndex?.((indicateur) => indicateur?.uuid === b?._indicateur?.uuid) || 0; | ||||||||||||||||||||||||||||||||||||||
return aIndex - bIndex; | ||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||
: []; | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+98
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the hasAnswerSurvey function definition after patientStateRecordKeys is available, and fix the logic to handle the case when patientStateRecordKeys is empty.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
if (hasAnswerSurvey()) { | ||||||||||||||||||||||||||||||||||||||
const emotion = Object.keys(patientState).find( | ||||||||||||||||||||||||||||||||||||||
(key) => (key === INDICATEURS_HUMEUR.uuid || key === INDICATEURS_HUMEUR.name) && patientState[key].value !== undefined | ||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
let emotionValue; | ||||||||||||||||||||||||||||||||||||||
if (emotion) { | ||||||||||||||||||||||||||||||||||||||
emotionValue = patientState[emotion].value; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||
<TouchableOpacity className="rounded-2xl border border-gray-500 flex-col my-4 p-6" onPress={() => handlePressItem({ editingSurvey: true })}> | ||||||||||||||||||||||||||||||||||||||
<View className="mb-4 flex-row justify-between"> | ||||||||||||||||||||||||||||||||||||||
<Text className={mergeClassNames(typography.textMdBold, "text-cnam-primary-950 capitalize")}>{formatRelativeDate(date)}</Text> | ||||||||||||||||||||||||||||||||||||||
<ArrowIcon /> | ||||||||||||||||||||||||||||||||||||||
</View> | ||||||||||||||||||||||||||||||||||||||
<View className="flex-1 flex-row items-center mb-6"> | ||||||||||||||||||||||||||||||||||||||
{emotionValue && ( | ||||||||||||||||||||||||||||||||||||||
<BasicIcon | ||||||||||||||||||||||||||||||||||||||
color={emojis[emotionValue].backgroundColor} | ||||||||||||||||||||||||||||||||||||||
borderColor={TW_COLORS.PRIMARY} | ||||||||||||||||||||||||||||||||||||||
iconColor={emojis[emotionValue].iconColor} | ||||||||||||||||||||||||||||||||||||||
icon={emojis[emotionValue].icon} | ||||||||||||||||||||||||||||||||||||||
borderWidth={0} | ||||||||||||||||||||||||||||||||||||||
iconContainerStyle={{ marginRight: 0 }} | ||||||||||||||||||||||||||||||||||||||
iconWidth={32} | ||||||||||||||||||||||||||||||||||||||
iconHeight={32} | ||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||||||||||
<View className="ml-2 p-2 flex-1"> | ||||||||||||||||||||||||||||||||||||||
<Text className={mergeClassNames(typography.textSmMedium, "text-cnam-primary-950")}>Anxiété, Accablement, Contrariété, Jalousie,</Text> | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded placeholder text should be replaced with dynamic data based on the actual patient state indicators.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
</View> | ||||||||||||||||||||||||||||||||||||||
</View> | ||||||||||||||||||||||||||||||||||||||
{[0, 1, 2, 3].map((item) => ( | ||||||||||||||||||||||||||||||||||||||
<View className="flex-1 flex-row items-center mb-2"> | ||||||||||||||||||||||||||||||||||||||
<View className="h-3 w-3 rounded-full mr-2 bg-red"></View> | ||||||||||||||||||||||||||||||||||||||
<View> | ||||||||||||||||||||||||||||||||||||||
<Text>Anxiété, Irritabilité</Text> | ||||||||||||||||||||||||||||||||||||||
</View> | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This hardcoded text and the map over [0,1,2,3] appears to be placeholder/debug code. Hardcoded strings like 'Anxiété, Accablement, Contrariété, Jalousie,' should be replaced with dynamic data or at minimum moved to constants.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
{/* <View> | ||||||||||||||||||||||||||||||||||||||
{patientStateRecordKeys.map((key) => { | ||||||||||||||||||||||||||||||||||||||
let patientStateRecord = patientState[key]; | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the large blocks of commented-out code. This appears to be old implementation that should either be deleted or moved to a separate branch/PR if it's still needed for reference. |
||||||||||||||||||||||||||||||||||||||
if (!patientStateRecord || patientStateRecord?.value === null || patientStateRecord.value === undefined) { | ||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
let [categoryName] = key.split("_"); | ||||||||||||||||||||||||||||||||||||||
if (categoryName === "TOXIC") { | ||||||||||||||||||||||||||||||||||||||
// for user with historic value in 'TOXIC', we replace category name by uuid for indicator substance | ||||||||||||||||||||||||||||||||||||||
key = STATIC_UUID_FOR_INSTANCE_OF_GENERIC_INDICATOR_SUBSTANCE; | ||||||||||||||||||||||||||||||||||||||
patientStateRecord = { | ||||||||||||||||||||||||||||||||||||||
...patientStateRecord, | ||||||||||||||||||||||||||||||||||||||
_indicateur: { | ||||||||||||||||||||||||||||||||||||||
...generateIndicatorFromPredefinedIndicator(GENERIC_INDICATOR_SUBSTANCE), | ||||||||||||||||||||||||||||||||||||||
uuid: key, | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
const indicator = indicateurs.find((i) => i.genericUuid === key) || indicateurs.find((i) => i.uuid === key); | ||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||
<PatientStateItem | ||||||||||||||||||||||||||||||||||||||
key={key} | ||||||||||||||||||||||||||||||||||||||
category={key} | ||||||||||||||||||||||||||||||||||||||
patientStateRecord={patientStateRecord} | ||||||||||||||||||||||||||||||||||||||
label={ | ||||||||||||||||||||||||||||||||||||||
indicator?.name || | ||||||||||||||||||||||||||||||||||||||
patientStateRecord?._indicateur?.name || | ||||||||||||||||||||||||||||||||||||||
INDICATEURS_LIST[key] || | ||||||||||||||||||||||||||||||||||||||
displayedCategories[key] || | ||||||||||||||||||||||||||||||||||||||
categoryName || | ||||||||||||||||||||||||||||||||||||||
"Unknown Indicator" | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
})} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
<GoalsStatus goalsData={goalsData} date={date} withSeparator={patientStateRecordKeys?.length > 0} /> | ||||||||||||||||||||||||||||||||||||||
<Context data={patientState?.CONTEXT} /> | ||||||||||||||||||||||||||||||||||||||
<Posology posology={patientState?.POSOLOGY} patientState={patientState} date={date} onPress={() => handleEdit("drugs")} /> | ||||||||||||||||||||||||||||||||||||||
<Notes notes={patientState?.NOTES} date={date} onPress={() => handleEdit("notes")} /> | ||||||||||||||||||||||||||||||||||||||
</View> */} | ||||||||||||||||||||||||||||||||||||||
</View> | ||||||||||||||||||||||||||||||||||||||
))} | ||||||||||||||||||||||||||||||||||||||
{/* {canEdit(date) ? ( | ||||||||||||||||||||||||||||||||||||||
<View> | ||||||||||||||||||||||||||||||||||||||
<Button icon="pencil" visible={true} onPress={() => handlePressItem({ editingSurvey: true })} /> | ||||||||||||||||||||||||||||||||||||||
</View> | ||||||||||||||||||||||||||||||||||||||
) : null} */} | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Large commented code blocks should be removed rather than left in the codebase. This improves readability and reduces maintenance overhead. |
||||||||||||||||||||||||||||||||||||||
</TouchableOpacity> | ||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||
<> | ||||||||||||||||||||||||||||||||||||||
{/* {canEdit(date) ? ( | ||||||||||||||||||||||||||||||||||||||
<View> | ||||||||||||||||||||||||||||||||||||||
<Card | ||||||||||||||||||||||||||||||||||||||
preset="grey" | ||||||||||||||||||||||||||||||||||||||
title={canEdit(date) ? "Renseigner mon état pour ce jour-là" : "Je ne peux plus saisir mon questionnaire pour ce jour"} | ||||||||||||||||||||||||||||||||||||||
image={{ source: require("./../../../assets/imgs/indicateur.png") }} | ||||||||||||||||||||||||||||||||||||||
onPress={handlePressItem} | ||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another large commented code block should be removed to keep the codebase clean. |
||||||||||||||||||||||||||||||||||||||
<GoalsStatusNoData goalsData={goalsData} date={date} onPress={handlePressItem} /> | ||||||||||||||||||||||||||||||||||||||
</View> | ||||||||||||||||||||||||||||||||||||||
) : ( | ||||||||||||||||||||||||||||||||||||||
<View /> | ||||||||||||||||||||||||||||||||||||||
)} */} | ||||||||||||||||||||||||||||||||||||||
{canEdit(date) && ( | ||||||||||||||||||||||||||||||||||||||
<TouchableOpacity className="rounded-2xl border border-gray-500 flex-col my-4 p-6" onPress={() => handlePressItem({ editingSurvey: true })}> | ||||||||||||||||||||||||||||||||||||||
<View className="mb-4 flex-row justify-between"> | ||||||||||||||||||||||||||||||||||||||
<Text className={mergeClassNames(typography.textMdBold, "text-cnam-primary-950 capitalize")}>{formatRelativeDate(date)}</Text> | ||||||||||||||||||||||||||||||||||||||
<ArrowIcon /> | ||||||||||||||||||||||||||||||||||||||
</View> | ||||||||||||||||||||||||||||||||||||||
<View className="flex-row items-center"> | ||||||||||||||||||||||||||||||||||||||
<BasicIcon | ||||||||||||||||||||||||||||||||||||||
color={TW_COLORS.CNAM_CYAN_50_LIGHTEN_90} | ||||||||||||||||||||||||||||||||||||||
borderColor={TW_COLORS.CNAM_PRIMARY_500} | ||||||||||||||||||||||||||||||||||||||
iconColor={TW_COLORS.GRAY_950} | ||||||||||||||||||||||||||||||||||||||
icon={"Plus"} | ||||||||||||||||||||||||||||||||||||||
borderWidth={1} | ||||||||||||||||||||||||||||||||||||||
iconContainerStyle={{ marginRight: 0 }} | ||||||||||||||||||||||||||||||||||||||
iconWidth={32} | ||||||||||||||||||||||||||||||||||||||
iconHeight={32} | ||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||
<View className="ml-2 p-2 flex-1"> | ||||||||||||||||||||||||||||||||||||||
<Text className={mergeClassNames(typography.textSmMedium, "text-cnam-primary-950")}>Complétez l'observation</Text> | ||||||||||||||||||||||||||||||||||||||
</View> | ||||||||||||||||||||||||||||||||||||||
</View> | ||||||||||||||||||||||||||||||||||||||
</TouchableOpacity> | ||||||||||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||||||||||
</> | ||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
}; |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mounted ref pattern is being used but the cleanup in useEffect return is not properly implemented. The ref should be properly typed and the cleanup should set mounted.current = false.