-
-
Notifications
You must be signed in to change notification settings - Fork 469
feat(settings): add email frequency setting #2039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chrismclarke
merged 6 commits into
ONEARMY:master
from
evakill:2028-email-frequency-setting
Dec 21, 2022
+76
−2
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
17128ff
feat(settings): add email frequency setting
evakill 7374dda
chore: fix lint issue
chrismclarke 0c43d31
feat(settings): default frequency to never
evakill 50b1759
Merge branch 'master' into 2028-email-frequency-setting
evakill dc4ac9e
Merge branch 'master' into 2028-email-frequency-setting
chrismclarke c6d77b3
chore: restrict notification settings to beta-testers
chrismclarke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
60 changes: 60 additions & 0 deletions
60
src/pages/Settings/content/formSections/EmailNotifications.section.tsx
This file contains hidden or 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,60 @@ | ||
| import * as React from 'react' | ||
| import { Heading, Box, Text } from 'theme-ui' | ||
| import { FlexSectionContainer } from './elements' | ||
| import { observer, inject } from 'mobx-react' | ||
| import { Select } from 'oa-components' | ||
| import type { INotificationSettings } from 'src/models/user.models' | ||
| import { EmailNotificationFrequency } from 'src/models/user.models' | ||
| import { Field } from 'react-final-form' | ||
|
|
||
| interface IProps { | ||
| notificationSettings?: INotificationSettings | ||
| } | ||
|
|
||
| const emailFrequencyOptions: { | ||
| value: EmailNotificationFrequency | ||
| label: string | ||
| }[] = [ | ||
| { value: EmailNotificationFrequency.NEVER, label: 'Never' }, | ||
| { value: EmailNotificationFrequency.DAILY, label: 'Daily' }, | ||
| { value: EmailNotificationFrequency.WEEKLY, label: 'Weekly' }, | ||
| { value: EmailNotificationFrequency.MONTHLY, label: 'Monthly' }, | ||
| ] | ||
|
|
||
| @inject('userStore') | ||
| @observer | ||
| export class EmailNotificationsSection extends React.Component<any> { | ||
| constructor(props: IProps) { | ||
| super(props) | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <FlexSectionContainer> | ||
| <Heading variant="small">Email notifications</Heading> | ||
| <Text mt={4} mb={4} sx={{ display: 'block' }}> | ||
| We send an email with all the notifications you've missed. Select how | ||
| often you want to receive this: | ||
| </Text> | ||
| <Box mt={2} sx={{ width: '40%' }}> | ||
| <Field name="notification_settings.emailFrequency"> | ||
| {({ input }) => { | ||
| return ( | ||
| <Select | ||
| options={emailFrequencyOptions} | ||
| defaultValue={emailFrequencyOptions.find( | ||
| ({ value }) => | ||
| value === | ||
| this.props.notificationSettings?.emailFrequency ?? | ||
| EmailNotificationFrequency.NEVER, | ||
| )} | ||
| onChange={({ value }) => input.onChange(value)} | ||
| /> | ||
| ) | ||
| }} | ||
| </Field> | ||
| </Box> | ||
| </FlexSectionContainer> | ||
| ) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for adding the check for users without any settings (still don't have an nice way to migrate all user profiles when we add new fields).
nit(blocking)
I like the idea that this will get users without notifications enabled to automatically opt in next time they save their profile, although I think probably to keep things a bit clearer it would be better to make the default value never and we can organise a migration in the future to set another default value to all users if required.