Skip to content
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

only show ongoing/future pause notifications info #988

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions assets/components/NotificationPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {formatDate, gettext, getTodayTimestamp, parseISODate} from 'utils';
import {formatDate, gettext, notificationsArePaused, notificationsWillBePaused, parseISODate} from 'utils';
import {IArticle, IUser} from 'interfaces';

import NotificationListItem from './NotificationListItem';
Expand All @@ -19,11 +19,10 @@ export interface IProps {
}

export const NotificationPopup = (props: IProps) => {
const today = getTodayTimestamp();
const pausedFrom = parseISODate(props.fullUser.notification_schedule?.pause_from);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI you can parse by passing a string to constructor new Date('2024-01-01')

const pausedTo = parseISODate(props.fullUser.notification_schedule?.pause_to);

if (pausedFrom <= today && pausedTo >= today) {
if (notificationsArePaused(pausedFrom, pausedTo)) {
return (
<div className="notif__list dropdown-menu dropdown-menu-right show">
<div className='notif__list__header d-flex'>
Expand Down Expand Up @@ -74,7 +73,7 @@ export const NotificationPopup = (props: IProps) => {
</button>
</div>

{(pausedFrom && pausedTo >= today) && (
{(notificationsWillBePaused(pausedFrom, pausedTo)) && (
<div className='p-3'>
<div className='nh-container nh-container__text--info p-2'>
{gettext('All notifications are set to be paused from {{dateFrom}} to {{dateTo}}', {dateFrom: formatDate(pausedFrom), dateTo: formatDate(pausedTo)})}
Expand Down
11 changes: 6 additions & 5 deletions assets/user-profile/components/profile/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import {connect} from 'react-redux';

import {IUser} from 'interfaces';
import {gettext, getSubscriptionTimesString, formatDate, parseISODate, getTodayTimestamp} from 'utils';
import {gettext, getSubscriptionTimesString, formatDate, parseISODate, notificationsArePaused, notificationsWillBePaused} from 'utils';

import TextInput from 'components/TextInput';
import SelectInput from 'components/SelectInput';
Expand Down Expand Up @@ -73,7 +73,8 @@ class UserProfile extends React.PureComponent<IProps> {
const {user, onChange, errors, authProviderFeatures} = this.props;
const onCancel = () => this.props.fetchUser(this.props.user._id);
const localeOptions = getLocaleInputOptions();
const today = getTodayTimestamp();
const pausedFrom = parseISODate(this.props.user.notification_schedule?.pause_from);
const pausedTo = parseISODate(this.props.user.notification_schedule?.pause_to);
return (
<form className="profile-content profile-content--user">
<div className="profile-content__main">
Expand Down Expand Up @@ -188,12 +189,12 @@ class UserProfile extends React.PureComponent<IProps> {

<div className='row'>
<div className="col-lg-6">
{(parseISODate(this.props.user.notification_schedule?.pause_from) && parseISODate(this.props.user.notification_schedule?.pause_to) >= today)
? (
{(notificationsArePaused(pausedFrom, pausedTo) || notificationsWillBePaused(pausedFrom, pausedTo)) ?
(
<div className="nh-container nh-container__text--alert">
<div className='d-flex flex-column gap-3 p-3'>
<div>
{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)})}
</div>
<div>
<button
Expand Down
16 changes: 14 additions & 2 deletions assets/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,18 @@ export function parseISODate(date?: string): number {
}

// Will return number of seconds since epoch for today at 00:00:00
export function getTodayTimestamp(): number {
function getTodayTimestamp(): number {
tomaskikutis marked this conversation as resolved.
Show resolved Hide resolved
return (new Date()).setUTCHours(0, 0, 0, 0);
}
}

export function notificationsArePaused(pausedFrom: number, pausedTo: number): boolean {
const today = getTodayTimestamp();

return pausedFrom <= today && pausedTo >= today;
}

export function notificationsWillBePaused(pausedFrom: number, pausedTo: number): boolean {
const today = getTodayTimestamp();

return pausedFrom > today && pausedTo > today;
}
Loading