Skip to content

Commit

Permalink
feat(notifs): centre de notifs pour les articles (#1418)
Browse files Browse the repository at this point in the history
* feat(notifs): création de la page

* feat(notifs): activer/désactiver notif articles

* feat(notifs): accessibilité

* feat(notif): retours PR

* feat(notifs): retours PR

* feat(notifs): retours PR
  • Loading branch information
alebret authored Sep 5, 2022
1 parent df50a35 commit baefebf
Show file tree
Hide file tree
Showing 11 changed files with 386 additions and 35 deletions.
7 changes: 7 additions & 0 deletions front/src/components/menu/menu.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ const Menu: React.FC<Props> = ({ showMenu, setShowMenu }) => {
},
title: Labels.timeline.library.nom,
},
{
icon: IcomoonIcons.notification,
onPress: () => {
void RootNavigation.navigate("notificationsCenter");
},
title: Labels.menu.notificationsCenter,
},
{
icon: IcomoonIcons.email,
onPress: () => {
Expand Down
116 changes: 116 additions & 0 deletions front/src/components/notification/notificationToggle.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import type { FC } from "react";
import * as React from "react";
import { useCallback, useEffect, useState } from "react";
import { StyleSheet, Text, View } from "react-native";

import { Toggle } from "../../components/baseComponents";
import { Labels, StorageKeysConstants } from "../../constants";
import { Colors, FontStyle, FontWeight, Margins } from "../../styles";
import { StorageUtils } from "../../utils";
import * as NotificationUtils from "../../utils/notification.util";
import { NotificationType } from "../../utils/notification.util";

interface Props {
title: string;
description: string;
type: NotificationType;
}

const NotificationToggle: FC<Props> = ({ title, description, type }) => {
const [isToggleOn, setToggleOn] = useState(false);

useEffect(() => {
void initToggle();
}, []);

const initToggle = async () => {
// Value in storage
const storageValue = (await StorageUtils.getObjectValue(
StorageKeysConstants.notifToggleArticles
)) as boolean;
setToggleOn(storageValue);
};

const onTouchToggle = useCallback(async () => {
const newValue = !isToggleOn;
setToggleOn(newValue);
await StorageUtils.storeObjectValue(
StorageKeysConstants.notifToggleArticles,
newValue
);

if (newValue) {
if (type === NotificationType.articles)
void NotificationUtils.updateArticlesNotification();
} else await NotificationUtils.cancelAllNotificationsByType(type);
}, [isToggleOn, type]);

return (
<View style={styles.mainContent}>
<View style={styles.itemTextBloc}>
<Text style={styles.itemTextTitle} accessibilityRole="header">
{title}
</Text>
<Text style={styles.itemTextDescr}>{description}</Text>
</View>
<View style={styles.itemToggleBloc}>
<Text
style={[
styles.itemToggleText,
isToggleOn ? null : { fontWeight: FontWeight.bold },
]}
importantForAccessibility="no"
accessibilityElementsHidden
accessible={false}
>
{Labels.buttons.no}
</Text>
<View style={styles.itemToggle}>
<Toggle isToggleOn={isToggleOn} toggleSwitch={onTouchToggle} />
</View>
<Text
style={[
styles.itemToggleText,
isToggleOn ? { fontWeight: FontWeight.bold } : null,
]}
importantForAccessibility="no"
accessibilityElementsHidden
accessible={false}
>
{Labels.buttons.yes}
</Text>
</View>
</View>
);
};

const styles = StyleSheet.create({
itemTextBloc: {
flex: 2,
},
itemTextDescr: {
color: Colors.grey,
fontStyle: FontStyle.italic,
marginTop: Margins.smaller,
},
itemTextTitle: {
fontWeight: FontWeight.bold,
},
itemToggle: {
marginHorizontal: Margins.smaller,
},
itemToggleBloc: {
flex: 1,
flexDirection: "row",
justifyContent: "center",
},
itemToggleText: {
color: Colors.secondaryGreenDark,
},
mainContent: {
flexDirection: "row",
marginVertical: Margins.larger,
},
});

export default NotificationToggle;
11 changes: 11 additions & 0 deletions front/src/constants/Labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ export default {
moodboard: "Suivi d'humeur",
myFavorites: "Mes favoris",
myProfil: "Mon profil",
notificationsCenter: "Centre de notification",
title: "Menu",
},
moodboard: {
Expand All @@ -593,6 +594,16 @@ export default {
notification: {
openTheApp: "Ouverture de l'app",
},
notificationsCenter: {
article: {
decription:
"Vous précisant qu’il y a tel article non lu sur votre étape.",
title: "Notifications des articles non lus",
},
description:
"Ici vous pouvez paramétrer les notifications que vous souhaitez recevoir en les activant/désactivant :",
title: "Paramètres de notifications",
},
onboarding: {
screenNumber: "Écran n°",
slidesText: [
Expand Down
2 changes: 2 additions & 0 deletions front/src/constants/storageKeys.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const cartoSavedCoordinates = "@cartoSavedCoordinates";
export const cartoIsFirstLaunch = "@cartoIsFirstLaunch";
export const notifIdNextStep = "@notifIdNextStep";
export const notifIdsEvents = "@notifIdsEvents";
export const notifToggleArticles = "@notifToggleArticles";
export const eventsCalcFromBirthday = "@eventsCalcFromBirthday";
export const forceToScheduleEventsNotif = "@forceToScheduleEventsNotif";
export const osCalendarId = "@osCalendarId";
Expand Down Expand Up @@ -53,6 +54,7 @@ export const allStorageKeys = [
cartoIsFirstLaunch,
notifIdNextStep,
notifIdsEvents,
notifToggleArticles,
eventsCalcFromBirthday,
forceToScheduleEventsNotif,
osCalendarId,
Expand Down
17 changes: 17 additions & 0 deletions front/src/navigation/BottomTabNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
TabHomeScreen,
TabSearchScreen,
} from "../screens";
import NotificationsCenter from "../screens/notificationsCenter/notificationsCenter.component";
import { Colors } from "../styles";
import type {
BottomTabParamList,
Expand Down Expand Up @@ -135,6 +136,10 @@ const TabHomeNavigator: FC = () => (
<TabHomeStack.Screen name="parentheque" component={Parentheque} />
<TabHomeStack.Screen name="article" component={ArticleDetail} />
<TabHomeStack.Screen name="epdsSurvey" component={TabEpdsScreen} />
<TabHomeStack.Screen
name="notificationsCenter"
component={NotificationsCenter}
/>
</TabHomeStack.Navigator>
);

Expand All @@ -150,6 +155,10 @@ const TabCalendarNavigator: FC = () => (
<TabCalendarStack.Screen name="article" component={ArticleDetail} />
<TabHomeStack.Screen name="parentheque" component={Parentheque} />
<TabCalendarStack.Screen name="aroundMeScreen" component={AroundMeScreen} />
<TabHomeStack.Screen
name="notificationsCenter"
component={NotificationsCenter}
/>
</TabCalendarStack.Navigator>
);

Expand All @@ -162,6 +171,10 @@ const TabEpdsNavigator: FC = () => (
options={{}}
/>
<TabHomeStack.Screen name="parentheque" component={Parentheque} />
<TabHomeStack.Screen
name="notificationsCenter"
component={NotificationsCenter}
/>
</TabEpdsStack.Navigator>
);

Expand All @@ -178,6 +191,10 @@ const TabSearchNavigator: FC = () => (
component={AroundMeMapAndList}
/>
<TabHomeStack.Screen name="parentheque" component={Parentheque} />
<TabHomeStack.Screen
name="notificationsCenter"
component={NotificationsCenter}
/>
</TabSearchStack.Navigator>
);

Expand Down
2 changes: 2 additions & 0 deletions front/src/screens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Parentheque from "./home/parentheque.component";
import TabHomeScreen from "./home/tabHomeScreen.component";
import LoadingScreen from "./loading/loading.component";
import Moodboard from "./moodboard/moodboard.component";
import NotificationsCenter from "./notificationsCenter/notificationsCenter.component";
import Onboarding from "./onboardingAndProfile/onboarding.component";
import Profile from "./onboardingAndProfile/profile.component";
import AroundMeMapAndList from "./search/aroundMeMapAndList.component";
Expand All @@ -27,6 +28,7 @@ export {
EventDetails,
LoadingScreen,
Moodboard,
NotificationsCenter,
Onboarding,
Parentheque,
Profile,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import type { StackNavigationProp } from "@react-navigation/stack";
import type { FC } from "react";
import * as React from "react";
import { useCallback, useState } from "react";
import { ScrollView, StyleSheet, View } from "react-native";

import { BackButton, TitleH1 } from "../../components/baseComponents";
import NotificationToggle from "../../components/notification/notificationToggle.component";
import TrackerHandler from "../../components/tracker/trackerHandler.component";
import { Labels } from "../../constants";
import { Colors, Paddings } from "../../styles";
import type { RootStackParamList } from "../../types";
import { TrackerUtils } from "../../utils";
import { NotificationType } from "../../utils/notification.util";

interface Props {
navigation: StackNavigationProp<RootStackParamList>;
}

const NotificationsCenter: FC<Props> = ({ navigation }) => {
const [trackerAction, setTrackerAction] = useState<string>("");

const goBack = useCallback(() => {
setTrackerAction(Labels.buttons.cancel);
navigation.goBack();
}, [navigation]);

return (
<ScrollView style={styles.mainContainer}>
<TrackerHandler
screenName={TrackerUtils.TrackingEvent.NOTIFICATIONS_CENTER}
actionName={trackerAction}
/>
<View style={styles.header}>
<View style={styles.flexStart}>
<BackButton action={goBack} />
</View>
<TitleH1
animated={false}
title={Labels.notificationsCenter.title}
description={Labels.notificationsCenter.description}
/>
<NotificationToggle
title={Labels.notificationsCenter.article.title}
description={Labels.notificationsCenter.article.decription}
type={NotificationType.articles}
/>
</View>
</ScrollView>
);
};

const styles = StyleSheet.create({
flexStart: {
alignItems: "flex-start",
},
header: {
padding: Paddings.default,
paddingTop: Paddings.default,
},
mainContainer: {
backgroundColor: Colors.white,
},
});

export default NotificationsCenter;
1 change: 1 addition & 0 deletions front/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type TabHomeParamList = {
parentheque: { documents?: Document[] };
article: { id: number; step?: Step };
epdsSurvey: undefined;
notificationsCenter: undefined;
};

export type TabCalendarParamList = {
Expand Down
Loading

0 comments on commit baefebf

Please sign in to comment.