From 1db68f1b40a63ff4ca2b7ecdbfa255b19b5fe168 Mon Sep 17 00:00:00 2001 From: Phill Pover Date: Sat, 5 Apr 2025 10:44:33 +0100 Subject: [PATCH] Moving create form to modal --- frontend/src/app/album/page.tsx | 43 +++---------- .../app/components/modals/create-album.tsx | 61 +++++++++++++++++++ 2 files changed, 70 insertions(+), 34 deletions(-) create mode 100644 frontend/src/app/components/modals/create-album.tsx diff --git a/frontend/src/app/album/page.tsx b/frontend/src/app/album/page.tsx index f1396d1..2ff95e7 100644 --- a/frontend/src/app/album/page.tsx +++ b/frontend/src/app/album/page.tsx @@ -1,14 +1,13 @@ 'use client'; -import { FormEvent, useState, useEffect } from 'react'; +import { useState, useEffect } from 'react'; import Link from 'next/link'; import { Album } from '@/entities/album.entity'; -import { createAlbum } from '@/app/actions'; -import { useRouter } from 'next/navigation'; +import CreateAlbumModal from "@/app/components/modals/create-album"; +import { Suspense } from "react"; export default function Page() { const [albums, setAlbums] = useState([]); - const router = useRouter(); useEffect(() => { async function fetchAlbums() { @@ -21,18 +20,11 @@ export default function Page() { if (!albums) return
Loading...
- async function onSubmit(event: FormEvent) { - event.preventDefault(); - - const formData = new FormData(event.currentTarget); - const response = await createAlbum(formData); - - await response.json(); - router.refresh(); - } - return (
+ + + @@ -63,26 +55,9 @@ export default function Page() { ))}
-
-
-
- -
-
- -
-
-
-
- -
-
-
-
- -
-
-
+ + +
); } diff --git a/frontend/src/app/components/modals/create-album.tsx b/frontend/src/app/components/modals/create-album.tsx new file mode 100644 index 0000000..6d124b2 --- /dev/null +++ b/frontend/src/app/components/modals/create-album.tsx @@ -0,0 +1,61 @@ +"use client"; + +import { FormEvent } from 'react'; +import {useSearchParams, usePathname} from "next/navigation"; +import Link from "next/link"; +import { createAlbum } from '@/app/actions'; +import { useRouter } from 'next/navigation'; + +function CreateAlbumModal() { + const searchParams = useSearchParams(); + const modal = searchParams.get("modal"); + const pathname = usePathname(); + const router = useRouter(); + + async function onSubmit(event: FormEvent) { + event.preventDefault(); + + const formData = new FormData(event.currentTarget); + const response = await createAlbum(formData); + + await response.json(); + router.refresh(); + } + + return ( + <> + {modal && + +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+ } + + ); +} + +export default CreateAlbumModal;