Skip to content

Commit d94c265

Browse files
committed
feat: use new formated date time all over place
Signed-off-by: amitamrutiya <[email protected]>
1 parent ecba3ca commit d94c265

File tree

13 files changed

+57
-92
lines changed

13 files changed

+57
-92
lines changed

package-lock.json

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"billboard.js": "^3.14.3",
105105
"js-yaml": "^4.1.0",
106106
"lodash": "^4.17.21",
107-
"moment": "^2.30.1",
107+
"moment-timezone": "^0.5.47",
108108
"mui-datatables": "*",
109109
"re-resizable": "^6.10.3",
110110
"react-draggable": "^4.4.6",

src/custom/CatalogDesignTable/CatalogDesignTable.tsx

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import _ from 'lodash';
3-
import moment from 'moment';
43
import { MUIDataTableColumn } from 'mui-datatables';
54
import { useCallback, useMemo, useRef } from 'react';
65
import { PublishIcon } from '../../icons';
76
import { CHARCOAL } from '../../theme';
7+
import { FormattedTime } from '../../utils';
88
import { Pattern } from '../CustomCatalog/CustomCard';
9-
import { CustomTooltip } from '../CustomTooltip';
109
import { ErrorBoundary } from '../ErrorBoundary';
1110
import { ColView } from '../Helpers/ResponsiveColumns/responsive-coulmns.tsx/responsive-column';
1211
import PromptComponent from '../Prompt';
@@ -58,10 +57,6 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
5857
}) => {
5958
const modalRef = useRef<PromptRef>(null);
6059

61-
const formatDate = useCallback((date: string | Date): string => {
62-
return moment(date).fromNow();
63-
}, []);
64-
6560
const processedColumns: MUIDataTableColumn[] = useMemo(() => {
6661
return columns.map((col) => {
6762
const newCol = { ...col };
@@ -82,25 +77,16 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
8277
if (!value || value === 'NA') return <>NA</>;
8378
if (typeof value === 'object' && 'Valid' in value) {
8479
if (value.Valid && value.Time) {
85-
const date = new Date(value.Time);
86-
return (
87-
<CustomTooltip title={date.toString()} disableInteractive>
88-
<div>{formatDate(date)}</div>
89-
</CustomTooltip>
90-
);
80+
return <FormattedTime date={value.Time} />;
9181
}
9282
return <>NA</>;
9383
}
94-
return (
95-
<CustomTooltip title={new Date(value).toString()} disableInteractive>
96-
<div>{formatDate(value)}</div>
97-
</CustomTooltip>
98-
);
84+
return <FormattedTime date={value.Time} />;
9985
};
10086
}
10187
return newCol;
10288
});
103-
}, [columns, columnVisibility, formatDate]);
89+
}, [columns, columnVisibility]);
10490

