Create a Next.js page for src/pages/project/tasks.tsx. Here are the instructions:
Issue: Create a Next.js React page for Project Tasks (tasks.tsx)
Objective
Create a Next.js React page tasks.tsx that displays the project tasks for the user. This page will be a Next.js page written in TypeScript as a functional component using ES6 syntax like arrow functions. The page should fetch data from the database via API endpoints built using Prisma, and use NextAuth for authentication. The styling should be done using Tailwind CSS, and fetched data should be used in compliance with the provided TypeScript interfaces.
Requirements
Create a new file tasks.tsx in the src/pages/project directory.
Import the necessary dependencies:
import { useSession } from "next-auth/react";
import { ProjectTask } from "~/types";
import TaskItem from "~/components/TaskItem";
Any other necessary imports for React, Next.js, or API calls.
Define a Props interface for the Tasks component that includes the following properties:
projectId: string;
Create a functional component Tasks that accepts the Props interface as its props.
Inside the Tasks component, use the useSession hook to get the user's session.
Fetch the project tasks data from the API endpoint (assume that the necessary API endpoint is already created). Use the projectId prop to fetch the tasks for the specific project.
Use the fetched data in compliance with the ProjectTask TypeScript interface.
Render the project tasks page as follows:
Display a heading "Project Tasks" at the top of the page.
Create a subheading that shows the project name.
Create a paragraph that explains the purpose of the page: "This page displays the list of tasks for the selected project. You can review, edit, approve, or reject each task."
Map over the fetched project tasks and render a TaskItem component for each task. Pass the necessary data from the ProjectTask interface to the TaskItem component.
The TaskItem component should display the task name, task description, approval status, and a button to approve or reject the task. When the approve/reject button is clicked, it should update the task's approval status in the database and re-render the updated task list.
Handle any potential error cases, such as failed API calls or missing data, by displaying an appropriate error message to the user.
Ensure that the created React component matches the given page description and properly manages the state and lifecycle, renders correctly, and supports necessary user interactions.
Please follow the above instructions step-by-step to create the tasks.tsx page. If you have any questions or need clarification, feel free to ask.
Create a Next.js page for src/pages/project/tasks.tsx. Here are the instructions:
Issue: Create a Next.js React page for Project Tasks (tasks.tsx)
Objective
Create a Next.js React page
tasks.tsx
that displays the project tasks for the user. This page will be a Next.js page written in TypeScript as a functional component using ES6 syntax like arrow functions. The page should fetch data from the database via API endpoints built using Prisma, and use NextAuth for authentication. The styling should be done using Tailwind CSS, and fetched data should be used in compliance with the provided TypeScript interfaces.Requirements
tasks.tsx
in thesrc/pages/project
directory.import { useSession } from "next-auth/react";
import { ProjectTask } from "~/types";
import TaskItem from "~/components/TaskItem";
Props
interface for theTasks
component that includes the following properties:projectId: string;
Tasks
that accepts theProps
interface as its props.Tasks
component, use theuseSession
hook to get the user's session.projectId
prop to fetch the tasks for the specific project.ProjectTask
TypeScript interface.TaskItem
component for each task. Pass the necessary data from theProjectTask
interface to theTaskItem
component.TaskItem
component should display the task name, task description, approval status, and a button to approve or reject the task. When the approve/reject button is clicked, it should update the task's approval status in the database and re-render the updated task list.Please follow the above instructions step-by-step to create the
tasks.tsx
page. If you have any questions or need clarification, feel free to ask.