Add Next.js frontend PWA

- Pages: login, register, tasks list, task detail
- Components: TaskCard, TaskForm, GroupSelector, StatusBadge, Header
- Tailwind CSS, dark/light mode, PWA manifest
- Running on :3001 via systemd

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude CLI Agent
2026-03-29 10:02:32 +00:00
parent 9d075455e3
commit b5a6dd6d6f
29 changed files with 7541 additions and 0 deletions

145
apps/tasks/lib/api.ts Normal file
View File

@@ -0,0 +1,145 @@
const API_BASE = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000";
interface ApiOptions {
method?: string;
body?: unknown;
token?: string;
}
async function apiFetch<T>(path: string, opts: ApiOptions = {}): Promise<T> {
const headers: Record<string, string> = {
"Content-Type": "application/json",
};
if (opts.token) {
headers["Authorization"] = `Bearer ${opts.token}`;
}
const res = await fetch(`${API_BASE}${path}`, {
method: opts.method || "GET",
headers,
body: opts.body ? JSON.stringify(opts.body) : undefined,
});
if (!res.ok) {
const err = await res.json().catch(() => ({ message: res.statusText }));
throw new Error(err.message || `HTTP ${res.status}`);
}
return res.json();
}
// Auth
export function register(data: { email: string; name: string; phone?: string }) {
return apiFetch<{ token: string; user: User }>("/api/v1/auth/register", {
method: "POST",
body: data,
});
}
export function login(data: { email: string; password?: string }) {
return apiFetch<{ token: string; user: User }>("/api/v1/auth/login", {
method: "POST",
body: data,
});
}
export function getMe(token: string) {
return apiFetch<{ user: User }>("/api/v1/auth/me", { token });
}
// Tasks
export function getTasks(token: string, params?: Record<string, string>) {
const qs = params ? "?" + new URLSearchParams(params).toString() : "";
return apiFetch<{ data: Task[]; total: number }>(`/api/v1/tasks${qs}`, { token });
}
export function getTask(token: string, id: string) {
return apiFetch<Task>(`/api/v1/tasks/${id}`, { token });
}
export function createTask(token: string, data: Partial<Task>) {
return apiFetch<Task>("/api/v1/tasks", { method: "POST", body: data, token });
}
export function updateTask(token: string, id: string, data: Partial<Task>) {
return apiFetch<Task>(`/api/v1/tasks/${id}`, { method: "PUT", body: data, token });
}
export function deleteTask(token: string, id: string) {
return apiFetch<void>(`/api/v1/tasks/${id}`, { method: "DELETE", token });
}
// Groups
export function getGroups(token: string) {
return apiFetch<{ data: Group[] }>("/api/v1/groups", { token });
}
export function createGroup(token: string, data: Partial<Group>) {
return apiFetch<Group>("/api/v1/groups", { method: "POST", body: data, token });
}
export function updateGroup(token: string, id: string, data: Partial<Group>) {
return apiFetch<Group>(`/api/v1/groups/${id}`, { method: "PUT", body: data, token });
}
export function deleteGroup(token: string, id: string) {
return apiFetch<void>(`/api/v1/groups/${id}`, { method: "DELETE", token });
}
export function reorderGroups(token: string, ids: string[]) {
return apiFetch<void>("/api/v1/groups/reorder", { method: "PUT", body: { ids }, token });
}
// Connectors
export function getConnectors(token: string) {
return apiFetch<{ data: Connector[] }>("/api/v1/connectors", { token });
}
export function createConnector(token: string, data: Partial<Connector>) {
return apiFetch<Connector>("/api/v1/connectors", { method: "POST", body: data, token });
}
// Types
export interface User {
id: string;
email: string;
name: string;
phone?: string;
}
export interface Task {
id: string;
user_id: string | null;
group_id: string | null;
title: string;
description: string;
status: "pending" | "in_progress" | "done" | "cancelled";
priority: "low" | "medium" | "high" | "urgent";
scheduled_at: string | null;
due_at: string | null;
completed_at: string | null;
assigned_to: string[];
attachments: string[];
external_id: string | null;
external_source: string | null;
created_at: string;
updated_at: string;
group_name: string | null;
group_color: string | null;
group_icon: string | null;
}
export interface Group {
id: string;
name: string;
color: string;
icon: string | null;
sort_order: number;
}
export interface Connector {
id: string;
name: string;
type: string;
config: Record<string, unknown>;
}

56
apps/tasks/lib/auth.ts Normal file
View File

@@ -0,0 +1,56 @@
"use client";
import { createContext, useContext } from "react";
import { User } from "./api";
export interface AuthState {
token: string | null;
user: User | null;
setAuth: (token: string | null, user: User | null) => void;
logout: () => void;
}
export const AuthContext = createContext<AuthState>({
token: null,
user: null,
setAuth: () => {},
logout: () => {},
});
export function useAuth() {
return useContext(AuthContext);
}
export function getStoredToken(): string | null {
if (typeof window === "undefined") return null;
return localStorage.getItem("taskteam_token");
}
export function setStoredToken(token: string | null) {
if (typeof window === "undefined") return;
if (token) {
localStorage.setItem("taskteam_token", token);
} else {
localStorage.removeItem("taskteam_token");
}
}
export function getStoredUser(): User | null {
if (typeof window === "undefined") return null;
const raw = localStorage.getItem("taskteam_user");
if (!raw) return null;
try {
return JSON.parse(raw);
} catch {
return null;
}
}
export function setStoredUser(user: User | null) {
if (typeof window === "undefined") return;
if (user) {
localStorage.setItem("taskteam_user", JSON.stringify(user));
} else {
localStorage.removeItem("taskteam_user");
}
}