diff --git a/assets/components/NotificationPopup.tsx b/assets/components/NotificationPopup.tsx index e3bb04de7..865a1eff1 100644 --- a/assets/components/NotificationPopup.tsx +++ b/assets/components/NotificationPopup.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import {formatDate, gettext} from 'utils'; +import {formatDate, gettext, notificationsArePaused, notificationsWillBePaused, parseISODate} from 'utils'; import {IArticle, IUser} from 'interfaces'; import NotificationListItem from './NotificationListItem'; @@ -19,15 +19,10 @@ export interface IProps { } export const NotificationPopup = (props: IProps) => { - const today = (new Date()).toISOString().substring(0, 10); - const pausedFrom = props.fullUser.notification_schedule?.pause_from ?? ''; - const pausedTo = props.fullUser.notification_schedule?.pause_to ?? ''; - const notificationsArePaused = ( - pausedFrom != '' && pausedFrom <= today && - pausedTo != '' && pausedTo >= today - ); + const pausedFrom = parseISODate(props.fullUser.notification_schedule?.pause_from); + const pausedTo = parseISODate(props.fullUser.notification_schedule?.pause_to); - if (notificationsArePaused) { + if (notificationsArePaused(pausedFrom, pausedTo)) { return (
@@ -78,7 +73,7 @@ export const NotificationPopup = (props: IProps) => {
- {(pausedFrom != '' && pausedTo != '' && notificationsArePaused === false) && ( + {(notificationsWillBePaused(pausedFrom, pausedTo)) && (
{gettext('All notifications are set to be paused from {{dateFrom}} to {{dateTo}}', {dateFrom: formatDate(pausedFrom), dateTo: formatDate(pausedTo)})} diff --git a/assets/user-profile/components/profile/UserProfile.tsx b/assets/user-profile/components/profile/UserProfile.tsx index ba217b5e7..35b3dff82 100644 --- a/assets/user-profile/components/profile/UserProfile.tsx +++ b/assets/user-profile/components/profile/UserProfile.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {connect} from 'react-redux'; import {IUser} from 'interfaces'; -import {gettext, getSubscriptionTimesString, formatDate} from 'utils'; +import {gettext, getSubscriptionTimesString, formatDate, parseISODate, notificationsArePaused, notificationsWillBePaused} from 'utils'; import TextInput from 'components/TextInput'; import SelectInput from 'components/SelectInput'; @@ -73,6 +73,8 @@ class UserProfile extends React.PureComponent { const {user, onChange, errors, authProviderFeatures} = this.props; const onCancel = () => this.props.fetchUser(this.props.user._id); const localeOptions = getLocaleInputOptions(); + const pausedFrom = parseISODate(this.props.user.notification_schedule?.pause_from); + const pausedTo = parseISODate(this.props.user.notification_schedule?.pause_to); return (
@@ -187,12 +189,12 @@ class UserProfile extends React.PureComponent {
- {this.props.user.notification_schedule && this.props.user.notification_schedule.pause_from != '' && this.props.user.notification_schedule.pause_to != '' - ? ( + {(notificationsArePaused(pausedFrom, pausedTo) || notificationsWillBePaused(pausedFrom, pausedTo)) ? + (
- {gettext('All notifications will be paused from {{dateFrom}} to {{dateTo}}', {dateFrom: formatDate(this.props.user.notification_schedule.pause_from), dateTo: formatDate(this.props.user.notification_schedule.pause_to)})} + {gettext('All notifications will be paused from {{dateFrom}} to {{dateTo}}', {dateFrom: formatDate(pausedFrom), dateTo: formatDate(pausedTo)})}