From 4ede04d72f25f54a2b6d6a11720e022098a4a4c0 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Tue, 4 Jul 2023 18:19:19 +0530 Subject: [PATCH] refactor: standardized date format throughout the platform (#1461) --- apps/app/components/core/feeds.tsx | 4 ++-- apps/app/components/cycles/sidebar.tsx | 6 +++--- apps/app/components/inbox/inbox-issue-card.tsx | 8 ++++---- apps/app/components/inbox/inbox-main-content.tsx | 10 +++++++--- apps/app/components/issues/activity.tsx | 4 ++-- apps/app/components/issues/select/date.tsx | 4 ++-- apps/app/components/issues/view-select/due-date.tsx | 6 ++++-- apps/app/components/modules/sidebar.tsx | 12 +++++++++--- apps/app/components/project/single-project-card.tsx | 6 +++--- apps/app/components/ui/date.tsx | 4 ++-- apps/app/components/ui/datepicker.tsx | 6 +++--- apps/app/components/views/single-view-item.tsx | 4 ++-- apps/app/components/workspace/activity-graph.tsx | 4 ++-- apps/app/helpers/date-time.helper.ts | 5 +++-- 14 files changed, 48 insertions(+), 35 deletions(-) diff --git a/apps/app/components/core/feeds.tsx b/apps/app/components/core/feeds.tsx index cce482da5..d00804ec8 100644 --- a/apps/app/components/core/feeds.tsx +++ b/apps/app/components/core/feeds.tsx @@ -19,7 +19,7 @@ import { } from "@heroicons/react/24/outline"; import { BlockedIcon, BlockerIcon, CyclesIcon, TagIcon, UserGroupIcon } from "components/icons"; // helpers -import { renderShortNumericDateFormat, timeAgo } from "helpers/date-time.helper"; +import { renderShortDateWithYearFormat, timeAgo } from "helpers/date-time.helper"; import { addSpaceIfCamelCase } from "helpers/string.helper"; // types import RemirrorRichTextEditor from "components/rich-text-editor"; @@ -187,7 +187,7 @@ export const Feeds: React.FC = ({ activities }) => ( activity.new_value && activity.new_value !== "" ? activity.new_value : activity.old_value; - value = renderShortNumericDateFormat(date as string); + value = renderShortDateWithYearFormat(date as string); } else if (activity.field === "description") { value = "description"; } else if (activity.field === "attachment") { diff --git a/apps/app/components/cycles/sidebar.tsx b/apps/app/components/cycles/sidebar.tsx index e4b48869f..2080d7f6b 100644 --- a/apps/app/components/cycles/sidebar.tsx +++ b/apps/app/components/cycles/sidebar.tsx @@ -35,7 +35,7 @@ import { capitalizeFirstLetter, copyTextToClipboard } from "helpers/string.helpe import { isDateGreaterThanToday, renderDateFormat, - renderShortDate, + renderShortDateWithYearFormat, } from "helpers/date-time.helper"; // types import { ICurrentUserResponse, ICycle } from "types"; @@ -315,7 +315,7 @@ export const CycleDetailsSidebar: React.FC = ({ > - {renderShortDate( + {renderShortDateWithYearFormat( new Date( `${watch("start_date") ? watch("start_date") : cycle?.start_date}` ), @@ -366,7 +366,7 @@ export const CycleDetailsSidebar: React.FC = ({ - {renderShortDate( + {renderShortDateWithYearFormat( new Date( `${watch("end_date") ? watch("end_date") : cycle?.end_date}` ), diff --git a/apps/app/components/inbox/inbox-issue-card.tsx b/apps/app/components/inbox/inbox-issue-card.tsx index 072647ae3..53d6c2e95 100644 --- a/apps/app/components/inbox/inbox-issue-card.tsx +++ b/apps/app/components/inbox/inbox-issue-card.tsx @@ -14,7 +14,7 @@ import { XCircleIcon, } from "@heroicons/react/24/outline"; // helpers -import { renderShortNumericDateFormat } from "helpers/date-time.helper"; +import { renderShortDateWithYearFormat } from "helpers/date-time.helper"; // types import type { IInboxIssue } from "types"; // constants @@ -72,12 +72,12 @@ export const InboxIssueCard: React.FC = (props) => {
- {renderShortNumericDateFormat(issue.created_at ?? "")} + {renderShortDateWithYearFormat(issue.created_at ?? "")}
diff --git a/apps/app/components/inbox/inbox-main-content.tsx b/apps/app/components/inbox/inbox-main-content.tsx index a05239a95..46aa4b33f 100644 --- a/apps/app/components/inbox/inbox-main-content.tsx +++ b/apps/app/components/inbox/inbox-main-content.tsx @@ -33,7 +33,7 @@ import { XCircleIcon, } from "@heroicons/react/24/outline"; // helpers -import { renderShortNumericDateFormat } from "helpers/date-time.helper"; +import { renderShortDateWithYearFormat } from "helpers/date-time.helper"; // types import type { IInboxIssue, IIssue } from "types"; // fetch-keys @@ -252,13 +252,17 @@ export const InboxMainContent: React.FC = () => { {new Date(issueDetails.issue_inbox[0].snoozed_till ?? "") < new Date() ? (

This issue was snoozed till{" "} - {renderShortNumericDateFormat(issueDetails.issue_inbox[0].snoozed_till ?? "")} + {renderShortDateWithYearFormat( + issueDetails.issue_inbox[0].snoozed_till ?? "" + )} .

) : (

This issue has been snoozed till{" "} - {renderShortNumericDateFormat(issueDetails.issue_inbox[0].snoozed_till ?? "")} + {renderShortDateWithYearFormat( + issueDetails.issue_inbox[0].snoozed_till ?? "" + )} .

)} diff --git a/apps/app/components/issues/activity.tsx b/apps/app/components/issues/activity.tsx index 8d708b856..e30f00b0b 100644 --- a/apps/app/components/issues/activity.tsx +++ b/apps/app/components/issues/activity.tsx @@ -26,7 +26,7 @@ import { } from "@heroicons/react/24/outline"; import { BlockedIcon, BlockerIcon, CyclesIcon, TagIcon, UserGroupIcon } from "components/icons"; // helpers -import { renderShortNumericDateFormat, timeAgo } from "helpers/date-time.helper"; +import { renderShortDateWithYearFormat, timeAgo } from "helpers/date-time.helper"; import { addSpaceIfCamelCase } from "helpers/string.helper"; // types import { ICurrentUserResponse, IIssueComment, IIssueLabels } from "types"; @@ -299,7 +299,7 @@ export const IssueActivitySection: React.FC = ({ issueId, user }) => { activityItem.new_value && activityItem.new_value !== "" ? activityItem.new_value : activityItem.old_value; - value = renderShortNumericDateFormat(date as string); + value = renderShortDateWithYearFormat(date as string); } else if (activityItem.field === "description") { value = "description"; } else if (activityItem.field === "attachment") { diff --git a/apps/app/components/issues/select/date.tsx b/apps/app/components/issues/select/date.tsx index 4abb03545..26288e11b 100644 --- a/apps/app/components/issues/select/date.tsx +++ b/apps/app/components/issues/select/date.tsx @@ -5,7 +5,7 @@ import { CalendarDaysIcon, XMarkIcon } from "@heroicons/react/24/outline"; // react-datepicker import DatePicker from "react-datepicker"; // import "react-datepicker/dist/react-datepicker.css"; -import { renderDateFormat } from "helpers/date-time.helper"; +import { renderDateFormat, renderShortDateWithYearFormat } from "helpers/date-time.helper"; type Props = { value: string | null; @@ -20,7 +20,7 @@ export const IssueDateSelect: React.FC = ({ value, onChange }) => ( {value ? ( <> - {value} + {renderShortDateWithYearFormat(value)} diff --git a/apps/app/components/issues/view-select/due-date.tsx b/apps/app/components/issues/view-select/due-date.tsx index f5dcbc982..efd568c30 100644 --- a/apps/app/components/issues/view-select/due-date.tsx +++ b/apps/app/components/issues/view-select/due-date.tsx @@ -3,7 +3,7 @@ import { useRouter } from "next/router"; // ui import { CustomDatePicker, Tooltip } from "components/ui"; // helpers -import { findHowManyDaysLeft } from "helpers/date-time.helper"; +import { findHowManyDaysLeft, renderShortDateWithYearFormat } from "helpers/date-time.helper"; // services import trackEventServices from "services/track-event.service"; // types @@ -32,7 +32,9 @@ export const ViewDueDateSelect: React.FC = ({ return (
= ({ module, isOpen, moduleIs > - {renderShortDate(new Date(`${module.start_date}`), "Start date")} + {renderShortDateWithYearFormat( + new Date(`${module.start_date}`), + "Start date" + )} @@ -279,7 +282,10 @@ export const ModuleDetailsSidebar: React.FC = ({ module, isOpen, moduleIs - {renderShortDate(new Date(`${module?.target_date}`), "End date")} + {renderShortDateWithYearFormat( + new Date(`${module?.target_date}`), + "End date" + )} diff --git a/apps/app/components/project/single-project-card.tsx b/apps/app/components/project/single-project-card.tsx index 04e56652d..9b7bf1c99 100644 --- a/apps/app/components/project/single-project-card.tsx +++ b/apps/app/components/project/single-project-card.tsx @@ -22,7 +22,7 @@ import { TrashIcon, } from "@heroicons/react/24/outline"; // helpers -import { renderShortNumericDateFormat } from "helpers/date-time.helper"; +import { renderShortDateWithYearFormat } from "helpers/date-time.helper"; import { copyTextToClipboard, truncateText } from "helpers/string.helper"; // types import type { IFavoriteProject, IProject } from "types"; @@ -202,13 +202,13 @@ export const SingleProjectCard: React.FC = ({
- {renderShortNumericDateFormat(project.created_at)} + {renderShortDateWithYearFormat(project.created_at)}
{hasJoined ? ( diff --git a/apps/app/components/ui/date.tsx b/apps/app/components/ui/date.tsx index d835ff22b..d5a2cb722 100644 --- a/apps/app/components/ui/date.tsx +++ b/apps/app/components/ui/date.tsx @@ -5,7 +5,7 @@ import { CalendarDaysIcon, XMarkIcon } from "@heroicons/react/24/outline"; // react-datepicker import DatePicker from "react-datepicker"; // import "react-datepicker/dist/react-datepicker.css"; -import { renderDateFormat } from "helpers/date-time.helper"; +import { renderDateFormat, renderShortDateWithYearFormat } from "helpers/date-time.helper"; type Props = { value: string | null; @@ -21,7 +21,7 @@ export const DateSelect: React.FC = ({ value, onChange, label }) => ( {value ? ( <> - {value} + {renderShortDateWithYearFormat(value)} diff --git a/apps/app/components/ui/datepicker.tsx b/apps/app/components/ui/datepicker.tsx index 80ce7aa91..9b20dcafc 100644 --- a/apps/app/components/ui/datepicker.tsx +++ b/apps/app/components/ui/datepicker.tsx @@ -38,9 +38,9 @@ export const CustomDatePicker: React.FC = ({ }} className={`${ renderAs === "input" - ? "block px-3 py-2 text-sm focus:outline-none" + ? "block px-2 py-2 text-sm focus:outline-none" : renderAs === "button" - ? `px-3 py-1 text-xs shadow-sm ${ + ? `px-2 py-1 text-xs shadow-sm ${ disabled ? "" : "hover:bg-brand-surface-2" } duration-300 focus:border-brand-accent focus:outline-none focus:ring-1 focus:ring-brand-accent` : "" @@ -49,7 +49,7 @@ export const CustomDatePicker: React.FC = ({ } ${ noBorder ? "" : "border border-brand-base" } w-full rounded-md bg-transparent caret-transparent ${className}`} - dateFormat="dd-MM-yyyy" + dateFormat="MMM dd, yyyy" isClearable={isClearable} disabled={disabled} /> diff --git a/apps/app/components/views/single-view-item.tsx b/apps/app/components/views/single-view-item.tsx index 5e5ff3cc0..233ee3e74 100644 --- a/apps/app/components/views/single-view-item.tsx +++ b/apps/app/components/views/single-view-item.tsx @@ -18,7 +18,7 @@ import { VIEWS_LIST } from "constants/fetch-keys"; import useToast from "hooks/use-toast"; // helpers import { truncateText } from "helpers/string.helper"; -import { renderShortDate, renderShortTime } from "helpers/date-time.helper"; +import { renderShortDateWithYearFormat, renderShortTime } from "helpers/date-time.helper"; type Props = { view: IView; @@ -107,7 +107,7 @@ export const SingleViewItem: React.FC = ({ view, handleEditView, handleDe

{renderShortTime(view.updated_at)} diff --git a/apps/app/components/workspace/activity-graph.tsx b/apps/app/components/workspace/activity-graph.tsx index 1f9db203d..b49446eeb 100644 --- a/apps/app/components/workspace/activity-graph.tsx +++ b/apps/app/components/workspace/activity-graph.tsx @@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from "react"; // ui import { Tooltip } from "components/ui"; // helpers -import { renderDateFormat, renderShortNumericDateFormat } from "helpers/date-time.helper"; +import { renderDateFormat, renderShortDateWithYearFormat } from "helpers/date-time.helper"; // types import { IUserActivity } from "types"; // constants @@ -109,7 +109,7 @@ export const ActivityGraph: React.FC = ({ activities }) => { key={`${date}-${index}`} tooltipContent={`${ isActive ? isActive.activity_count : 0 - } activities on ${renderShortNumericDateFormat(date)}`} + } activities on ${renderShortDateWithYearFormat(date)}`} theme="dark" >

{ +export const renderShortDateWithYearFormat = (date: string | Date, placeholder?: string) => { if (!date || date === "") return null; date = new Date(date); @@ -136,7 +136,8 @@ export const renderShortDateWithYearFormat = (date: string | Date) => { const day = date.getDate(); const month = months[date.getMonth()]; const year = date.getFullYear(); - return isNaN(date.getTime()) ? "N/A" : ` ${month} ${day}, ${year}`; + + return isNaN(date.getTime()) ? placeholder ?? "N/A" : ` ${month} ${day}, ${year}`; }; export const renderShortDate = (date: string | Date, placeholder?: string) => {