Skip to content

Commit

Permalink
fix: Corrige les notifications articles et certaines redirections ver…
Browse files Browse the repository at this point in the history
…s les articles
  • Loading branch information
benguedj committed Jan 15, 2024
1 parent 67ea71b commit 5364e89
Show file tree
Hide file tree
Showing 8 changed files with 481 additions and 442 deletions.
12 changes: 6 additions & 6 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@react-navigation/bottom-tabs": "6.0.9",
"@react-navigation/native": "^6.0.6",
"@react-navigation/stack": "^6.0.11",
"@sentry/react-native": "5.5.0",
"@sentry/react-native": "5.10.0",
"@socialgouv/nos1000jours-lib": "1.2.1",
"babel-plugin-inline-dotenv": "^1.6.0",
"date-fns": "^2.25.0",
Expand All @@ -63,10 +63,10 @@
"expo-asset": "~8.10.1",
"expo-asset-utils": "^2.0.0",
"expo-build-properties": "~0.8.3",
"expo-calendar": "~11.3.0",
"expo-calendar": "~11.3.2",
"expo-constants": "~14.4.2",
"expo-device": "~5.4.0",
"expo-file-system": "~15.4.3",
"expo-file-system": "~15.4.5",
"expo-font": "~11.4.0",
"expo-linking": "~5.0.2",
"expo-localization": "~14.3.0",
Expand All @@ -76,7 +76,7 @@
"expo-status-bar": "~1.6.0",
"expo-store-review": "~6.4.0",
"expo-system-ui": "~2.4.0",
"expo-updates": "~0.18.12",
"expo-updates": "~0.18.19",
"expo-web-browser": "~12.3.2",
"graphql": "^15.7.2",
"html-entities": "^2.3.3",
Expand All @@ -88,7 +88,7 @@
"postinstall-postinstall": "^2.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.4",
"react-native": "0.72.6",
"react-native-animatable": "^1.3.3",
"react-native-calendars": "^1.1268.0",
"react-native-confetti": "^0.1.0",
Expand All @@ -111,7 +111,7 @@
"react-native-vector-icons": "^8.1.0",
"react-native-web": "~0.19.6",
"react-native-webview": "13.2.2",
"sentry-expo": "~7.0.0",
"sentry-expo": "~7.1.0",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
8 changes: 7 additions & 1 deletion front/src/components/article/articleCard.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface Props {
articles: Article[];
step?: Step;
isFromSearchScreen?: boolean;
isFromTndScreen?: boolean;
setStepAndArticleId?: (articleId: number, step: Step | undefined) => void;
onFavoriteUpdate?: () => void;
}
Expand All @@ -36,6 +37,7 @@ const ArticleCard: FC<Props> = ({
articles,
step,
isFromSearchScreen,
isFromTndScreen,
setStepAndArticleId,
onFavoriteUpdate,
}) => {
Expand Down Expand Up @@ -68,7 +70,11 @@ const ArticleCard: FC<Props> = ({
}, [checkReadAndFavorites]);

const onItemPressed = useCallback(async () => {
if (isFromSearchScreen && setStepAndArticleId && article)
if (
(isFromSearchScreen || isFromTndScreen) &&
setStepAndArticleId &&
article
)
setStepAndArticleId(article.id, step);
else {
const isScreenReaderEnabled =
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/article/imageBanner.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ImageBanner: FC<Props> = ({ visuel }) => {
}}
containerStyle={[styles.articleImage]}
height={200}
width="100%"
resizeMode="cover"
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { FC } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import * as React from "react";

import { Labels } from "../../constants";
import { Labels, NotificationConstants } from "../../constants";
import { NotificationUtils, TrackerUtils } from "../../utils";
import { NotificationModal } from "../baseComponents";
import TrackerHandler from "../tracker/trackerHandler.component";
Expand All @@ -31,7 +31,11 @@ const NotificationHandler: FC = () => {
// Ajoute un setTimeout pour éviter que l'application freeze
// lorsque l'on ouvre l'app depuis une notification
setTimeout(() => {
setNotification(notif);
const redirectTo = notif.request.content.data.redirectTo as string;
const params = notif.request.content.data.redirectParams as string;
if (redirectTo === NotificationConstants.SCREEN_ARTICLES && !params)
return false;
else setNotification(notif);
}, 1000);
};

Expand Down
25 changes: 20 additions & 5 deletions front/src/screens/home/tabHomeScreen.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
StringUtils,
TrackerUtils,
} from "../../utils";
import { NotificationType } from "../../utils/notifications/notification.util";

interface Props {
navigation: StackNavigationProp<TabHomeParamList>;
Expand Down Expand Up @@ -89,18 +90,32 @@ const TabHomeScreen: FC<Props> = ({ navigation }) => {
}, [currentStep]);

const scheduleArticlesNotificationIfNeeded = useCallback(async () => {
if (currentStep) {
const triggerForArticlesNotification = await StorageUtils.getObjectValue(
StorageKeysConstants.triggerForArticlesNotification
const articlesNotification =
await NotificationUtils.getAllNotificationsByType(
NotificationType.articles
);
// Programme la notification des articles non lus si cette notification n'a jamais été programmée ou si il y a un changement d'étape

if (currentStep) {
// Programme la notification des articles non lus si :
// - cette notification n'a jamais été programmée
// - cette notification est déjà programmée mais qu'il n'y a pas de 'redirectParams'
// - il y a un changement d'étape
if (
!triggerForArticlesNotification ||
articlesNotification.length === 0 ||
(articlesNotification.length > 0 &&
!articlesNotification[0].content.data.redirectParams) ||
(StringUtils.isNotNullNorEmpty(previousCurrentStepId) &&
previousCurrentStepId !== currentStep.id.toString())
) {
await NotificationUtils.scheduleArticlesNotification();
}
} else {
// Annule la notification si l'étape courante n'est pas définie
if (articlesNotification.length > 0) {
await NotificationUtils.cancelAllNotificationsByType(
NotificationType.articles
);
}
}
}, [currentStep, previousCurrentStepId]);

Expand Down
76 changes: 71 additions & 5 deletions front/src/screens/tndSurvey/tndSurveyResult.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ import HTML from "react-native-render-html";
import WebView from "react-native-webview";

import ImgBtnReview from "../../assets/images/btn-review-sp-plus.svg";
import { ArticleCard } from "../../components";
import { CommonText, TitleH1, View } from "../../components/baseComponents";
import { ArticleList } from "../../components";
import {
CommonText,
SecondaryTextItalic,
TitleH1,
View,
} from "../../components/baseComponents";
import {
FetchPoliciesConstants,
HomeDbQueries,
Expand All @@ -22,8 +27,58 @@ import { GraphQLMutation, GraphQLQuery } from "../../services";
import { Colors, FontWeight, Margins, Paddings, Sizes } from "../../styles";
import type { SurveyQuestionAndAnswers } from "../../type";
import type { TndAnswers, TndQuestionnaire } from "../../type/tndSurvey.types";
import type { Article } from "../../types";
import type { Article, Step } from "../../types";
import { LinkingUtils, TndSurveyUtils } from "../../utils";
import ArticleDetail from "../articles/articleDetail.component";

export const ArticlesRoute = (
updatedText: string,
articles: Article[]
): React.ReactElement => {
const [showArticle, setShowArticle] = useState(false);
const [currentArticleId, setCurrentArticleId] = useState(0);
const [currentArticleStep, setCurrentArticleStep] = useState<
Step | undefined
>();

const onBackButtonPressed = useCallback(() => {
setShowArticle(false);
}, []);

const onUpdateStepAndArticleId = useCallback(
(articleId: number, step: Step | undefined) => {
setShowArticle(true);
setCurrentArticleId(articleId);
setCurrentArticleStep(step);
},
[]
);

if (articles.length <= 0) {
return (
<View style={styles.center}>
<SecondaryTextItalic>{updatedText}</SecondaryTextItalic>
</View>
);
}

return showArticle ? (
<ArticleDetail
_articleId={currentArticleId}
_articleStep={currentArticleStep}
goBack={onBackButtonPressed}
/>
) : (
<View style={styles.listContainer}>
<ArticleList
articles={articles}
animationDuration={500}
isFromSearchScreen
setStepAndArticleId={onUpdateStepAndArticleId}
/>
</View>
);
};

interface Props {
result: number;
Expand Down Expand Up @@ -118,14 +173,16 @@ const TndSurveyResult: FC<Props> = ({ survey, tndQuestionnaire }) => {
<CommonText style={styles.listArticlesTitle}>
{Labels.tndSurvey.surveyResult.articlesToRead}
</CommonText>
{handicapArticles.map((article, index) => (
{/* {handicapArticles.map((article, index) => (
<View key={index}>
<ArticleCard
selectedArticleId={article.id}
articles={handicapArticles}
isFromTndScreen={true}
/>
</View>
))}
))} */}
{ArticlesRoute("", handicapArticles)}
</View>
)}
</ScrollView>
Expand All @@ -138,6 +195,11 @@ const styles = StyleSheet.create({
alignItems: "center",
marginTop: Paddings.default,
},
center: {
alignItems: "center",
justifyContent: "center",
margin: Margins.default,
},
fontBold: {
fontWeight: FontWeight.bold,
},
Expand All @@ -156,6 +218,10 @@ const styles = StyleSheet.create({
paddingTop: Paddings.default,
paddingVertical: Paddings.smaller,
},
listContainer: {
paddingHorizontal: Paddings.default,
paddingVertical: Paddings.smallest,
},
marginHorizontal: {
marginHorizontal: Margins.default,
},
Expand Down
56 changes: 30 additions & 26 deletions front/src/utils/notifications/notification.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,32 +394,35 @@ export const buildArticlesNotificationContent = async (
StorageKeysConstants.currentStep
)) as Step | null;

if (nbArticlesToRead > 0) {
return {
body: `${Labels.article.notification.articlesToRead.bodyPart1} ${nbArticlesToRead} ${Labels.article.notification.articlesToRead.bodyPart2}.`,
data: {
redirectFromRoot: false,
redirectParams: { step: currentStep },
redirectTitle: Labels.article.notification.articlesToRead.redirectTitle,
redirectTo: NotificationConstants.SCREEN_ARTICLES,
type: NotificationType.articles,
},
title: Labels.article.notification.articlesToRead.title,
};
}
if (nbArticlesToRead === 0) {
return {
body: Labels.article.notification.congrats.body,
data: {
confetti: true,
redirectFromRoot: false,
redirectParams: null,
redirectTitle: Labels.article.notification.congrats.redirectTitle,
redirectTo: null,
type: NotificationType.articles,
},
title: Labels.article.notification.congrats.title,
};
if (currentStep) {
if (nbArticlesToRead > 0) {
return {
body: `${Labels.article.notification.articlesToRead.bodyPart1} ${nbArticlesToRead} ${Labels.article.notification.articlesToRead.bodyPart2}.`,
data: {
redirectFromRoot: false,
redirectParams: { step: currentStep },
redirectTitle:
Labels.article.notification.articlesToRead.redirectTitle,
redirectTo: NotificationConstants.SCREEN_ARTICLES,
type: NotificationType.articles,
},
title: Labels.article.notification.articlesToRead.title,
};
}
if (nbArticlesToRead === 0) {
return {
body: Labels.article.notification.congrats.body,
data: {
confetti: true,
redirectFromRoot: false,
redirectParams: null,
redirectTitle: Labels.article.notification.congrats.redirectTitle,
redirectTo: null,
type: NotificationType.articles,
},
title: Labels.article.notification.congrats.title,
};
}
}

return null;
Expand Down Expand Up @@ -595,6 +598,7 @@ export const scheduleFakeNotif = async (
case NotificationType.articles: {
const nbArticlesToRead = await nbOfUnreadArticlesInCurrentStep();
content = await buildArticlesNotificationContent(nbArticlesToRead);
if (content?.data?.redirectParams) content.data.redirectParams = null;
break;
}
case NotificationType.inAppReview:
Expand Down
Loading

0 comments on commit 5364e89

Please sign in to comment.