From 4586c84b4e25e1dff44b74a5adfeec3e6c7b040d Mon Sep 17 00:00:00 2001 From: Takeshi Kimata <117462761+kimatata@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:31:38 +0900 Subject: [PATCH] create project dialog --- frontend/app/projects/page.tsx | 135 ++++++----------------- frontend/app/projects/project-dialog.tsx | 116 +++++++++++++++++++ 2 files changed, 152 insertions(+), 99 deletions(-) create mode 100644 frontend/app/projects/project-dialog.tsx diff --git a/frontend/app/projects/page.tsx b/frontend/app/projects/page.tsx index 8c487dd..7fa499e 100644 --- a/frontend/app/projects/page.tsx +++ b/frontend/app/projects/page.tsx @@ -2,20 +2,20 @@ import { useEffect, useState } from "react"; import { title } from "@/components/primitives"; import { ProjectCard } from "./project-card"; -import { - Button, - Input, - Textarea, - Modal, - ModalContent, - ModalHeader, - ModalBody, - ModalFooter, -} from "@nextui-org/react"; +import { ProjectDialog } from "./project-dialog"; +import { Button } from "@nextui-org/react"; import Config from "@/config/config"; const apiServer = Config.apiServer; +export type ProjectType = { + id: number; + name: string; + detail: string; + createdAt: string; + updatedAt: string; +}; + /** * fetch project records * @@ -23,7 +23,7 @@ const apiServer = Config.apiServer; * @returns {Promise} - project record array * @throws {Error} */ -async function fetchProjects(url) { +async function fetchProjects(url: string) { try { const response = await fetch(url, { method: "GET", @@ -50,7 +50,7 @@ async function fetchProjects(url) { * @function * @throws {Error} */ -async function createProject(name, detail) { +async function createProject(name: string, detail: string) { const newProjectData = { name: name, detail: detail, @@ -118,51 +118,23 @@ export default function ProjectsPage() { fetchDataEffect(); }, []); - // new project data - const [projectName, setProjectName] = useState({ - text: "", - isValid: false, - errorMessage: "", - }); - const [projectDetail, setProjectDetail] = useState({ - text: "", - isValid: false, - errorMessage: "", - }); - - // modal - const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false); - const openModal = () => { - setIsCreateDialogOpen(true); + // dialog + const [isProjectDialogOpen, setIsProjectDialogOpen] = useState(false); + const [editingProject, setEditingProject] = useState(null); + const openDialogForCreate = () => { + setIsProjectDialogOpen(true); + setEditingProject(null); }; - const closeModal = () => { - setProjectName({ text: "", isValid: false, errorMessage: "" }); - setProjectDetail({ text: "", isValid: false, errorMessage: "" }); - setIsCreateDialogOpen(false); + const closeDialog = () => { + setIsProjectDialogOpen(false); + setEditingProject(null); }; - const onCreateClicked = async () => { - let isValid = true; - - // validate projectName - if (!projectName.text) { - setProjectName({ - text: "", - isValid: false, - errorMessage: "Please enter project name", - }); - isValid = false; - } - - if (isValid) { - const newProject = await createProject( - projectName.text, - projectDetail.text - ); - setProjects([...projects, newProject]); - closeModal(); - } + const onSubmit = async (name: string, detail: string) => { + const newProject = await createProject(name, detail); + setProjects([...projects, newProject]); + closeDialog(); }; const onDeleteClicked = async (projectId: number) => { @@ -178,7 +150,11 @@ export default function ProjectsPage() {

Projects

-
@@ -193,51 +169,12 @@ export default function ProjectsPage() { ))}
- { - setIsCreateDialogOpen(false); - }} - > - - Project - - { - setProjectName({ - ...projectName, - text: e.target.value, - }); - }} - /> -