mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
Merge pull request #341 from Hexastack/336-bug-time-formatting-breaks-after-sending-a-new-message-in-the-inbox
fix(frontend): date normalization
This commit is contained in:
commit
beddb7f22a
@ -22,6 +22,7 @@ import { useAuth } from "@/hooks/useAuth";
|
|||||||
import { useConfig } from "@/hooks/useConfig";
|
import { useConfig } from "@/hooks/useConfig";
|
||||||
import { useTranslate } from "@/hooks/useTranslate";
|
import { useTranslate } from "@/hooks/useTranslate";
|
||||||
import { EntityType } from "@/services/types";
|
import { EntityType } from "@/services/types";
|
||||||
|
import { normalizeDate } from "@/utils/date";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getAvatarSrc,
|
getAvatarSrc,
|
||||||
@ -115,8 +116,9 @@ export function Chat() {
|
|||||||
key={message.id}
|
key={message.id}
|
||||||
title={`${subscriber.first_name} ${
|
title={`${subscriber.first_name} ${
|
||||||
subscriber.last_name
|
subscriber.last_name
|
||||||
} : ${message.createdAt.toLocaleString(
|
} : ${normalizeDate(
|
||||||
i18n.language,
|
i18n.language,
|
||||||
|
message.createdAt,
|
||||||
)}`}
|
)}`}
|
||||||
src={getAvatarSrc(
|
src={getAvatarSrc(
|
||||||
apiUrl,
|
apiUrl,
|
||||||
|
@ -20,6 +20,7 @@ import { useConfig } from "@/hooks/useConfig";
|
|||||||
import { useTranslate } from "@/hooks/useTranslate";
|
import { useTranslate } from "@/hooks/useTranslate";
|
||||||
import { Title } from "@/layout/content/Title";
|
import { Title } from "@/layout/content/Title";
|
||||||
import { EntityType, RouterType } from "@/services/types";
|
import { EntityType, RouterType } from "@/services/types";
|
||||||
|
import { normalizeDate } from "@/utils/date";
|
||||||
import { extractQueryParamsUrl } from "@/utils/URL";
|
import { extractQueryParamsUrl } from "@/utils/URL";
|
||||||
|
|
||||||
import { getAvatarSrc } from "../helpers/mapMessages";
|
import { getAvatarSrc } from "../helpers/mapMessages";
|
||||||
@ -82,7 +83,7 @@ export const SubscribersList = (props: {
|
|||||||
{subscriber.first_name} {subscriber.last_name}
|
{subscriber.first_name} {subscriber.last_name}
|
||||||
</div>
|
</div>
|
||||||
<div className="cs-conversation__info">
|
<div className="cs-conversation__info">
|
||||||
{subscriber.lastvisit?.toLocaleString(i18n.language)}
|
{normalizeDate(i18n.language, subscriber.lastvisit)}
|
||||||
</div>
|
</div>
|
||||||
</Conversation.Content>
|
</Conversation.Content>
|
||||||
<Conversation.Operations visible>
|
<Conversation.Operations visible>
|
||||||
|
@ -14,3 +14,25 @@ export const getDateTimeFormatter = (date: Date) => ({
|
|||||||
val: DATE_TIME_FORMAT,
|
val: DATE_TIME_FORMAT,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes and formats a date using the provided locale
|
||||||
|
*
|
||||||
|
* @param {string} locale - The locale to use for formatting (e.g., 'en-US', 'fr-FR')
|
||||||
|
* @param {Date | string} dateField - The date to format, either as Date object or string
|
||||||
|
* @param {Intl.DateTimeFormatOptions} options - An object that contains one or more properties that specify comparison options
|
||||||
|
* @returns {string | undefined} Formatted date string, or undefined if dateField is undefined
|
||||||
|
*/
|
||||||
|
export const normalizeDate = (
|
||||||
|
locale: string = "en-US",
|
||||||
|
dateField?: Date | string,
|
||||||
|
options?: Intl.DateTimeFormatOptions,
|
||||||
|
) => {
|
||||||
|
if (!dateField) return undefined;
|
||||||
|
|
||||||
|
const date = typeof dateField === "string" ? new Date(dateField) : dateField;
|
||||||
|
|
||||||
|
return !isNaN(date.getTime())
|
||||||
|
? date.toLocaleString(locale, options)
|
||||||
|
: undefined;
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user