diff --git a/app/components/Card/Card.tsx b/app/components/Card/Card.tsx index bbec467..4909f95 100644 --- a/app/components/Card/Card.tsx +++ b/app/components/Card/Card.tsx @@ -84,7 +84,13 @@ export default function DocCard({ docId, thumbnail, title, updatedAt, users }: D ) })} -

{prettifyDate(String(updatedAt))}

+

+ {prettifyDate(String(updatedAt), { + year: "numeric", + month: "short", + day: "2-digit" + })} +

diff --git a/app/components/Header/Header.tsx b/app/components/Header/Header.tsx index df6dc72..c976c22 100644 --- a/app/components/Header/Header.tsx +++ b/app/components/Header/Header.tsx @@ -41,6 +41,7 @@ export default function Header() { const logout = async () => { const response = await LogoutAction(); + console.log(response); if (response.success) { toast.success("Successfully logged out") router.push('/api/auth/signin') diff --git a/app/components/Header/actions.ts b/app/components/Header/actions.ts index f6fd198..03f7705 100644 --- a/app/components/Header/actions.ts +++ b/app/components/Header/actions.ts @@ -32,12 +32,17 @@ export const CreateNewDocument = async (userId: string) => { export const LogoutAction = async () => { try { + console.log("here1") cookies().delete('token'); + console.log("here2") cookies().delete('next-auth.session-token'); + console.log("here3") signOut(); + console.log("here4") return { success: true, data: null }; } catch (e) { + console.log("here5") console.error(e); return { success: false, error: "Internal server error" }; } diff --git a/app/writer/[id]/actions.ts b/app/writer/[id]/actions.ts index abc378c..4131ca8 100644 --- a/app/writer/[id]/actions.ts +++ b/app/writer/[id]/actions.ts @@ -1,6 +1,8 @@ "use server" +import prettifyDate from "@/helpers/prettifyDates" import prisma from "@/prisma/prismaClient" +import { revalidatePath } from "next/cache" export const GetDocDetails = async (id: any, userId: string) => { try { @@ -18,7 +20,6 @@ export const GetDocDetails = async (id: any, userId: string) => { } export const UpdateDocData = async (id: any, userId: string, data: string) => { - console.log("here3") try { const doc = await prisma.document.findFirst({ where: { id, userId } }) if (!doc) return { @@ -26,13 +27,12 @@ export const UpdateDocData = async (id: any, userId: string, data: string) => { error: "Document does not exist", } - console.log("here4") await prisma.document.update( { where: { id, userId }, data: { data: data, - updatedAt: Date(), + updatedAt: new Date(), } }) @@ -52,6 +52,7 @@ export const UpdateThumbnail = async (id: any, userId: string, thumbnail: string } await prisma.document.update({ where: { id, userId }, data: { thumbnail } }) + revalidatePath('/'); return { success: true, data: "Internal server error" } } catch (e) { diff --git a/app/writer/[id]/page.tsx b/app/writer/[id]/page.tsx index d6357eb..6dbc796 100644 --- a/app/writer/[id]/page.tsx +++ b/app/writer/[id]/page.tsx @@ -101,6 +101,7 @@ export default function Dashboard() { }); useEffect(() => { + console.log(docData); if (editor && docData) { editor.commands.setContent(docData); } diff --git a/helpers/prettifyDates.ts b/helpers/prettifyDates.ts index ad7d991..4667475 100644 --- a/helpers/prettifyDates.ts +++ b/helpers/prettifyDates.ts @@ -1,13 +1,23 @@ -const prettifyDate = (dateString: string | undefined) => { - if(!dateString) return "" +type OptionsType = { + weekday?: "narrow" | "short" | "long"; + year?: "numeric" | "2-digit"; + month?: "numeric" | "2-digit" | "narrow" | "short" | "long"; + day?: "numeric" | "2-digit"; + hour?: "numeric" | "2-digit"; + minute?: "numeric" | "2-digit"; + second?: "numeric" | "2-digit"; + timeZoneName?: "short" | "long"; + hour12?: boolean; + era?: "narrow" | "short" | "long"; + timeZone?: string; + fractionalSecondDigits?: 1 | 2 | 3; +}; + +const prettifyDate = (dateString: string | undefined, options: OptionsType) => { + if (!dateString) return "" const date = new Date(dateString); - return new Intl.DateTimeFormat("en-US", { - // weekday: "short", - year: "numeric", - month: "short", - day: "numeric", - }).format(date); + return new Intl.DateTimeFormat("en-US", options).format(date); }; export default prettifyDate;