Create Home tab
This commit is contained in:
@@ -29,10 +29,12 @@ app.use("/", indexRoute);
|
|||||||
|
|
||||||
// "/projects"
|
// "/projects"
|
||||||
const projectsIndexRoute = require("./routes/projects/index")(sequelize);
|
const projectsIndexRoute = require("./routes/projects/index")(sequelize);
|
||||||
|
const projectsShowRoute = require("./routes/projects/show")(sequelize);
|
||||||
const projectsNewRoute = require("./routes/projects/new")(sequelize);
|
const projectsNewRoute = require("./routes/projects/new")(sequelize);
|
||||||
const projectsEditRoute = require("./routes/projects/edit")(sequelize);
|
const projectsEditRoute = require("./routes/projects/edit")(sequelize);
|
||||||
const projectsDeleteRoute = require("./routes/projects/delete")(sequelize);
|
const projectsDeleteRoute = require("./routes/projects/delete")(sequelize);
|
||||||
app.use("/projects", projectsIndexRoute);
|
app.use("/projects", projectsIndexRoute);
|
||||||
|
app.use("/projects", projectsShowRoute);
|
||||||
app.use("/projects", projectsNewRoute);
|
app.use("/projects", projectsNewRoute);
|
||||||
app.use("/projects", projectsEditRoute);
|
app.use("/projects", projectsEditRoute);
|
||||||
app.use("/projects", projectsDeleteRoute);
|
app.use("/projects", projectsDeleteRoute);
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ function defineProject(sequelize, DataTypes) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Project.associate = (models) => {
|
||||||
|
Project.hasMany(models.Folder, { foreignKey: "projectId" });
|
||||||
|
};
|
||||||
|
|
||||||
return Project;
|
return Project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
38
backend/routes/projects/show.js
Normal file
38
backend/routes/projects/show.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
const express = require("express");
|
||||||
|
const router = express.Router();
|
||||||
|
const defineProject = require("../../models/projects");
|
||||||
|
const defineFolder = require("../../models/folders");
|
||||||
|
const { DataTypes } = require("sequelize");
|
||||||
|
|
||||||
|
module.exports = function (sequelize) {
|
||||||
|
const Project = defineProject(sequelize, DataTypes);
|
||||||
|
const Folder = defineFolder(sequelize, DataTypes);
|
||||||
|
Project.hasMany(Folder, { foreignKey: "projectId" });
|
||||||
|
|
||||||
|
router.get("/:projectId", async (req, res) => {
|
||||||
|
const projectId = req.params.projectId;
|
||||||
|
|
||||||
|
if (!projectId) {
|
||||||
|
return res.status(400).json({ error: "projectId is required" });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const project = await Project.findByPk(projectId, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Folder,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
if (!project) {
|
||||||
|
return res.status(404).send("Project not found");
|
||||||
|
}
|
||||||
|
res.json(project);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).send("Internal Server Error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return router;
|
||||||
|
};
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export default function Page() {
|
|
||||||
return <>This is Dashboard tab</>;
|
|
||||||
}
|
|
||||||
59
frontend/app/projects/[projectId]/home/home.tsx
Normal file
59
frontend/app/projects/[projectId]/home/home.tsx
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
"use client";
|
||||||
|
import Config from "@/config/config";
|
||||||
|
const apiServer = Config.apiServer;
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
|
async function fetchProject(url) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching data:", error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
projectId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function Home({ projectId }: Props) {
|
||||||
|
const [project, setProject] = useState({
|
||||||
|
Folders: [],
|
||||||
|
});
|
||||||
|
const url = `${apiServer}/projects/${projectId}`;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function fetchDataEffect() {
|
||||||
|
try {
|
||||||
|
const data = await fetchProject(url);
|
||||||
|
setProject(data);
|
||||||
|
console.log(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in effect:", error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchDataEffect();
|
||||||
|
}, [url]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h3 className="font-bold ms-2">Home</h3>
|
||||||
|
|
||||||
|
<h4 className="font-bold ms-2 mt-5">
|
||||||
|
Folder num: {project.Folders.length}
|
||||||
|
</h4>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
9
frontend/app/projects/[projectId]/home/page.tsx
Normal file
9
frontend/app/projects/[projectId]/home/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Home } from "./home";
|
||||||
|
|
||||||
|
export default function Page({ params }: { params: { projectId: string } }) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Home projectId={params.projectId} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { Menu, MenuItem } from "@nextui-org/react";
|
import { Menu, MenuItem } from "@nextui-org/react";
|
||||||
import { LayoutDashboard, Files, FlaskConical } from "lucide-react";
|
import { Home, Files, FlaskConical } from "lucide-react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import useGetCurrentIds from "@/utils/useGetCurrentIds";
|
import useGetCurrentIds from "@/utils/useGetCurrentIds";
|
||||||
|
|
||||||
@@ -11,11 +11,11 @@ export default function Sidebar() {
|
|||||||
<div className="w-64 border-r-1 dark:border-neutral-700">
|
<div className="w-64 border-r-1 dark:border-neutral-700">
|
||||||
<Menu aria-label="sidebar">
|
<Menu aria-label="sidebar">
|
||||||
<MenuItem
|
<MenuItem
|
||||||
startContent={<LayoutDashboard strokeWidth={1} size={28} />}
|
startContent={<Home strokeWidth={1} size={28} />}
|
||||||
className="p-3"
|
className="p-3"
|
||||||
onClick={() => router.push(`/projects/${projectId}/dashboard`)}
|
onClick={() => router.push(`/projects/${projectId}/home`)}
|
||||||
>
|
>
|
||||||
Dashboard
|
Home
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
startContent={<Files strokeWidth={1} size={28} />}
|
startContent={<Files strokeWidth={1} size={28} />}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export function ProjectCard({ project, onEditClick, onDeleteClick }) {
|
|||||||
<CardHeader className="flex gap-3 h-[50px] justify-between text-ellipsis overflow-hidden">
|
<CardHeader className="flex gap-3 h-[50px] justify-between text-ellipsis overflow-hidden">
|
||||||
<div className="flex gap-5">
|
<div className="flex gap-5">
|
||||||
<div className="flex flex-col gap-1 items-start justify-center">
|
<div className="flex flex-col gap-1 items-start justify-center">
|
||||||
<Link underline="hover" href={`/projects/${project.id}/dashboard`}>{project.name}</Link>
|
<Link underline="hover" href={`/projects/${project.id}/home`}>{project.name}</Link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Dropdown>
|
<Dropdown>
|
||||||
|
|||||||
Reference in New Issue
Block a user