Skip to content

Commit

Permalink
added new function to redirect to order details page, changed logic f…
Browse files Browse the repository at this point in the history
…or handling completed order notifications
  • Loading branch information
ameerul-deriv committed Sep 21, 2022
1 parent 6f76f3e commit 40a5f26
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
34 changes: 28 additions & 6 deletions packages/core/src/Stores/notification-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export default class NotificationStore extends BaseStore {
this.filterNotificationMessages();
}
);
reaction(
() => this.p2p_order_props,
() => {
this.refreshNotifications();
}
);
reaction(
() => [
root_store.client.account_settings,
Expand Down Expand Up @@ -431,23 +437,39 @@ export default class NotificationStore extends BaseStore {
}
}

@action.bound
showCompletedOrderNotification(advertiser_name, order_id) {
const notification_key = `order-${order_id}`;

const notification_action =
routes.cashier_p2p === window.location.pathname
? {
onClick: () => {
this.p2p_order_props.redirectToOrderDetails(order_id);
this.setP2POrderProps({
...this.p2p_order_props,
order_id,
});
if (this.is_notifications_visible) this.toggleNotificationsModal();
},
text: localize('Give feedback C'),
}
: {
route: `${routes.cashier_p2p}?order=${order_id}`,
text: localize('Give feedback R'),
};

this.addNotificationMessage({
action:
this.p2p_order_props?.order_id === order_id
? {
onClick: () => {
this.p2p_order_props.setIsRatingModalOpen(true);
this.toggleNotificationsModal();
if (this.is_notifications_visible) this.toggleNotificationsModal();
},
text: localize('Give feedback'),
text: localize('Give feedback SAME'),
}
: {
route: `${routes.cashier_p2p}?order=${order_id}`,
text: localize('Give feedback'),
},
: notification_action,
header: <Localize i18n_default_text='Your order {{order_id}} is complete' values={{ order_id }} />,
key: notification_key,
message: (
Expand Down
11 changes: 11 additions & 0 deletions packages/p2p/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ const App = props => {
if (order_id) {
general_store.redirectTo('orders');
order_store.setOrderId(order_id);
general_store.props.setP2POrderProps({
order_id: order_store.order_id,
redirectToOrderDetails: general_store.redirectToOrderDetails,
setIsRatingModalOpen: order_store.setIsRatingModalOpen,
});
} else {
general_store.props.setP2POrderProps({
order_id,
redirectToOrderDetails: general_store.redirectToOrderDetails,
setIsRatingModalOpen: order_store.setIsRatingModalOpen,
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [order_id]);
Expand Down
6 changes: 6 additions & 0 deletions packages/p2p/src/components/order-details/order-details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const OrderDetails = observer(() => {
order_store.setIsRecommended(undefined);
general_store.props.setP2POrderProps({
order_id: order_store.order_id,
redirectToOrderDetails: general_store.redirectToOrderDetails,
setIsRatingModalOpen: order_store.setIsRatingModalOpen,
});

Expand All @@ -96,6 +97,11 @@ const OrderDetails = observer(() => {
disposeReactions();
order_store.setOrderPaymentMethodDetails(undefined);
order_store.setOrderId(null);
general_store.props.setP2POrderProps({
order_id: order_store.order_id,
redirectToOrderDetails: general_store.redirectToOrderDetails,
setIsRatingModalOpen: order_store.setIsRatingModalOpen,
});
};
}, []); // eslint-disable-line react-hooks/exhaustive-deps

Expand Down
12 changes: 9 additions & 3 deletions packages/p2p/src/stores/general-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ export default class GeneralStore extends BaseStore {
this.updateP2pNotifications(notifications);
}

@action.bound
redirectToOrderDetails(order_id) {
const { order_store } = this.root_store;
this.redirectTo('orders');
this.setOrderTableType(order_list.INACTIVE);
order_store.setOrderId(order_id);
}

@action.bound
showCompletedOrderNotification(advertiser_name, order_id) {
const { order_store } = this.root_store;
Expand All @@ -212,9 +220,7 @@ export default class GeneralStore extends BaseStore {
if (order_store.order_id === order_id) {
order_store.setIsRatingModalOpen(true);
}
this.redirectTo('orders');
this.setOrderTableType(order_list.INACTIVE);
order_store.setOrderId(order_id);
this.redirectToOrderDetails(order_id);
},
text: localize('Give feedback'),
},
Expand Down

0 comments on commit 40a5f26

Please sign in to comment.