- Introduction
- Technology Stack
- Project Structure
- Screen Implementations
- Next.js App Router and Server Components
- Client Components
- Authentication
- State Management
- API Integration
- Styling
- Performance Optimization
- Testing
- Deployment
- Setup and Installation
- Conclusion
This documentation outlines the frontend implementation of the Task Management Web Application. Built with Next.js 13+ and integrated with Auth.js for authentication, this frontend provides a responsive, efficient, and user-friendly interface for managing tasks. It leverages the new App Router and Server Components for improved performance and developer experience.
- Framework: Next.js 13+ (React)
- Authentication: Auth.js (formerly NextAuth.js)
- State Management: React Context API and Hooks
- Styling: Tailwind CSS
- HTTP Client: Native fetch API
- Form Handling: React Hook Form
- Testing: Jest and React Testing Library
src/
├── app/
│ ├── layout.tsx
│ ├── page.tsx
│ ├── tasks/
│ │ ├── page.tsx
│ │ └── [id]/
│ │ └── page.tsx
│ └── api/
│ └── auth/
│ └── [...nextauth]/
│ └── route.ts
├── components/
│ ├── layout/
│ │ ├── Header.tsx
│ │ └── Footer.tsx
│ ├── tasks/
│ │ ├── TaskList.tsx
│ │ ├── TaskItem.tsx
│ │ └── TaskForm.tsx
│ └── common/
│ ├── Button.tsx
│ └── Input.tsx
├── lib/
│ ├── api.ts
│ └── auth.ts
├── types/
│ └── task.ts
├── utils/
│ └── dateFormatter.ts
├── public/
│ └── mocks/
│ ├── home.png
│ ├── task-list.png
│ └── task-detail.png
└── tests/
├── components/
└── app/
We leverage Next.js 13+'s new App Router and Server Components for improved performance and developer experience. Here's an example of a Server Component:
import React from 'react';
import AuthForm from './auth-form';
export default function AuthPage() {
return (
<div className="min-h-screen bg-gradient-to-br from-orange-100 to-yellow-100 flex items-center justify-center px-4">
<div className="max-w-md w-full space-y-8 bg-white p-10 rounded-xl shadow-lg">
<div className="text-center">
<h2 className="mt-6 text-3xl font-extrabold text-gray-900">Welcome to ErgonFlow</h2>
<p className="mt-2 text-sm text-gray-600">Sign in to manage your tasks efficiently</p>
</div>
<AuthForm />
</div>
</div>
);
}
This Server Component fetches tasks on the server, reducing the amount of JavaScript sent to the client and improving initial page load times.
For interactive elements, we use Client Components. Here's an example:
// components/tasks/TaskForm.tsx
// app/components/TaskForm.tsx
'use client';
import React, { useState } from 'react';
import { TaskPriority } from '@/app/lib/definitions/TaskEnum';
import { Category } from '@/app/lib/definitions/Task';
interface TaskFormProps {
onCreateTask: (task: {
title: string;
description: string;
priority: TaskPriority;
dueDate: string;
category: Category;
}) => void;
}
export default function TaskForm({ onCreateTask }: TaskFormProps) {
const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
const [priority, setPriority] = useState<TaskPriority>(TaskPriority.MEDIUM);
const [dueDate, setDueDate] = useState('');
const [category, setCategory] = useState('');
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
onCreateTask({
title,
description,
priority,
dueDate,
category: new Category(category),
});
// Reset form
setTitle('');
setDescription('');
setPriority(TaskPriority.MEDIUM);
setDueDate('');
setCategory('');
};
return (
<form onSubmit={handleSubmit} className="bg-white shadow-md rounded-lg px-8 pt-6 pb-8 mb-4">
<h2 className="text-2xl font-semibold mb-4 text-gray-800">Create New Task</h2>
{['title', 'description', 'priority', 'dueDate', 'category'].map((field) => (
<div key={field} className="mb-4">
<label className="block text-gray-700 text-sm font-bold mb-2" htmlFor={field}>
{field.charAt(0).toUpperCase() + field.slice(1)}
</label>
{field === 'description' ? (
<textarea
className="shadow-sm appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:ring-2 focus:ring-orange-500"
id={field}
value={eval(field)}
onChange={(e) => eval(`set${field.charAt(0).toUpperCase() + field.slice(1)}`)(e.target.value)}
required
/>
) : field === 'priority' ? (
<select
className="shadow-sm appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:ring-2 focus:ring-orange-500"
id={field}
value={priority}
onChange={(e) => setPriority(e.target.value as TaskPriority)}
>
{Object.values(TaskPriority).map((p) => (
<option key={p} value={p}>{p}</option>
))}
</select>
) : (
<input
className="shadow-sm appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:ring-2 focus:ring-orange-500"
id={field}
type={field === 'dueDate' ? 'date' : 'text'}
value={eval(field)}
onChange={(e) => eval(`set${field.charAt(0).toUpperCase() + field.slice(1)}`)(e.target.value)}
required
/>
)}
</div>
))}
<div className="flex items-center justify-between">
<button
className="bg-orange-500 hover:bg-orange-600 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline transition-colors"
type="submit"
>
Create Task
</button>
</div>
</form>
);
}
This Client Component handles user input and updates the UI accordingly.
We use Auth.js for handling authentication. Here's a basic setup:
We use React Context API for global state management. Here's an example of a TaskContext:
/
We use the native fetch API for data fetching. Here's an example:
// lib/api.ts
We use Tailwind CSS for styling. Here's an example of how we apply styles:
// components/common/Button.tsx
- We use Next.js Server Components for improved initial page load times
- Implement code splitting using dynamic imports for Client Components
- Use React.memo for preventing unnecessary re-renders of components
- Implement image optimization using Next.js Image component
We use Jest and React Testing Library for unit and integration tests. Here's an example test:
We use Vercel for deploying our Next.js application. The deployment process is as follows:
- Push your code to a GitHub repository
- Connect your Vercel account to your GitHub account
- Import the project into Vercel
- Configure your environment variables
- Deploy
Vercel will automatically deploy your application on every push to the main branch.
[This section remains unchanged from the previous version]
This frontend implementation for the Task Management Application leverages the latest features of Next.js 13+ to create a responsive, efficient, and user-friendly interface. Key highlights include:
- Next.js App Router: Utilizing the new file-based routing system for improved performance and developer experience.
- Server Components: Leveraging server-side rendering for faster initial page loads and improved SEO.
- Client Components: Using client-side interactivity where needed for a dynamic user experience.
- Authentication: Implementing secure user authentication with Auth.js.
- Responsive Design: Ensuring a great user experience across devices with Tailwind CSS.
- State Management: Using React Context for efficient state management without the complexity of additional libraries.
- API Integration: Implementing efficient data fetching with the native fetch API.
- Performance Optimization: Applying various techniques to ensure the application runs smoothly.
- Testing: Ensuring reliability with comprehensive unit and integration tests.
- Screen Mocks: Guiding development with clear visual references.
This implementation provides a solid foundation for the Task Management Application, taking full advantage of modern Next.js features while maintaining flexibility for future enhancements.