Skip to content

Commit

Permalink
fix: make request id cell render on client
Browse files Browse the repository at this point in the history
  • Loading branch information
RyukTheCoder committed Jan 22, 2025
1 parent 381d4df commit 3def87f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-disable @next/next/no-img-element */
import { SecondsTohms } from 'src/utils/secondsTohms';
import { SwapDetailItem } from './SwapDetail.type';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import IconStatus from 'src/components/common/IconStatus';
import { StepsIcon } from 'src/components/icons';
import Tooltip from 'src/components/common/Tooltip';
import dynamic from 'next/dynamic';

dayjs.extend(utc);
const LocalDate = dynamic(() => import('src/components/common/LocalDate'), {
ssr: false,
});

function SwapDetailMobileValue(props: SwapDetailItem) {
const { details, column } = props;
Expand Down Expand Up @@ -49,11 +50,7 @@ function SwapDetailMobileValue(props: SwapDetailItem) {
)}
{column.title === 'Initiation Date And Time' && creationDate && (
<div className="text-14 text-primary-500">
{dayjs
.utc(creationDate)
.local()
.format('MMMM DD, YYYY | HH:mm:ss')
.toString()}
<LocalDate date={creationDate} />
</div>
)}
{column.title === 'Duration' && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-disable @next/next/no-img-element */
import { SecondsTohms } from 'src/utils/secondsTohms';
import { SwapDetailItem } from './SwapDetail.type';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import IconStatus from 'src/components/common/IconStatus';
import { StepsIcon } from 'src/components/icons';
import Tooltip from 'src/components/common/Tooltip';
import dynamic from 'next/dynamic';

dayjs.extend(utc);
const LocalDate = dynamic(() => import('src/components/common/LocalDate'), {
ssr: false,
});

function SwapDetailValue(props: SwapDetailItem) {
const { details, column } = props;
Expand Down Expand Up @@ -70,11 +71,7 @@ function SwapDetailValue(props: SwapDetailItem) {
)}
{column.title === 'Initiation Date And Time' && creationDate && (
<span className="text-primary-500">
{dayjs
.utc(creationDate)
.local()
.format('MMMM D, YYYY | hh:mm:ss A')
.toString()}
<LocalDate date={creationDate} />
</span>
)}
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/app/swap/[id]/_components/SwapSteps/SwapStepValue.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { SecondsTohms } from 'src/utils/secondsTohms';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import { SwapStepItemValueProps } from './SwapSteps.type';
import dynamic from 'next/dynamic';

dayjs.extend(utc);
const LocalDate = dynamic(() => import('src/components/common/LocalDate'), {
ssr: false,
});

function SwapStepValue(props: SwapStepItemValueProps) {
const { step, column, firstStep } = props;
Expand Down Expand Up @@ -62,8 +63,7 @@ function SwapStepValue(props: SwapStepItemValueProps) {

{column.title === 'Step Start Time' && (
<span className="text-primary-500">
{startTime &&
dayjs.utc(startTime).local().format('HH:mm:ss').toString()}
{startTime && <LocalDate date={startTime} format="HH:mm:ss" />}
</span>
)}

Expand Down
6 changes: 6 additions & 0 deletions src/components/common/LocalDate/LocalDate.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ConfigType as DateType } from 'dayjs';

export interface LocalDateProps {
date: DateType;
format?: string;
}
12 changes: 12 additions & 0 deletions src/components/common/LocalDate/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import dayjs from 'dayjs';
import { LocalDateProps } from './LocalDate.types';
import utc from 'dayjs/plugin/utc';
dayjs.extend(utc);

function LocalDate(props: LocalDateProps) {
const { date, format = 'MMMM D, YYYY | hh:mm:ss A' } = props;

return <>{dayjs.utc(date).local().format(format).toString()}</>;
}

export default LocalDate;
4 changes: 0 additions & 4 deletions src/components/common/Table/TableBody.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
import { TableBodyProps } from './Table.type';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import { columns } from './Table.helper';
import Link from 'next/link';

dayjs.extend(utc);

function TableBody(props: TableBodyProps) {
const { data } = props;
return (
Expand Down
13 changes: 5 additions & 8 deletions src/components/common/Table/cells/RequestIDCell.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import { CellProps } from '../Table.type';
import ButtonCopyIcon from 'src/components/common/ButtonCopyIcon';
import Tooltip from 'src/components/common/Tooltip';
import Link from 'next/link';
import dynamic from 'next/dynamic';

dayjs.extend(utc);
const LocalDate = dynamic(() => import('../../LocalDate'), {
ssr: false,
});

function RequestIDCell(props: CellProps) {
const { swapItem, column } = props;
Expand All @@ -28,11 +29,7 @@ function RequestIDCell(props: CellProps) {
<ButtonCopyIcon tooltipText="Copy Request ID " text={requestId} />
</div>
<div className="text-12 md:text-14 text-neutral-400">
{dayjs
.utc(transactionTime)
.local()
.format('MMMM D, YYYY | hh:mm:ss A')
.toString()}
<LocalDate date={transactionTime} />
</div>
</div>
);
Expand Down

0 comments on commit 3def87f

Please sign in to comment.