10591
const handleTableChange = useCallback(
10692
(action: string, tableState: any) => {

src/custom/CatalogDetail/UserInfo.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Avatar } from '../../base';
22
import { CLOUD_URL } from '../../constants/constants';
33
import { LockIcon, PublicIcon } from '../../icons';
4+
import { getFormatDate } from '../../utils';
45
import { Pattern } from '../CustomCatalog/CustomCard';
56
import { getVersion } from '../CustomCatalog/Helper';
67
import { VisibilityChipMenu } from '../VisibilityChipMenu';
78
import { VIEW_VISIBILITY } from '../VisibilityChipMenu/VisibilityChipMenu';
8-
import { formatDate } from './helper';
99
import { ContentDetailsPoints, ContentDetailsText, ContentRow, RedirectLink } from './style';
1010
import { UserProfile } from './types';
1111

@@ -56,11 +56,11 @@ const UserInfo: React.FC<UserInfoProps> = ({
5656
</ContentRow>
5757
<ContentRow>
5858
<ContentDetailsPoints>CREATED AT</ContentDetailsPoints>
59-
<ContentDetailsText>{formatDate(details?.created_at)}</ContentDetailsText>
59+
<ContentDetailsText>{getFormatDate(details?.created_at.toString())}</ContentDetailsText>
6060
</ContentRow>
6161
<ContentRow>
6262
<ContentDetailsPoints>UPDATED AT</ContentDetailsPoints>
63-
<ContentDetailsText>{formatDate(details?.updated_at)}</ContentDetailsText>
63+
<ContentDetailsText>{getFormatDate(details?.updated_at.toString())}</ContentDetailsText>
6464
</ContentRow>
6565
{showVersion && (
6666
<ContentRow>

src/custom/CatalogDetail/helper.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ export const formatToTitleCase = (value: string): string => {
5656
return '';
5757
};
5858

59-
export const formatDate = (date: Date) => {
60-
const options = { year: 'numeric', month: 'short', day: 'numeric' };
61-
const formattedDate = new Date(date).toLocaleDateString('en-US', options);
62-
return formattedDate;
63-
};
64-
6559
interface HeadingProps {
6660
type: string;
6761
userProfile?: {

src/custom/DashboardWidgets/RecentDesignWidget.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import {
1717
import { iconMedium } from '../../constants/iconsSizes';
1818
import { AddIcon, OpenInNewIcon } from '../../icons';
1919
import { useTheme } from '../../theme';
20+
import { getFullFormattedTime, getRelativeTime } from '../../utils';
2021
import { CustomTooltip } from '../CustomTooltip';
2122
import { Modal, ModalBody } from '../Modal';
22-
import { formatDateTime, formatRelativeDate } from './utils';
2323

2424
interface Resource {
2525
link: string;
@@ -297,15 +297,15 @@ interface RelativeFormattedDateProps {
297297

298298
const RelativeFormattedDate: React.FC<RelativeFormattedDateProps> = ({ date, style }) => {
299299
return (
300-
<Tooltip title={formatDateTime(date)} placement="top">
300+
<Tooltip title={getFullFormattedTime(date)} placement="top">
301301
<div>
302302
<Typography
303303
style={{
304304
fontStyle: 'italic',
305305
...style
306306
}}
307307
>
308-
{formatRelativeDate(date)}
308+
{getRelativeTime(date)}
309309
</Typography>
310310
</div>
311311
</Tooltip>

src/custom/DashboardWidgets/WorkspaceActivityWidget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SelectChangeEvent } from '@mui/material';
22
import { styled } from '@mui/material/styles';
3-
import moment from 'moment';
3+
import moment from 'moment-timezone';
44
import {
55
Box,
66
Button,

src/custom/DashboardWidgets/utils.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/custom/ResourceDetailFormatters/useResourceCleanData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import _ from 'lodash';
3-
import moment from 'moment';
3+
import moment from 'moment-timezone';
44
import { GetResourceCleanDataProps, NumberState } from './types';
55

66
export const useResourceCleanData = () => {

src/custom/ResponsiveDataTable.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import moment from 'moment';
21
import MUIDataTable, { MUIDataTableColumn } from 'mui-datatables';
32
import React, { useCallback } from 'react';
43
import { Checkbox, Collapse, ListItemIcon, ListItemText, Menu, MenuItem } from '../base';
54
import { ShareIcon } from '../icons';
65
import { EllipsisIcon } from '../icons/Ellipsis';
6+
import { FormattedTime } from '../utils';
77
import { styled, useTheme } from './../theme';
8-
import { CustomTooltip } from './CustomTooltip';
98
import { ColView } from './Helpers/ResponsiveColumns/responsive-coulmns.tsx';
109
import { TooltipIcon } from './TooltipIconButton';
1110

@@ -158,10 +157,6 @@ const ResponsiveDataTable = ({
158157
rowsPerPageOptions = [10, 25, 50, 100],
159158
...props
160159
}: ResponsiveDataTableProps): JSX.Element => {
161-
const formatDate = (date: Date): string => {
162-
return moment(date).fromNow();
163-
};
164-
165160
const updatedOptions = {
166161
...options,
167162
print: false,
@@ -221,22 +216,12 @@ const ResponsiveDataTable = ({
221216
} else if (typeof value === 'object' && 'Valid' in value) {
222217
const obj = value as { Valid: boolean; Time: string | undefined };
223218
if (obj.Valid && obj.Time) {
224-
const date = new Date(obj.Time);
225-
return (
226-
<CustomTooltip title={date.toString()} disableInteractive>
227-
<div>{formatDate(date)}</div>
228-
</CustomTooltip>
229-
);
219+
return <FormattedTime date={obj.Time} />;
230220
} else {
231221
return <>NA</>;
232222
}
233223
} else if (typeof value === 'string') {
234-
const date = new Date(value);
235-
return (
236-
<CustomTooltip title={date.toString()} disableInteractive>
237-
<div>{formatDate(date)}</div>
238-
</CustomTooltip>
239-
);
224+
return <FormattedTime date={value} />;
240225
} else {
241226
return <>{value}</>;
242227
}

0 commit comments

Comments
 (0)