fix: N/A problem on repacks

This commit is contained in:
Zamitto 2024-10-23 13:23:44 -03:00
parent b46f46bc45
commit 582c276e95
2 changed files with 8 additions and 3 deletions

View File

@ -77,6 +77,8 @@ export function useDate() {
},
formatDate: (date: number | Date | string): string => {
if (isNaN(new Date(date).getDate())) return "N/A";
const locale = getDateLocale();
return format(date, locale == enUS ? "MM/dd/yyyy" : "dd/MM/yyyy");
},

View File

@ -1,8 +1,7 @@
import { format } from "date-fns";
import { useContext } from "react";
import { useTranslation } from "react-i18next";
import { useDownload } from "@renderer/hooks";
import { useDate, useDownload } from "@renderer/hooks";
import { HeroPanelActions } from "./hero-panel-actions";
import * as styles from "./hero-panel.css";
@ -17,6 +16,8 @@ export interface HeroPanelProps {
export function HeroPanel({ isHeaderStuck }: HeroPanelProps) {
const { t } = useTranslation("game_details");
const { formatDate } = useDate();
const { game, repacks, gameColor } = useContext(gameDetailsContext);
const { lastPacket } = useDownload();
@ -29,7 +30,9 @@ export function HeroPanel({ isHeaderStuck }: HeroPanelProps) {
const [latestRepack] = repacks;
if (latestRepack) {
const lastUpdate = format(latestRepack.uploadDate!, "dd/MM/yyyy");
const lastUpdate = latestRepack.uploadDate
? formatDate(latestRepack.uploadDate!)
: "";
const repacksCount = repacks.length;
return (