generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: same titles for sent email groups
- Loading branch information
Kyrylo Hudym-Levkovych
authored and
Kyrylo Hudym-Levkovych
committed
Jul 3, 2024
1 parent
10f906b
commit a3da16d
Showing
10 changed files
with
99 additions
and
23 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
export const RECIPIENTS_DISPLAY_NAMES = { | ||
myself: 'Myself', | ||
staff: 'Staff/Administrators', | ||
learners: 'All Learners', | ||
}; | ||
|
||
export const HISTORY_RECIPIENTS_DISPLAY_NAMES = { | ||
'Staff and instructors': 'Staff/Administrators', | ||
'All students': 'All Learners', | ||
}; | ||
|
||
// Output: { 'Myself': 'myself', 'Staff/Administrators': 'staff', 'All Learners': 'learners' } | ||
export const REVERSE_RECIPIENTS_DISPLAY_NAMES = Object.fromEntries( | ||
Object.entries(RECIPIENTS_DISPLAY_NAMES).map(([key, value]) => [value, key]), | ||
); | ||
|
||
export const getDisplayText = (recipient, courseModes) => { | ||
const normalizedRecipient = recipient.replace(/-/, ':'); | ||
|
||
if (normalizedRecipient.startsWith('track') && courseModes) { | ||
const courseModeSlug = normalizedRecipient.split(':')[1]; | ||
const courseMode = courseModes.find((mode) => mode.slug === courseModeSlug); | ||
if (courseMode) { | ||
return `Learners in the ${courseMode.name} Track`; | ||
} | ||
} | ||
|
||
if (normalizedRecipient.startsWith('cohort')) { | ||
const cohort = normalizedRecipient.replace(/:/, ': '); | ||
return cohort.charAt(0).toUpperCase() + cohort.slice(1); | ||
} | ||
|
||
return RECIPIENTS_DISPLAY_NAMES[recipient] || recipient; | ||
}; | ||
|
||
export const getRecipientFromDisplayText = (displayText, courseModes) => { | ||
const trackMatch = displayText.match(/^Learners in the (.+) Track$/); | ||
if (trackMatch) { | ||
const courseModeName = trackMatch[1]; | ||
const courseMode = courseModes.find(mode => mode.name === courseModeName); | ||
if (courseMode) { | ||
return `track:${courseMode.slug}`; | ||
} | ||
} | ||
|
||
const cohortMatch = displayText.match(/^Cohort: (.+)$/); | ||
if (cohortMatch) { | ||
return `cohort:${cohortMatch[1].replace(' ', '-')}`; | ||
} | ||
|
||
return REVERSE_RECIPIENTS_DISPLAY_NAMES[displayText] || displayText; | ||
}; |