From 7269e8b5d55cf66e88ba9be5eddac38f8ef98e2f Mon Sep 17 00:00:00 2001 From: Osama Sayed Date: Fri, 1 Mar 2024 16:26:33 +0700 Subject: [PATCH] updates --- .../CallToActionButtons.module.scss | 8 ++ .../LearningPlansButtons.tsx | 73 +++++++++++++++++++ .../CallToActionButtons/QuranGoalsButtons.tsx | 48 ++++++++++++ .../LearningPlans/LearningPlans.module.scss | 8 -- .../LearningPlans/index.tsx | 46 +----------- .../GoalButtons/GoalButtons.module.scss | 2 +- .../QuranReadingGoals/GoalButtons/index.tsx | 12 ++- .../QuranReadingGoals/index.tsx | 35 +++------ .../CollapsibleSection/index.tsx | 12 ++- .../QuranGrowthJourneySection.module.scss | 2 +- 10 files changed, 162 insertions(+), 84 deletions(-) create mode 100644 src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/CallToActionButtons.module.scss create mode 100644 src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/LearningPlansButtons.tsx create mode 100644 src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/QuranGoalsButtons.tsx diff --git a/src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/CallToActionButtons.module.scss b/src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/CallToActionButtons.module.scss new file mode 100644 index 0000000000..d8f762b61d --- /dev/null +++ b/src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/CallToActionButtons.module.scss @@ -0,0 +1,8 @@ +.viewPlansBtn { + margin-inline-end: var(--spacing-small); +} + +.buttonsContainer { + display: flex; + padding-block-start: var(--spacing-xxsmall); +} diff --git a/src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/LearningPlansButtons.tsx b/src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/LearningPlansButtons.tsx new file mode 100644 index 0000000000..2286666ea3 --- /dev/null +++ b/src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/LearningPlansButtons.tsx @@ -0,0 +1,73 @@ +import React from 'react'; + +import useTranslation from 'next-translate/useTranslation'; +import useSWRImmutable from 'swr/immutable'; + +import styles from './CallToActionButtons.module.scss'; + +import Button, { ButtonSize } from '@/dls/Button/Button'; +import { getUserCoursesCount } from '@/utils/auth/api'; +import { makeGetUserCoursesCountUrl } from '@/utils/auth/apiPaths'; +import { isLoggedIn } from '@/utils/auth/login'; +import { logButtonClick } from '@/utils/eventLogger'; +import { getCoursesNavigationUrl, getMyCoursesNavigationUrl } from '@/utils/navigation'; + +const LearningPlansButtons = () => { + const { t } = useTranslation('home'); + const { data, isValidating, error } = useSWRImmutable( + isLoggedIn() ? makeGetUserCoursesCountUrl() : null, + async () => { + const response = await getUserCoursesCount(); + return response; + }, + ); + + const onViewPlansButtonClicked = (e) => { + // don't toggle collapsible parent when clicking + e.stopPropagation(); + logButtonClick('homepage_qgj_view_plans'); + }; + + const onMyPlansButtonClicked = (e) => { + e.stopPropagation(); + logButtonClick('homepage_qgj_my_plans'); + }; + + const viewPlansButton = ( + + ); + + if (!isLoggedIn()) { + return viewPlansButton; + } + + /** + * If we are loading, or if we have an error, or if we have no data, we show the message + */ + if ((isValidating && !data) || error || (data?.count ?? 0) === 0) { + return viewPlansButton; + } + + // user has already 1 plan + return ( +
+ {viewPlansButton} + +
+ ); +}; + +export default LearningPlansButtons; diff --git a/src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/QuranGoalsButtons.tsx b/src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/QuranGoalsButtons.tsx new file mode 100644 index 0000000000..cd311d7e83 --- /dev/null +++ b/src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/QuranGoalsButtons.tsx @@ -0,0 +1,48 @@ +import React from 'react'; + +import useTranslation from 'next-translate/useTranslation'; + +import styles from './CallToActionButtons.module.scss'; + +import GoalButtons from '@/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/QuranReadingGoals/GoalButtons'; +import Button, { ButtonSize } from '@/dls/Button/Button'; +import useGetRecentlyReadVerseKeys from '@/hooks/auth/useGetRecentlyReadVerseKeys'; +import useGetStreakWithMetadata from '@/hooks/auth/useGetStreakWithMetadata'; +import { logButtonClick } from '@/utils/eventLogger'; +import { getReadingGoalNavigationUrl } from '@/utils/navigation'; + +const QuranGoalsButtons = () => { + const { t } = useTranslation('reading-goal'); + const { goal, currentActivityDay } = useGetStreakWithMetadata({ + disableIfNoGoalExists: false, + }); + const { recentlyReadVerseKeys } = useGetRecentlyReadVerseKeys(); + + const nextVerseToRead = goal?.progress?.nextVerseToRead ?? recentlyReadVerseKeys[0]; + + const onCreateReadingGoalClick = (e) => { + // don't toggle collapsible parent when clicking + e.stopPropagation(); + logButtonClick('homepage_qgj_create_goal'); + }; + + if (goal) { + return ( + + ); + } + + return ( +
+ +
+ ); +}; + +export default QuranGoalsButtons; diff --git a/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/LearningPlans/LearningPlans.module.scss b/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/LearningPlans/LearningPlans.module.scss index a5ff7d3a46..45266a19f3 100644 --- a/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/LearningPlans/LearningPlans.module.scss +++ b/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/LearningPlans/LearningPlans.module.scss @@ -1,11 +1,3 @@ -.buttonsContainer { - display: flex; -} - .desc { margin-block-end: var(--spacing-small); } - -.viewPlansBtn { - margin-inline-end: var(--spacing-small); -} diff --git a/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/LearningPlans/index.tsx b/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/LearningPlans/index.tsx index 2490e52bf6..664ce1cb83 100644 --- a/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/LearningPlans/index.tsx +++ b/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/LearningPlans/index.tsx @@ -5,24 +5,13 @@ import useSWRImmutable from 'swr/immutable'; import styles from './LearningPlans.module.scss'; -import Button, { ButtonSize } from '@/dls/Button/Button'; import { getUserCoursesCount } from '@/utils/auth/api'; import { makeGetUserCoursesCountUrl } from '@/utils/auth/apiPaths'; import { isLoggedIn } from '@/utils/auth/login'; -import { logButtonClick } from '@/utils/eventLogger'; -import { getCoursesNavigationUrl, getMyCoursesNavigationUrl } from '@/utils/navigation'; const LearningPlans = () => { const { t } = useTranslation('home'); - const onViewPlansButtonClicked = () => { - logButtonClick('homepage_qgj_view_plans'); - }; - - const onMyPlansButtonClicked = () => { - logButtonClick('homepage_qgj_my_plans'); - }; - const { data, isValidating, error } = useSWRImmutable( isLoggedIn() ? makeGetUserCoursesCountUrl() : null, async () => { @@ -31,24 +20,8 @@ const LearningPlans = () => { }, ); - const viewPlansButton = ( - - ); - if (!isLoggedIn()) { - return ( -
-

{t('qgj.learning-plans.desc.logged-out')}

- {viewPlansButton} -
- ); + return

{t('qgj.learning-plans.desc.logged-out')}

; } /** @@ -58,26 +31,11 @@ const LearningPlans = () => { return (

{t('qgj.learning-plans.desc.logged-in-no-plans')}

- {viewPlansButton}
); } // user has at least 1 plan - return ( -
-

{t('qgj.learning-plans.desc.logged-in')}

-
- {viewPlansButton} - -
-
- ); + return

{t('qgj.learning-plans.desc.logged-in')}

; }; export default LearningPlans; diff --git a/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/QuranReadingGoals/GoalButtons/GoalButtons.module.scss b/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/QuranReadingGoals/GoalButtons/GoalButtons.module.scss index e9ec045160..37d38239c7 100644 --- a/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/QuranReadingGoals/GoalButtons/GoalButtons.module.scss +++ b/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/QuranReadingGoals/GoalButtons/GoalButtons.module.scss @@ -1,5 +1,5 @@ .actionsContainer { - margin-block-start: var(--spacing-large); + padding-block-start: var(--spacing-xxsmall); display: flex; align-items: center; diff --git a/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/QuranReadingGoals/GoalButtons/index.tsx b/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/QuranReadingGoals/GoalButtons/index.tsx index d240eb3972..6b8121e719 100644 --- a/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/QuranReadingGoals/GoalButtons/index.tsx +++ b/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/QuranReadingGoals/GoalButtons/index.tsx @@ -4,7 +4,7 @@ import useTranslation from 'next-translate/useTranslation'; import styles from './GoalButtons.module.scss'; -import Button, { ButtonVariant } from '@/dls/Button/Button'; +import Button, { ButtonSize, ButtonVariant } from '@/dls/Button/Button'; import { CurrentQuranActivityDay } from '@/types/auth/ActivityDay'; import { logButtonClick } from '@/utils/eventLogger'; import { @@ -19,11 +19,15 @@ type Props = { const GoalButtons: React.FC = ({ nextVerseToRead, currentActivityDay }) => { const { t } = useTranslation('reading-goal'); - const onViewProgressClick = () => { + const onViewProgressClick = (e) => { + // don't toggle collapsible parent when clicking + e.stopPropagation(); logButtonClick('homepage_streak_widget_view_progress'); }; - const onContinueReadingClick = () => { + const onContinueReadingClick = (e) => { + // don't toggle collapsible parent when clicking + e.stopPropagation(); logButtonClick('homepage_streak_widget_continue_reading', { // eslint-disable-next-line @typescript-eslint/naming-convention verse_key: nextVerseToRead, @@ -36,11 +40,13 @@ const GoalButtons: React.FC = ({ nextVerseToRead, currentActivityDay }) = href={nextVerseToRead ? getChapterWithStartingVerseUrl(nextVerseToRead) : undefined} isDisabled={!nextVerseToRead} onClick={onContinueReadingClick} + size={ButtonSize.Small} > {t(currentActivityDay?.ranges.length ? 'continue-reading' : 'start-reading')} - )} - + {goal && ( +
+ +
+ )} ); }; diff --git a/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/index.tsx b/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/index.tsx index af7b80fe72..17a4a11397 100644 --- a/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/index.tsx +++ b/src/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/index.tsx @@ -6,6 +6,8 @@ import styles from './CollapsibleSection.module.scss'; import CollapsibleTitle from './CollapsibleTitle'; import LearningPlans from './LearningPlans'; +import LearningPlansButtons from '@/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/LearningPlansButtons'; +import QuranGoalsButtons from '@/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/QuranGoalsButtons'; import QuranReadingGoals from '@/components/HomePage/QuranGrowthJourneySection/CollapsibleSection/QuranReadingGoals'; import Collapsible, { CollapsibleDirection } from '@/dls/Collapsible/Collapsible'; import ChevronDownIcon from '@/icons/chevron-down.svg'; @@ -36,9 +38,15 @@ const CollapsibleSection: React.FC = ({ onOpenChange, type }) => { shouldOpen={isOpen} title={ type === CollapsibleType.QuranReadingGoalsType ? ( - } /> +
+ } /> + +
) : ( - } /> +
+ } /> + +
) } prefix={} diff --git a/src/components/HomePage/QuranGrowthJourneySection/QuranGrowthJourneySection.module.scss b/src/components/HomePage/QuranGrowthJourneySection/QuranGrowthJourneySection.module.scss index 8174d8dfa7..0238989c95 100644 --- a/src/components/HomePage/QuranGrowthJourneySection/QuranGrowthJourneySection.module.scss +++ b/src/components/HomePage/QuranGrowthJourneySection/QuranGrowthJourneySection.module.scss @@ -5,7 +5,7 @@ $widget-wrapper-background-color: var(--color-success-faded); .wrapper { background-color: $widget-wrapper-background-color; - padding: var(--spacing-large); + padding: var(--spacing-small); position: relative; @include breakpoints.tablet {