diff --git a/app/(auth)/actions.ts b/app/(auth)/actions.ts
index f2b1993..2e3c950 100644
--- a/app/(auth)/actions.ts
+++ b/app/(auth)/actions.ts
@@ -2,26 +2,12 @@
import { cookies } from "next/headers"
import { z } from 'zod';
-import { JWTPayload, SignJWT, importJWK } from 'jose';
// @ts-ignore
import bcrypt from 'bcryptjs';
import prisma from "@/prisma/prismaClient";
import { signinSchema, signupSchema } from './zodSchema';
-
-const generateJWT = async (payload: JWTPayload) => {
- const secret = process.env.JWT_SECRET || 'secret';
-
- const jwk = await importJWK({ k: secret, alg: 'HS256', kty: 'oct' });
-
- const jwt = await new SignJWT(payload)
- .setProtectedHeader({ alg: 'HS256' })
- .setIssuedAt()
- .setExpirationTime('365d')
- .sign(jwk);
-
- return jwt;
-};
+import { generateJWT } from "@/helpers/generateJWT";
export const SignupAction = async (data: z.infer) => {
try {
@@ -51,7 +37,7 @@ export const SignupAction = async (data: z.infer) => {
await prisma.user.upsert({
where: { email: data.email },
update: {
- password: hashedPassword
+ password: hashedPassword
},
create: {
name: data.name,
diff --git a/app/(auth)/signin/components/LogInForm.tsx b/app/(auth)/signin/components/SignInForm.tsx
similarity index 100%
rename from app/(auth)/signin/components/LogInForm.tsx
rename to app/(auth)/signin/components/SignInForm.tsx
diff --git a/app/(auth)/signin/page.tsx b/app/(auth)/signin/page.tsx
index cc0cc73..15dde56 100644
--- a/app/(auth)/signin/page.tsx
+++ b/app/(auth)/signin/page.tsx
@@ -2,7 +2,7 @@
import Link from "next/link"
-import LogInForm from "./components/LogInForm"
+import SignInForm from "./components/SignInForm"
import GoogleAuthButton from "./components/GoogleAuthButton"
export default function Login() {
@@ -16,7 +16,7 @@ export default function Login() {
-
+
OR
diff --git a/app/actions.ts b/app/actions.ts
index 740d153..9ddbb82 100644
--- a/app/actions.ts
+++ b/app/actions.ts
@@ -6,12 +6,21 @@ export const GetAllDocs = async (userId: string) => {
try {
const response = await prisma.document.findMany(
{
- where: { userId },
+ where: {
+ users: {
+ some: {
+ user: {
+ id: userId
+ }
+ }
+ }
+ },
select: {
id: true,
thumbnail: true,
name: true,
updatedAt: true,
+ createdBy: true,
users: {
select: {
user: {
diff --git a/app/components/Card/Card.tsx b/app/components/Card/Card.tsx
index 8ebf59f..65c20bd 100644
--- a/app/components/Card/Card.tsx
+++ b/app/components/Card/Card.tsx
@@ -2,20 +2,21 @@
import { useRef, useState } from "react"
import { useRouter } from "next/navigation"
+import { CircleCheck } from "lucide-react"
import {
Card,
CardContent,
CardFooter,
} from "@/components/ui/card"
-import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Input } from "@/components/ui/input"
+import type { User } from "@prisma/client"
-import prettifyDate from '@/helpers/prettifyDates'
-import CardOptions from "./components/Options"
import { RenameDocument } from "./actions"
+import AvatarList from '@/components/AvatarList'
+import CardOptions from "./components/Options"
+import prettifyDate from '@/helpers/prettifyDates'
import useClientSession from "@/lib/customHooks/useClientSession"
-import { CircleCheck } from "lucide-react"
type DocCardPropType = {
docId: string;
@@ -23,29 +24,25 @@ type DocCardPropType = {
title: string;
updatedAt: Date
users: {
- user:
- {
- name: string,
- picture: string | null
- }
+ user: Pick
}[]
}
-export default function DocCard({ docId, thumbnail, title, updatedAt, users }: DocCardPropType) {
+export default function DocCard({
+ docId,
+ thumbnail,
+ title,
+ updatedAt,
+ users
+}: DocCardPropType) {
const router = useRouter();
const session = useClientSession();
+ localStorage.setItem('name', session.name as string);
const inputRef = useRef(null);
const [name, setName] = useState(title)
- const getInitials = (name: string) => {
- let initials = name.split(" ");
-
- if (initials.length > 2) return initials[0][0] + initials[1][0];
- return initials[0][0];
- }
-
return (
- {users.map((e, index) => {
- return (
-
- {
- e.user.picture
- ?
- : {getInitials(e.user.name)}
- }
-
- )
- })}
+
{prettifyDate(String(updatedAt), {
year: "numeric",
diff --git a/app/components/Card/components/Options.tsx b/app/components/Card/components/Options.tsx
index d486543..85bd936 100644
--- a/app/components/Card/components/Options.tsx
+++ b/app/components/Card/components/Options.tsx
@@ -26,6 +26,7 @@ import { Button } from "@/components/ui/button"
import { DeleteDocument } from "../actions"
import useClientSession from "@/lib/customHooks/useClientSession"
import LoaderButton from "@/components/LoaderButton"
+import { Jua } from "next/font/google"
type CardOptionsPropType = {
docId: string,
@@ -40,12 +41,12 @@ export default function CardOptions({ docId, inputRef }: CardOptionsPropType) {
const docOptions = [
{ icon: Type, color: "#60b7c3", title: "Rename", onClick: () => renameDocument() },
{ icon: FilePenLine, color: "#48acf9", title: "Edit", onClick: () => editDocument() },
- { icon: Share2, color: "#48f983", title: "Share", onClick: () => console.log("edit") },
+ { icon: Share2, color: "#48f983", title: "Share", onClick: () => shareDocument() },
{ icon: Trash2, color: "#f94848", title: "Delete", onClick: () => deleteDocument() },
]
const [isOptionsOpen, setIsOptionsOpen] = useState(false);
- const [isOpen, setIsOpen] = useState(false);
+ const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
const renameDocument = () => {
@@ -58,9 +59,20 @@ export default function CardOptions({ docId, inputRef }: CardOptionsPropType) {
router.push(`/writer/${docId}`)
}
+ const shareDocument = () => {
+ navigator.clipboard.writeText(`${process.env.NEXT_PUBLIC_APP_URL}/writer/${docId}`).then(() => {
+ toast.success('Share link copied to clipboard');
+ }).catch(e => {
+ console.log(e)
+ toast.error(e);
+ }).finally(() => {
+ setIsOptionsOpen(false);
+ });
+ }
+
const deleteDocument = async () => {
setIsOptionsOpen(false);
- setIsOpen(true);
+ setIsDeleteModalOpen(true);
}
const confirmDeleteDocument = async () => {
@@ -102,7 +114,7 @@ export default function CardOptions({ docId, inputRef }: CardOptionsPropType) {
-