fix: date upload in table spit
This commit is contained in:
parent
720ae06d78
commit
1eb206e218
|
|
@ -15,7 +15,7 @@ import {
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import { format } from "date-fns";
|
import { format, parseISO } from "date-fns";
|
||||||
import { Link } from "@/components/navigation";
|
import { Link } from "@/components/navigation";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import withReactContent from "sweetalert2-react-content";
|
import withReactContent from "sweetalert2-react-content";
|
||||||
|
|
@ -118,21 +118,43 @@ const useTableColumns = () => {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// accessorKey: "contentCreatedDate",
|
||||||
|
// header: t("upload-date", { defaultValue: "Upload Date" }),
|
||||||
|
// cell: ({ row }) => {
|
||||||
|
// const createdAt = row.getValue("contentCreatedDate") as
|
||||||
|
// | string
|
||||||
|
// | number
|
||||||
|
// | undefined;
|
||||||
|
// const formattedDate =
|
||||||
|
// createdAt && !isNaN(new Date(createdAt).getTime())
|
||||||
|
// ? format(new Date(createdAt), "dd-MM-yyyy HH:mm:ss")
|
||||||
|
// : "-";
|
||||||
|
// return <span className="whitespace-nowrap">{formattedDate}</span>;
|
||||||
|
// },
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
accessorKey: "contentCreatedDate",
|
accessorKey: "contentCreatedDate",
|
||||||
header: t("upload-date", { defaultValue: "Upload Date" }),
|
header: t("upload-date", { defaultValue: "Upload Date" }),
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const createdAt = row.getValue("contentCreatedDate") as
|
const createdAt = row.getValue("contentCreatedDate") as string | null;
|
||||||
| string
|
|
||||||
| number
|
if (!createdAt) return <span>-</span>;
|
||||||
| undefined;
|
|
||||||
const formattedDate =
|
// parse ISO string dari API (UTC)
|
||||||
createdAt && !isNaN(new Date(createdAt).getTime())
|
const date = parseISO(createdAt);
|
||||||
? format(new Date(createdAt), "dd-MM-yyyy HH:mm:ss")
|
|
||||||
: "-";
|
// geser balik dengan timezoneOffset supaya yang tampil = UTC
|
||||||
|
const utcDate = new Date(
|
||||||
|
date.getTime() + date.getTimezoneOffset() * 60000
|
||||||
|
);
|
||||||
|
|
||||||
|
const formattedDate = format(utcDate, "dd-MM-yyyy HH:mm:ss");
|
||||||
|
|
||||||
return <span className="whitespace-nowrap">{formattedDate}</span>;
|
return <span className="whitespace-nowrap">{formattedDate}</span>;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
id: "actions",
|
id: "actions",
|
||||||
accessorKey: "action",
|
accessorKey: "action",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue