-
-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5db0997
commit 7269e8b
Showing
10 changed files
with
162 additions
and
84 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...ts/HomePage/QuranGrowthJourneySection/CallToActionButtons/CallToActionButtons.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.viewPlansBtn { | ||
margin-inline-end: var(--spacing-small); | ||
} | ||
|
||
.buttonsContainer { | ||
display: flex; | ||
padding-block-start: var(--spacing-xxsmall); | ||
} |
73 changes: 73 additions & 0 deletions
73
...omponents/HomePage/QuranGrowthJourneySection/CallToActionButtons/LearningPlansButtons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = ( | ||
<Button | ||
onClick={onViewPlansButtonClicked} | ||
href={getCoursesNavigationUrl()} | ||
className={styles.viewPlansBtn} | ||
size={ButtonSize.Small} | ||
> | ||
{t('qgj.learning-plans.cta.all-plans')} | ||
</Button> | ||
); | ||
|
||
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 ( | ||
<div className={styles.buttonsContainer}> | ||
{viewPlansButton} | ||
<Button | ||
onClick={onMyPlansButtonClicked} | ||
href={getMyCoursesNavigationUrl()} | ||
size={ButtonSize.Small} | ||
> | ||
{t('qgj.learning-plans.cta.my-plans')} | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LearningPlansButtons; |
48 changes: 48 additions & 0 deletions
48
src/components/HomePage/QuranGrowthJourneySection/CallToActionButtons/QuranGoalsButtons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<GoalButtons nextVerseToRead={nextVerseToRead} currentActivityDay={currentActivityDay} /> | ||
); | ||
} | ||
|
||
return ( | ||
<div className={styles.buttonsContainer}> | ||
<Button | ||
onClick={onCreateReadingGoalClick} | ||
size={ButtonSize.Small} | ||
href={getReadingGoalNavigationUrl()} | ||
> | ||
{t('create-reading-goal')} | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default QuranGoalsButtons; |
8 changes: 0 additions & 8 deletions
8
...Page/QuranGrowthJourneySection/CollapsibleSection/LearningPlans/LearningPlans.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,3 @@ | ||
.buttonsContainer { | ||
display: flex; | ||
} | ||
|
||
.desc { | ||
margin-block-end: var(--spacing-small); | ||
} | ||
|
||
.viewPlansBtn { | ||
margin-inline-end: var(--spacing-small); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...thJourneySection/CollapsibleSection/QuranReadingGoals/GoalButtons/GoalButtons.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters