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

Amina/wall 575/maintenance notifications for site and cashier #9064

Merged
Show file tree
Hide file tree
Changes from 4 commits
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
3 changes: 3 additions & 0 deletions packages/account/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ const App = ({ passthrough }: TAppProps) => {
const { root_store, WS } = passthrough;
initStore(root_store, WS);

const { notification_messages_ui: Notifications } = root_store.ui;

return (
<MobxContentProvider store={root_store}>
{Notifications && <Notifications />}
<Routes />
<ResetTradingPassword />
</MobxContentProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export const PersonalDetailsForm = ({
refreshNotifications,
showPOAAddressMismatchSuccessNotification,
showPOAAddressMismatchFailureNotification,
Notifications,
fetchResidenceList,
fetchStatesList,
has_residence,
Expand Down Expand Up @@ -555,7 +554,6 @@ export const PersonalDetailsForm = ({
dirty,
}) => (
<React.Fragment>
{Notifications && <Notifications />}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this is removed from personal details component?
Could there be notifications which should be only displayed when the user is in personal details route?

Copy link
Contributor Author

@amina-deriv amina-deriv Jun 20, 2023

Choose a reason for hiding this comment

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

i removed it from this component and added in parent account/app.tsx .

<LeaveConfirm onDirty={isMobile() ? showForm : null} />
{show_form && (
<Form
Expand Down Expand Up @@ -1286,7 +1284,6 @@ PersonalDetailsForm.propTypes = {
refreshNotifications: PropTypes.func,
showPOAAddressMismatchSuccessNotification: PropTypes.func,
showPOAAddressMismatchFailureNotification: PropTypes.func,
Notifications: PropTypes.node,
fetchResidenceList: PropTypes.func,
fetchStatesList: PropTypes.func,
has_residence: PropTypes.bool,
Expand All @@ -1300,7 +1297,7 @@ PersonalDetailsForm.propTypes = {
is_language_changing: PropTypes.bool,
};

export default connect(({ client, notifications, ui, common }) => ({
export default connect(({ client, notifications, common }) => ({
account_settings: client.account_settings,
authentication_status: client.authentication_status,
has_residence: client.has_residence,
Expand All @@ -1319,7 +1316,6 @@ export default connect(({ client, notifications, ui, common }) => ({
refreshNotifications: notifications.refreshNotifications,
showPOAAddressMismatchSuccessNotification: notifications.showPOAAddressMismatchSuccessNotification,
showPOAAddressMismatchFailureNotification: notifications.showPOAAddressMismatchFailureNotification,
Notifications: ui.notification_messages_ui,
updateAccountStatus: client.updateAccountStatus,
has_poa_address_mismatch: client.account_status.status?.includes('poa_address_mismatch'),
is_language_changing: common.is_language_changing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const TwoFactorAuthentication = ({
setTwoFAStatus,
getTwoFAStatus,
has_enabled_two_fa,
Notifications,
setTwoFAChangedStatus,
}) => {
const [is_loading, setLoading] = React.useState(true);
Expand Down Expand Up @@ -200,7 +199,6 @@ const TwoFactorAuthentication = ({
'two-factor__wrapper-dashboard': is_appstore,
})}
>
{Notifications && <Notifications />}
{has_enabled_two_fa ? TwoFactorEnabled : TwoFactorDisabled}
</div>
</section>
Expand All @@ -213,16 +211,14 @@ TwoFactorAuthentication.propTypes = {
setTwoFAStatus: PropTypes.func,
getTwoFAStatus: PropTypes.func,
has_enabled_two_fa: PropTypes.bool,
Notifications: PropTypes.node,
setTwoFAChangedStatus: PropTypes.func,
};

export default connect(({ client, ui }) => ({
export default connect(({ client }) => ({
email_address: client.email_address,
is_switching: client.is_switching,
setTwoFAStatus: client.setTwoFAStatus,
getTwoFAStatus: client.getTwoFAStatus,
has_enabled_two_fa: client.has_enabled_two_fa,
Notifications: ui.notification_messages_ui,
setTwoFAChangedStatus: client.setTwoFAChangedStatus,
}))(TwoFactorAuthentication);
21 changes: 18 additions & 3 deletions packages/core/src/App/Containers/app-notification-messages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import Notification, {
max_display_notifications_mobile,
} from '../Components/Elements/NotificationMessage';
import { useLocation } from 'react-router-dom';
import { excluded_notifications, priority_toast_messages } from '../../Stores/Helpers/client-notifications';
import {
excluded_notifications,
priority_toast_messages,
maintenance_notifications,
} from '../../Stores/Helpers/client-notifications';

const Portal = ({ children }) =>
isMobile() ? ReactDOM.createPortal(children, document.getElementById('deriv_app')) : children;
Expand Down Expand Up @@ -107,6 +111,8 @@ const AppNotificationMessages = ({
const is_not_marked_notification = !marked_notifications.includes(message.key);
const is_non_hidden_notification = isMobile()
? [
'system_maintenance',
'site_maintenance',
'authenticate',
'deriv_go',
'document_needs_action',
Expand Down Expand Up @@ -145,7 +151,14 @@ const AppNotificationMessages = ({

const is_only_for_p2p_notification =
window.location.pathname !== routes.cashier_p2p || message?.platform === 'P2P';
return is_not_marked_notification && is_non_hidden_notification && is_only_for_p2p_notification;

const is_maintenance_notifications = maintenance_notifications.includes(message.key);

return (
is_not_marked_notification &&
is_non_hidden_notification &&
(is_only_for_p2p_notification || is_maintenance_notifications)
);
});

const notifications_limit = isMobile() ? max_display_notifications_mobile : max_display_notifications;
Expand All @@ -159,7 +172,9 @@ const AppNotificationMessages = ({

const notifications_sublist =
window.location.pathname === routes.cashier_deposit
? filtered_excluded_notifications.filter(message => message.key.includes('switched_to_real'))
? filtered_excluded_notifications.filter(
message => message.key.includes('switched_to_real') || maintenance_notifications.includes(message.key)
amina-deriv marked this conversation as resolved.
Show resolved Hide resolved
)
: filtered_excluded_notifications.slice(0, notifications_limit);

if (!should_show_popups) return null;
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/Stores/Helpers/client-notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,13 @@ export const getCashierValidations = cashier_arr => {
// Notifications keys will not be added to localStorage and will appear again after user logout/login
export const excluded_notifications = ['contract_sold', 'switched_to_real', 'has_changed_two_fa'];

export const priority_toast_messages = ['svg', 'need_fa', 'p2p_daily_limit_increase', 'authenticate'];
export const priority_toast_messages = [
'system_maintenance',
'site_maintenance',
'svg',
'need_fa',
'p2p_daily_limit_increase',
'authenticate',
];

export const maintenance_notifications = ['system_maintenance', 'site_maintenance'];
13 changes: 0 additions & 13 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1729,19 +1729,6 @@ export default class ClientStore extends BaseStore {

responseWebsiteStatus(response) {
this.website_status = response.website_status;
if (this.website_status.message && this.website_status.message.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is great 👍🏼

this.root_store.notifications.addNotificationMessage({
key: 'maintenance',
header: localize('Site is being updated'),
message: localize(this.website_status.message),
type: 'warning',
is_persistent: true,
});
} else {
this.root_store.notifications.removeNotificationMessage({
key: 'maintenance',
});
}
}

responseLandingCompany(response) {
Expand Down
25 changes: 21 additions & 4 deletions packages/core/src/Stores/notification-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getCashierValidations,
getStatusValidations,
hasMissingRequiredField,
maintenance_notifications,
} from './Helpers/client-notifications';
import { sortNotifications, sortNotificationsMobile } from '../App/Components/Elements/NotificationMessage/constants';
import BaseStore from './base-store';
Expand Down Expand Up @@ -223,10 +224,10 @@ export default class NotificationStore extends BaseStore {
filterNotificationMessages() {
if (LocalStore.get('active_loginid') !== 'null')
this.resetVirtualBalanceNotification(LocalStore.get('active_loginid'));

if (window.location.pathname === routes.personal_details) {
this.notification_messages = this.notification_messages.filter(
notification => notification.platform === 'Account'
notification =>
notification.platform === 'Account' || maintenance_notifications.includes(notification.key)
);
} else if (window.location.pathname !== routes.cashier_p2p) {
this.notification_messages = this.notification_messages.filter(notification => {
Expand Down Expand Up @@ -315,6 +316,12 @@ export default class NotificationStore extends BaseStore {

let has_missing_required_field;

if (website_status.message && website_status.message.length) {
amina-deriv marked this conversation as resolved.
Show resolved Hide resolved
this.addNotificationMessage(this.client_notifications.site_maintenance);
} else {
this.removeNotificationByKey({ key: this.client_notifications.site_maintenance });
}

if (is_logged_in) {
if (isEmptyObject(account_status)) return;
const {
Expand Down Expand Up @@ -1233,6 +1240,14 @@ export default class NotificationStore extends BaseStore {
type: 'danger',
};
},
site_maintenance: {
key: 'site_maintenance',
header: localize('We’re updating our site'),
message: localize('Some services may be temporarily unavailable.'),
type: 'warning',
should_show_again: true,
closeOnClick: notification_obj => this.markNotificationMessage({ key: notification_obj.key }),
},
system_maintenance: (withdrawal_locked, deposit_locked) => {
let message, header;
if (isCryptocurrency(client_data.currency)) {
Expand All @@ -1253,16 +1268,18 @@ export default class NotificationStore extends BaseStore {
);
}
} else {
header = localize('Scheduled cashier system maintenance');
header = localize('Scheduled cashier maintenance');
message = localize(
'Our cashier is temporarily down due to system maintenance. You can access the cashier in a few minutes when the maintenance is complete.'
'The cashier is temporarily down due to maintenance. It will be available as soon as the maintenance is complete.'
);
}
return {
key: 'system_maintenance',
header,
message,
type: 'warning',
should_show_again: true,
closeOnClick: notification_obj => this.markNotificationMessage({ key: notification_obj.key }),
};
},
tax: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
z-index: 6;
position: absolute;
right: 0;
margin-top: 1.6rem;

> div {
display: flex;
Expand Down