[WEB-1803] chore: workspace notification sorting when we refresh the notifications on workspace notifications (#5049)
* chore: workspace notification sorting when we refresh the notifications on workspace notifications * chore: replaced sorting with ISO to EPOCH * chore: converted obj to array
This commit is contained in:
parent
61ce055cb3
commit
c75091ca3a
2 changed files with 21 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import isEmpty from "lodash/isEmpty";
|
import isEmpty from "lodash/isEmpty";
|
||||||
|
import orderBy from "lodash/orderBy";
|
||||||
import set from "lodash/set";
|
import set from "lodash/set";
|
||||||
import update from "lodash/update";
|
import update from "lodash/update";
|
||||||
import { action, makeObservable, observable, runInAction } from "mobx";
|
import { action, makeObservable, observable, runInAction } from "mobx";
|
||||||
|
|
@ -18,6 +19,8 @@ import {
|
||||||
ENotificationTab,
|
ENotificationTab,
|
||||||
TNotificationTab,
|
TNotificationTab,
|
||||||
} from "@/constants/notification";
|
} from "@/constants/notification";
|
||||||
|
// helpers
|
||||||
|
import { convertToEpoch } from "@/helpers/date-time.helper";
|
||||||
// services
|
// services
|
||||||
import workspaceNotificationService from "@/services/workspace-notification.service";
|
import workspaceNotificationService from "@/services/workspace-notification.service";
|
||||||
// store
|
// store
|
||||||
|
|
@ -119,7 +122,12 @@ export class WorkspaceNotificationStore implements IWorkspaceNotificationStore {
|
||||||
*/
|
*/
|
||||||
notificationIdsByWorkspaceId = computedFn((workspaceId: string) => {
|
notificationIdsByWorkspaceId = computedFn((workspaceId: string) => {
|
||||||
if (!workspaceId || isEmpty(this.notifications)) return undefined;
|
if (!workspaceId || isEmpty(this.notifications)) return undefined;
|
||||||
const workspaceNotificationIds = Object.values(this.notifications || {})
|
const workspaceNotifications = orderBy(
|
||||||
|
Object.values(this.notifications || []),
|
||||||
|
(n) => convertToEpoch(n.created_at),
|
||||||
|
["desc"]
|
||||||
|
);
|
||||||
|
const workspaceNotificationIds = workspaceNotifications
|
||||||
.filter((n) => n.workspace === workspaceId)
|
.filter((n) => n.workspace === workspaceId)
|
||||||
.filter((n) => {
|
.filter((n) => {
|
||||||
if (!this.filters.archived && !this.filters.snoozed) {
|
if (!this.filters.archived && !this.filters.snoozed) {
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,18 @@ export const convertToISODateString = (dateString: string | undefined) => {
|
||||||
return date.toISOString();
|
return date.toISOString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the date string in Epoch regardless of the timezone in input date string
|
||||||
|
* @param dateString
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const convertToEpoch = (dateString: string | undefined) => {
|
||||||
|
if (!dateString) return dateString;
|
||||||
|
|
||||||
|
const date = new Date(dateString);
|
||||||
|
return date.getTime();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get current Date time in UTC ISO format
|
* get current Date time in UTC ISO format
|
||||||
* @returns
|
* @returns
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue