diff --git a/app/actions/list.action.ts b/app/actions/list.action.ts new file mode 100644 index 0000000..7146aac --- /dev/null +++ b/app/actions/list.action.ts @@ -0,0 +1,45 @@ +'use server'; + +import { revalidateTag } from 'next/cache'; +import { redirect } from 'next/navigation'; +import { z } from 'zod'; + +import { auth } from '@/lib/auth'; +import { prisma } from '@/lib/prisma'; + +const schema = z.object({ + name: z.string(), + spaceId: z.string() +}); + +export const addList = async (formData: FormData) => { + const { name, spaceId } = schema.parse({ + name: formData.get('name'), + spaceId: formData.get('spaceId') + }); + + const session = await auth(); + + const newList = await prisma.list.create({ + data: { + name, + Space: { + connect: { + id: spaceId + } + }, + creator: { + connect: { + id: session?.user.id + } + } + }, + select: { + id: true + } + }); + + revalidateTag(`/spaces/${spaceId}`); + + redirect(`/spaces/${spaceId}/lists/${newList.id}`); +}; diff --git a/app/actions/space.actions.ts b/app/actions/space.actions.ts new file mode 100644 index 0000000..ad30098 --- /dev/null +++ b/app/actions/space.actions.ts @@ -0,0 +1,35 @@ +'use server'; + +import { revalidateTag } from 'next/cache'; +import { redirect } from 'next/navigation'; +import { z } from 'zod'; + +import { auth } from '@/lib/auth'; +import { prisma } from '@/lib/prisma'; + +const schema = z.object({ + name: z.string() +}); + +export const addSpace = async (formData: FormData) => { + const parsed = schema.parse({ + name: formData.get('name') + }); + + const session = await auth(); + + const space = await prisma.space.create({ + data: { + name: parsed.name, + creator: { + connect: { + id: session?.user.id + } + } + } + }); + + revalidateTag('/spaces'); + + redirect(`/spaces/${space.id}`); +}; diff --git a/app/page.tsx b/app/page.tsx index 32d50fe..f4340c2 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,7 +1,7 @@ export default function Home() { return (
-

main content

+

hello

); } diff --git a/app/spaces/[spaceId]/lists/[listId]/not-found.tsx b/app/spaces/[spaceId]/lists/[listId]/not-found.tsx new file mode 100644 index 0000000..f0a81bb --- /dev/null +++ b/app/spaces/[spaceId]/lists/[listId]/not-found.tsx @@ -0,0 +1,29 @@ +'use client'; + +import Link from 'next/link'; +import { useParams } from 'next/navigation'; + +import { SpaceItemParams } from '../../page'; + +export default function NotFound() { + const params = useParams(); + + return ( +
+

Oops Your List was not found

+ +
+

+ Go back to{' '} + + Your Lists + {' '} + or{' '} + + Home Page + +

+
+
+ ); +} diff --git a/app/spaces/[spaceId]/lists/[listId]/page.tsx b/app/spaces/[spaceId]/lists/[listId]/page.tsx new file mode 100644 index 0000000..8ff2fb5 --- /dev/null +++ b/app/spaces/[spaceId]/lists/[listId]/page.tsx @@ -0,0 +1,24 @@ +import { notFound } from 'next/navigation'; + +import { prisma } from '@/lib/prisma'; + +import { SpaceItemParams } from '../../page'; + +type ListItemParams = SpaceItemParams & { + listId: string; +}; +export default async function List({ params }: { params: ListItemParams }) { + const list = await prisma.list.findUnique({ + where: { id: params.listId } + }); + + if (!list) { + notFound(); + } + + return ( +
+

{params.spaceId}

+
+ ); +} diff --git a/app/spaces/[spaceId]/lists/add/page.tsx b/app/spaces/[spaceId]/lists/add/page.tsx new file mode 100644 index 0000000..5880c6d --- /dev/null +++ b/app/spaces/[spaceId]/lists/add/page.tsx @@ -0,0 +1,25 @@ +import { addList } from '@/app/actions/list.action'; +import { FormField } from '@/components/formField'; +import { Button } from '@/components/ui/button'; + +export default function AddList({ + params: { spaceId } +}: { + params: { spaceId: string }; +}) { + return ( +
+
+ +
+ ); +} diff --git a/app/spaces/[spaceId]/not-found.tsx b/app/spaces/[spaceId]/not-found.tsx new file mode 100644 index 0000000..809cdcb --- /dev/null +++ b/app/spaces/[spaceId]/not-found.tsx @@ -0,0 +1,22 @@ +import Link from 'next/link'; + +export default function NotFound() { + return ( +
+

Oops Your Space was not found

+ +
+

+ Go back to{' '} + + Your Spaces + {' '} + or{' '} + + Home Page + +

+
+
+ ); +} diff --git a/app/spaces/[spaceId]/page.tsx b/app/spaces/[spaceId]/page.tsx new file mode 100644 index 0000000..929abae --- /dev/null +++ b/app/spaces/[spaceId]/page.tsx @@ -0,0 +1,58 @@ +import Link from 'next/link'; +import { notFound } from 'next/navigation'; + +import { prisma } from '@/lib/prisma'; + +export type SpaceItemParams = { spaceId: string }; + +export default async function SingleSpace({ + params: { spaceId: paramsSpaceId } +}: { + params: SpaceItemParams; +}) { + const space = await prisma.space.findUnique({ + where: { id: paramsSpaceId }, + include: { Lists: true } + }); + + if (!space) { + notFound(); + } + + return ( +
+
+

+ ☀︎ {space.name} +

+ + + + +
+ {!space.Lists.length ? ( +
+

No List was Found

+
+ ) : ( + + )} +
+ ); +} diff --git a/app/spaces/add/page.tsx b/app/spaces/add/page.tsx new file mode 100644 index 0000000..7777bed --- /dev/null +++ b/app/spaces/add/page.tsx @@ -0,0 +1,17 @@ +import { addSpace } from '@/app/actions/space.actions'; +import { FormField } from '@/components/formField'; +import { Button } from '@/components/ui/button'; + +export default async function NewSpace() { + return ( +
+

ADD NEW SPACE

+ +
+ + {/*
+ ); +} diff --git a/app/spaces/page.tsx b/app/spaces/page.tsx new file mode 100644 index 0000000..67dad8a --- /dev/null +++ b/app/spaces/page.tsx @@ -0,0 +1,62 @@ +import Link from 'next/link'; +import { redirect } from 'next/navigation'; + +import { auth } from '@/lib/auth'; +import { prisma } from '@/lib/prisma'; + +export default async function Spaces() { + const session = await auth(); + + const id = session?.user?.id; + + if (!id) { + redirect('/'); + } + + const spaces = await prisma.space.findMany({ + where: { + creator: { + id + } + } + }); + + console.log(spaces); + + return ( +
+
+

+ Your Spaces +

+ + + + + +
+
+ {spaces.length ? ( +
+
    + {spaces.map((sp) => ( +
  • + + {sp.name} + +
  • + ))} +
+
+ ) : ( +
no space was found
+ )} +
+
+ ); +} diff --git a/components/Anchor.tsx b/components/Anchor.tsx index dea7dde..282ade7 100644 --- a/components/Anchor.tsx +++ b/components/Anchor.tsx @@ -4,5 +4,5 @@ import { RouteType } from 'next/dist/lib/load-custom-routes'; import Link, { LinkProps } from 'next/link'; export function Anchor(props: PropsWithChildren>) { - return ; + return ; } diff --git a/components/Nav.tsx b/components/Nav.tsx index 0bbfa58..da243b8 100644 --- a/components/Nav.tsx +++ b/components/Nav.tsx @@ -14,9 +14,10 @@ export async function Nav() { const session = await auth(); return ( -