Skip to content

Commit

Permalink
Merge pull request #12 from git-init-priyanshu/nextjs
Browse files Browse the repository at this point in the history
Nextjs
  • Loading branch information
git-init-priyanshu authored Aug 8, 2024
2 parents 7b204f7 + 1a38a8c commit 428c61a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
8 changes: 7 additions & 1 deletion app/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ export default function DocCard({ docId, thumbnail, title, updatedAt, users }: D
</Avatar>
)
})}
<p className="text-neutral-600 cursor-default">{prettifyDate(String(updatedAt))}</p>
<p className="text-neutral-600 cursor-default">
{prettifyDate(String(updatedAt), {
year: "numeric",
month: "short",
day: "2-digit"
})}
</p>
</div>
<CardOptions docId={docId} inputRef={inputRef} />
</div>
Expand Down
1 change: 1 addition & 0 deletions app/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions app/components/Header/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
}
Expand Down
7 changes: 4 additions & 3 deletions app/writer/[id]/actions.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -18,21 +20,19 @@ 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 {
success: false,
error: "Document does not exist",
}

console.log("here4")
await prisma.document.update(
{
where: { id, userId },
data: {
data: data,
updatedAt: Date(),
updatedAt: new Date(),
}
})

Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions app/writer/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default function Dashboard() {
});

useEffect(() => {
console.log(docData);
if (editor && docData) {
editor.commands.setContent(docData);
}
Expand Down
26 changes: 18 additions & 8 deletions helpers/prettifyDates.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 428c61a

Please sign in to comment.