fix(frontend): date normalization

This commit is contained in:
yassinedorbozgithub 2024-11-17 09:10:25 +01:00
parent dadb263176
commit 2c7c821b39
3 changed files with 11 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import { useAuth } from "@/hooks/useAuth";
import { useConfig } from "@/hooks/useConfig";
import { useTranslate } from "@/hooks/useTranslate";
import { EntityType } from "@/services/types";
import { normalizeDate } from "@/utils/date";
import {
getAvatarSrc,
@ -115,8 +116,9 @@ export function Chat() {
key={message.id}
title={`${subscriber.first_name} ${
subscriber.last_name
} : ${message.createdAt.toLocaleString(
} : ${normalizeDate(
i18n.language,
message.createdAt,
)}`}
src={getAvatarSrc(
apiUrl,

View File

@ -20,6 +20,7 @@ import { useConfig } from "@/hooks/useConfig";
import { useTranslate } from "@/hooks/useTranslate";
import { Title } from "@/layout/content/Title";
import { EntityType, RouterType } from "@/services/types";
import { normalizeDate } from "@/utils/date";
import { extractQueryParamsUrl } from "@/utils/URL";
import { getAvatarSrc } from "../helpers/mapMessages";
@ -82,7 +83,7 @@ export const SubscribersList = (props: {
{subscriber.first_name} {subscriber.last_name}
</div>
<div className="cs-conversation__info">
{subscriber.lastvisit?.toLocaleString(i18n.language)}
{normalizeDate(i18n.language, subscriber.lastvisit)}
</div>
</Conversation.Content>
<Conversation.Operations visible>

View File

@ -14,3 +14,9 @@ export const getDateTimeFormatter = (date: Date) => ({
val: DATE_TIME_FORMAT,
},
});
export const normalizeDate = (locale: string, dateField?: Date | string) =>
(typeof dateField === "string"
? new Date(dateField)
: dateField
)?.toLocaleString(locale);