Skip to content

Commit

Permalink
fix: OZENSEMBLE-MZ
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Aug 8, 2024
1 parent d3e8a25 commit 4c1a3f3
Showing 1 changed file with 27 additions and 129 deletions.
156 changes: 27 additions & 129 deletions expo/src/components/Reminder.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,92 +46,11 @@ const Reminder = ({
const [weekDay, setWeekDay] = useRecoilState(reminderWeekDayState); // 0 Sunday, 1 Monday -> 6 Saturday
const [reminderSetupVisible, setReminderSetupVisible] = useState(false);
const [reminderErrorAlertVisible, setReminderErrorAlertVisible] = useState(false);
const getReminder = async (showAlert = true) => {
const isRegistered = await NotificationService.checkPermission();
if (Boolean(reminder) && !dayjs(reminder).isValid()) {
deleteReminder();
return;
}
if (!isRegistered && reminder && showAlert) showPermissionsAlert();
if (!reminder) return;
setReminder(dayjs(reminder));
};

const notifHandled = useRef(false);
const handleNotification = (notification) => {
if (Platform.OS === "android") {
if (notification.title === notifReminderTitle) {
navigation.navigate("CONSO_FOLLOW_UP_NAVIGATOR", { screen: "CONSO_FOLLOW_UP" });
logEvent({
category: "CONSO",
action: "CONSO_OPEN",
name: "ORIGIN",
value: CONSTANTS.FROM_BACKGROUND_NOTIFICATION,
});
}
}
if (Platform.OS === "ios") {
if (notification.foreground && !notifHandled.current) {
notifHandled.current = true;
if (notification.message === notifReminderMessage) {
Alert.alert(
notifReminderTitle,
notifReminderMessage,
[
{
text: "Suivi",
onPress: () => {
navigation.navigate("CONSO_FOLLOW_UP_NAVIGATOR", { screen: "CONSO_FOLLOW_UP" });
logEvent({
category: "CONSO",
action: "CONSO_OPEN",
name: "ORIGIN",
value: CONSTANTS.FROM_LOCAL_NOTIFICATION,
});
notifHandled.current = false;
},
},
{
text: "Annuler",
style: "cancel",
onPress: () => {
notifHandled.current = false;
},
},
],
{ cancelable: true }
);
}
} else {
if (notification.message === notifReminderMessage) {
navigation.navigate("CONSO_FOLLOW_UP_NAVIGATOR", { screen: "CONSO_FOLLOW_UP" });
logEvent({
category: "CONSO",
action: "CONSO_OPEN",
name: "ORIGIN",
value: CONSTANTS.FROM_BACKGROUND_NOTIFICATION,
});
}
}
}
};

const scheduleNotification = async (
reminder = new Date(Date.now() + 10 * 1000),
mode = "day",
weekDay = 0
) => {
const scheduleNotification = async (reminder = new Date(Date.now() + 10 * 1000), mode = "day", weekDay = 0) => {
NotificationService.cancelAll();

const weekDayName = [
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
"sunday",
][weekDay];
const weekDayName = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"][weekDay];

if (!storage.getString("STORAGE_KEY_PUSH_NOTIFICATION_TOKEN")) return;

Expand Down Expand Up @@ -259,17 +178,7 @@ const Reminder = ({
});
};

useEffect(() => {
getReminder(false);
const unsubscribe = NotificationService.subscribe(handleNotification);
return () => {
unsubscribe();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const continueButton =
route?.params?.enableContinueButton && route?.params?.onPressContinueNavigation?.length > 0;
const continueButton = route?.params?.enableContinueButton && route?.params?.onPressContinueNavigation?.length > 0;
const continueButtonOnPress = async () => {
if (!reminder) return navigation.navigate(...route.params.onPressContinueNavigation);
setReminderHasBeenSet(true);
Expand All @@ -292,17 +201,13 @@ const Reminder = ({
) : (
<>
<Title>
<TextStyled color="#4030a5">
{title || "Une aide pour penser à noter vos consommations"}
</TextStyled>
<TextStyled color="#4030a5">{title || "Une aide pour penser à noter vos consommations"}</TextStyled>
</Title>
<SubTitle>
{reminder ? (
<>
<TextStyled color="#191919">Vous avez défini un rappel à</TextStyled>
<TextStyled color="#4030a5">{`\n \n${dayjs(reminder).format(
"HH:mm"
)} \n `}</TextStyled>
<TextStyled color="#4030a5">{`\n \n${dayjs(reminder).format("HH:mm")} \n `}</TextStyled>
<TextStyled color="#191919">tous les jours.</TextStyled>
</>
) : (
Expand All @@ -318,16 +223,12 @@ const Reminder = ({
<>
<EditButton content={"Modifier le rappel"} onPress={showReminderSetup} />
<RemoveButton content="Désactiver le rappel" onPress={deleteReminder} />
{continueButton && (
<ButtonPrimary content="Continuer" onPress={continueButtonOnPress} />
)}
{continueButton && <ButtonPrimary content="Continuer" onPress={continueButtonOnPress} />}
</>
) : (
<>
<ButtonPrimary content={"Définir un rappel"} onPress={showReminderSetup} />
{continueButton && (
<EditButton content="Continuer" onPress={continueButtonOnPress} />
)}
{continueButton && <EditButton content="Continuer" onPress={continueButtonOnPress} />}
</>
)}
</ButtonsContainer>
Expand All @@ -338,10 +239,7 @@ const Reminder = ({
hide={() => setReminderSetupVisible(false)}
setReminderRequest={setReminderRequest}
/>
<ReminderErrorAlert
visible={reminderErrorAlertVisible}
hide={() => setReminderErrorAlertVisible(false)}
/>
<ReminderErrorAlert visible={reminderErrorAlertVisible} hide={() => setReminderErrorAlertVisible(false)} />
</Container>
</WrapperContainer>
</>
Expand Down Expand Up @@ -404,7 +302,8 @@ const ModeAndWeekDayChooseModal = ({ visible, hide, setReminderRequest, onlyDail
animationType="fade"
hide={hide}
withBackground
hideOnTouch>
hideOnTouch
>
<ModalContainer>
{mode !== "week" ? (
<>
Expand All @@ -417,15 +316,17 @@ const ModeAndWeekDayChooseModal = ({ visible, hide, setReminderRequest, onlyDail
setMode("day");
setModePickerVisible(false);
setTimeout(() => setTimePickerVisible(true), 500);
}}>
}}
>
Tous les jours
</ModeSelectButton>
<ModeSelectButton
onPress={() => {
setMode("week");
setModePickerVisible(false);
setWeekdayPickerVisible(true);
}}>
}}
>
Une fois par semaine
</ModeSelectButton>
</ModalContent>
Expand All @@ -436,19 +337,18 @@ const ModeAndWeekDayChooseModal = ({ visible, hide, setReminderRequest, onlyDail
<TextStyled color="#4030a5">Quel jour ?</TextStyled>
</ModalTitle>
<ModalContent>
{["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"].map(
(weekDay, index) => (
<ModeSelectButton
key={index}
onPress={() => {
setWeekDay(index % 7);
setWeekdayPickerVisible(false);
setTimeout(() => setTimePickerVisible(true), 500);
}}>
{weekDay}
</ModeSelectButton>
)
)}
{["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"].map((weekDay, index) => (
<ModeSelectButton
key={index}
onPress={() => {
setWeekDay(index % 7);
setWeekdayPickerVisible(false);
setTimeout(() => setTimePickerVisible(true), 500);
}}
>
{weekDay}
</ModeSelectButton>
))}
</ModalContent>
</>
)}
Expand All @@ -472,9 +372,7 @@ const ReminderErrorAlert = ({ visible, hide }) => {
<TextStyled color="#4030a5">Ce service nécessite une connexion internet</TextStyled>
</ModalTitle>
<ModalContent>
<TextStyled>
Veuillez vous connecter à internet avant de définir votre rappel
</TextStyled>
<TextStyled>Veuillez vous connecter à internet avant de définir votre rappel</TextStyled>
</ModalContent>
</ModalContainer>
</Modal>
Expand Down

0 comments on commit 4c1a3f3

Please sign in to comment.