From b0ab1e86ca354196358dc6b372217a81074239ee Mon Sep 17 00:00:00 2001 From: M-Gabrielly Date: Tue, 7 Oct 2025 17:23:02 -0300 Subject: [PATCH] refactor(core): Restructure the projectfor feature-sliced architecture feature-sliced - Move components, hooks, and types to their respective directories in /features. - Update all imports to reflect the new structure. - Fixes the path alias in tsconfig and removes legacy files. --- src/app/(admin)/consultas/page.tsx | 2 +- src/app/(admin)/doutores/page.tsx | 2 +- src/app/(admin)/pacientes/page.tsx | 2 +- src/app/(marketing)/sobre/page.tsx | 2 +- src/app/agenda/page.tsx | 2 +- src/app/layout.tsx | 2 +- src/app/login/page.tsx | 4 +- src/app/page.tsx | 2 +- src/components/layout/ProtectedRoute.tsx | 4 +- .../components}/AgendaCalendar.tsx | 0 .../components}/AppointmentModal.tsx | 0 .../agendamento/components}/FooterAgenda.tsx | 0 .../agendamento/components}/HeaderAgenda.tsx | 0 .../agendamento/components}/ListaEspera.tsx | 0 .../forms/calendar-registration-form.tsx | 0 .../agendamento/components}/index.ts | 0 .../agendamento/hooks/useAgenda.ts} | 0 src/features/autenticacao/api/index.ts | 8 +- .../autenticacao}/hooks/useAuth.tsx | 4 +- .../autenticacao/types/index.ts} | 0 .../marketing}/components/about-section.tsx | 0 .../marketing}/components/hero-section.tsx | 0 .../forms/patient-registration-form.tsx | 0 .../forms/doctor-registration-form.tsx | 0 src/lib/auth.ts | 2 +- src/lib/http.ts | 2 +- src/styles/globals.css | 133 ------------------ tsconfig.json | 2 +- 28 files changed, 21 insertions(+), 152 deletions(-) rename src/{components/agendamento => features/agendamento/components}/AgendaCalendar.tsx (100%) rename src/{components/agendamento => features/agendamento/components}/AppointmentModal.tsx (100%) rename src/{components/agenda => features/agendamento/components}/FooterAgenda.tsx (100%) rename src/{components/agenda => features/agendamento/components}/HeaderAgenda.tsx (100%) rename src/{components/agendamento => features/agendamento/components}/ListaEspera.tsx (100%) rename src/{ => features/agendamento}/components/forms/calendar-registration-form.tsx (100%) rename src/{components/agendamento => features/agendamento/components}/index.ts (100%) rename src/{hooks/UseAgenda.ts => features/agendamento/hooks/useAgenda.ts} (100%) rename src/{ => features/autenticacao}/hooks/useAuth.tsx (98%) rename src/{types/auth.ts => features/autenticacao/types/index.ts} (100%) rename src/{ => features/marketing}/components/about-section.tsx (100%) rename src/{ => features/marketing}/components/hero-section.tsx (100%) rename src/{ => features/pacientes}/components/forms/patient-registration-form.tsx (100%) rename src/{ => features/profissionais}/components/forms/doctor-registration-form.tsx (100%) delete mode 100644 src/styles/globals.css diff --git a/src/app/(admin)/consultas/page.tsx b/src/app/(admin)/consultas/page.tsx index 47365d8..5c7ed77 100644 --- a/src/app/(admin)/consultas/page.tsx +++ b/src/app/(admin)/consultas/page.tsx @@ -54,7 +54,7 @@ import { } from "@/components/ui/select"; import { mockAppointments, mockProfessionals } from "@/lib/mocks/appointment-mocks"; -import { CalendarRegistrationForm } from "@/components/forms/calendar-registration-form"; +import { CalendarRegistrationForm } from "@/features/agendamento/components/forms/calendar-registration-form"; const formatDate = (date: string | Date) => { diff --git a/src/app/(admin)/doutores/page.tsx b/src/app/(admin)/doutores/page.tsx index 64fcf5e..cf676d0 100644 --- a/src/app/(admin)/doutores/page.tsx +++ b/src/app/(admin)/doutores/page.tsx @@ -9,7 +9,7 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, Di import { Label } from "@/components/ui/label"; import { MoreHorizontal, Plus, Search, Edit, Trash2, ArrowLeft, Eye } from "lucide-react"; import { Badge } from "@/components/ui/badge"; -import { DoctorRegistrationForm } from "@/components/forms/doctor-registration-form"; +import { DoctorRegistrationForm } from "@/features/profissionais/components/forms/doctor-registration-form"; import { listarMedicos, excluirMedico, buscarMedicos, buscarMedicoPorId, Medico } from "@/lib/api"; diff --git a/src/app/(admin)/pacientes/page.tsx b/src/app/(admin)/pacientes/page.tsx index 6b8193a..c0887ec 100644 --- a/src/app/(admin)/pacientes/page.tsx +++ b/src/app/(admin)/pacientes/page.tsx @@ -11,7 +11,7 @@ import { Label } from "@/components/ui/label"; import { MoreHorizontal, Plus, Search, Eye, Edit, Trash2, ArrowLeft } from "lucide-react"; import { Paciente, Endereco, listarPacientes, buscarPacientes, buscarPacientePorId, excluirPaciente } from "@/lib/api"; -import { PatientRegistrationForm } from "@/components/forms/patient-registration-form"; +import { PatientRegistrationForm } from "@/features/pacientes/components/forms/patient-registration-form"; function normalizePaciente(p: any): Paciente { diff --git a/src/app/(marketing)/sobre/page.tsx b/src/app/(marketing)/sobre/page.tsx index e163efa..644744e 100644 --- a/src/app/(marketing)/sobre/page.tsx +++ b/src/app/(marketing)/sobre/page.tsx @@ -1,5 +1,5 @@ import { Header } from "@/components/layout/marketing/Header" -import { AboutSection } from "@/components/about-section" +import { AboutSection } from "@/features/marketing/components/about-section" import { Footer } from "@/components/layout/marketing/Footer" export default function AboutPage() { diff --git a/src/app/agenda/page.tsx b/src/app/agenda/page.tsx index ac75b0c..f91a561 100644 --- a/src/app/agenda/page.tsx +++ b/src/app/agenda/page.tsx @@ -1,7 +1,7 @@ "use client"; import { useRouter } from "next/navigation"; -import { CalendarRegistrationForm } from "@/components/forms/calendar-registration-form"; +import { CalendarRegistrationForm } from "@/features/agendamento/components/forms/calendar-registration-form"; import HeaderAgenda from "@/components/agenda/HeaderAgenda"; import FooterAgenda from "@/components/agenda/FooterAgenda"; import { useState } from "react"; diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 4a5ba4d..a0e37ba 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,6 +1,6 @@ import type React from "react" import type { Metadata } from "next" -import { AuthProvider } from "@/hooks/useAuth" +import { AuthProvider } from "@/features/autenticacao/hooks/useAuth" import { ThemeProvider } from "@/components/layout/ThemeProvider" import "./globals.css" diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 73a2cd2..33a56da 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -3,13 +3,13 @@ import { useEffect, useMemo, useState, type ChangeEvent, type FormEvent } from 'react' import Link from 'next/link' import { useRouter, useSearchParams } from 'next/navigation' -import { useAuth } from '@/hooks/useAuth' +import { useAuth } from '@/features/autenticacao/hooks/useAuth' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Alert, AlertDescription } from '@/components/ui/alert' import { AuthenticationError } from '@/lib/auth' -import { AUTH_STORAGE_KEYS } from '@/types/auth' +import { AUTH_STORAGE_KEYS } from '@/features/autenticacao/types' type UserRole = 'profissional' | 'paciente' | 'administrador' diff --git a/src/app/page.tsx b/src/app/page.tsx index ca74853..049f2ef 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,5 +1,5 @@ import { Header } from "@/components/layout/marketing/Header" -import { HeroSection } from "@/components/hero-section" +import { HeroSection } from "@/features/marketing/components/hero-section" import { Footer } from "@/components/layout/marketing/Footer" export default function HomePage() { diff --git a/src/components/layout/ProtectedRoute.tsx b/src/components/layout/ProtectedRoute.tsx index ee49112..4d444ad 100644 --- a/src/components/layout/ProtectedRoute.tsx +++ b/src/components/layout/ProtectedRoute.tsx @@ -2,8 +2,8 @@ import { useEffect, useRef } from 'react' import { useRouter } from 'next/navigation' import { useAuth } from '@/hooks/useAuth' -import type { UserType } from '@/types/auth' -import { USER_TYPE_ROUTES, LOGIN_ROUTES, AUTH_STORAGE_KEYS } from '@/types/auth' +import type { UserType } from '@/features/autenticacao/types' +import { USER_TYPE_ROUTES, LOGIN_ROUTES, AUTH_STORAGE_KEYS } from '@/features/autenticacao/types' interface ProtectedRouteProps { children: React.ReactNode diff --git a/src/components/agendamento/AgendaCalendar.tsx b/src/features/agendamento/components/AgendaCalendar.tsx similarity index 100% rename from src/components/agendamento/AgendaCalendar.tsx rename to src/features/agendamento/components/AgendaCalendar.tsx diff --git a/src/components/agendamento/AppointmentModal.tsx b/src/features/agendamento/components/AppointmentModal.tsx similarity index 100% rename from src/components/agendamento/AppointmentModal.tsx rename to src/features/agendamento/components/AppointmentModal.tsx diff --git a/src/components/agenda/FooterAgenda.tsx b/src/features/agendamento/components/FooterAgenda.tsx similarity index 100% rename from src/components/agenda/FooterAgenda.tsx rename to src/features/agendamento/components/FooterAgenda.tsx diff --git a/src/components/agenda/HeaderAgenda.tsx b/src/features/agendamento/components/HeaderAgenda.tsx similarity index 100% rename from src/components/agenda/HeaderAgenda.tsx rename to src/features/agendamento/components/HeaderAgenda.tsx diff --git a/src/components/agendamento/ListaEspera.tsx b/src/features/agendamento/components/ListaEspera.tsx similarity index 100% rename from src/components/agendamento/ListaEspera.tsx rename to src/features/agendamento/components/ListaEspera.tsx diff --git a/src/components/forms/calendar-registration-form.tsx b/src/features/agendamento/components/forms/calendar-registration-form.tsx similarity index 100% rename from src/components/forms/calendar-registration-form.tsx rename to src/features/agendamento/components/forms/calendar-registration-form.tsx diff --git a/src/components/agendamento/index.ts b/src/features/agendamento/components/index.ts similarity index 100% rename from src/components/agendamento/index.ts rename to src/features/agendamento/components/index.ts diff --git a/src/hooks/UseAgenda.ts b/src/features/agendamento/hooks/useAgenda.ts similarity index 100% rename from src/hooks/UseAgenda.ts rename to src/features/agendamento/hooks/useAgenda.ts diff --git a/src/features/autenticacao/api/index.ts b/src/features/autenticacao/api/index.ts index 5a21703..2f49d4c 100644 --- a/src/features/autenticacao/api/index.ts +++ b/src/features/autenticacao/api/index.ts @@ -1,6 +1,7 @@ import httpClient from "@/lib/http"; import { API_KEY } from "@/lib/config"; // Necessário para algumas chamadas de auth -import { AUTH_ENDPOINTS } from "@/lib/env-config"; // Endpoints de autenticação +import { ENV_CONFIG } from "@/lib/env-config"; // Configuração de ambiente completa +import { API_KEY } from "@/lib/config"; // Necessário para algumas chamadas de auth // ===== TIPOS DE AUTENTICAÇÃO E PERFIL ===== export type Profile = { @@ -11,9 +12,10 @@ export type Profile = { }; export type CreateUserWithPasswordResponse = { - user_id: string; + success: boolean; + user: any; // Objeto do usuário retornado pelo Supabase email: string; - password?: string; // A senha só é retornada na criação + password?: string; }; export type UserData = { diff --git a/src/hooks/useAuth.tsx b/src/features/autenticacao/hooks/useAuth.tsx similarity index 98% rename from src/hooks/useAuth.tsx rename to src/features/autenticacao/hooks/useAuth.tsx index 92150e5..940bf3d 100644 --- a/src/hooks/useAuth.tsx +++ b/src/features/autenticacao/hooks/useAuth.tsx @@ -9,8 +9,8 @@ import type { UserData, AuthStatus, UserType -} from '@/types/auth' -import { AUTH_STORAGE_KEYS, LOGIN_ROUTES } from '@/types/auth' +} from '@/features/autenticacao/types' +import { AUTH_STORAGE_KEYS, LOGIN_ROUTES } from '@/features/autenticacao/types' const AuthContext = createContext(undefined) diff --git a/src/types/auth.ts b/src/features/autenticacao/types/index.ts similarity index 100% rename from src/types/auth.ts rename to src/features/autenticacao/types/index.ts diff --git a/src/components/about-section.tsx b/src/features/marketing/components/about-section.tsx similarity index 100% rename from src/components/about-section.tsx rename to src/features/marketing/components/about-section.tsx diff --git a/src/components/hero-section.tsx b/src/features/marketing/components/hero-section.tsx similarity index 100% rename from src/components/hero-section.tsx rename to src/features/marketing/components/hero-section.tsx diff --git a/src/components/forms/patient-registration-form.tsx b/src/features/pacientes/components/forms/patient-registration-form.tsx similarity index 100% rename from src/components/forms/patient-registration-form.tsx rename to src/features/pacientes/components/forms/patient-registration-form.tsx diff --git a/src/components/forms/doctor-registration-form.tsx b/src/features/profissionais/components/forms/doctor-registration-form.tsx similarity index 100% rename from src/components/forms/doctor-registration-form.tsx rename to src/features/profissionais/components/forms/doctor-registration-form.tsx diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 1e0ea62..9809742 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -4,7 +4,7 @@ import type { RefreshTokenResponse, AuthError, UserData -} from '@/types/auth'; +} from '@/features/autenticacao/types'; import { API_CONFIG, AUTH_ENDPOINTS, DEFAULT_HEADERS, API_KEY, buildApiUrl } from '@/lib/config'; import { debugRequest } from '@/lib/debug-utils'; diff --git a/src/lib/http.ts b/src/lib/http.ts index f5abef2..ac5ffcf 100644 --- a/src/lib/http.ts +++ b/src/lib/http.ts @@ -3,7 +3,7 @@ * Implementa lock para evitar múltiplas chamadas de refresh simultaneamente */ -import { AUTH_STORAGE_KEYS, LOGIN_ROUTES, type UserType } from '@/types/auth' +import { AUTH_STORAGE_KEYS, LOGIN_ROUTES, type UserType } from '@/features/autenticacao/types' import { isExpired } from '@/lib/jwt' import { API_KEY } from '@/lib/config' diff --git a/src/styles/globals.css b/src/styles/globals.css deleted file mode 100644 index f52d561..0000000 --- a/src/styles/globals.css +++ /dev/null @@ -1,133 +0,0 @@ -@import 'tailwindcss'; -@import 'tw-animate-css'; - - -:root { - --background: var(--primary) - --background: oklch(1 0 0); - --foreground: oklch(0.145 0 0); - --card: oklch(1 0 0); - --card-foreground: oklch(0.145 0 0); - --popover: oklch(1 0 0); - --popover-foreground: oklch(0.145 0 0); - --primary: oklch(0.205 0 0); - --primary-foreground: oklch(0.985 0 0); - --secondary: oklch(0.97 0 0); - --secondary-foreground: oklch(0.205 0 0); - --muted: oklch(0.97 0 0); - --muted-foreground: oklch(0.556 0 0); - --accent: oklch(0.97 0 0); - --accent-foreground: oklch(0.205 0 0); - --destructive: oklch(0.577 0.245 27.325); - --destructive-foreground: oklch(0.577 0.245 27.325); - --border: oklch(0.922 0 0); - --input: oklch(0.922 0 0); - --ring: oklch(0.708 0 0); - --chart-1: oklch(0.646 0.222 41.116); - --chart-2: oklch(0.6 0.118 184.704); - --chart-3: oklch(0.398 0.07 227.392); - --chart-4: oklch(0.828 0.189 84.429); - --chart-5: oklch(0.769 0.188 70.08); - --radius: 0.625rem; - --sidebar: oklch(0.985 0 0); - --sidebar-foreground: oklch(0.145 0 0); - --sidebar-primary: oklch(0.205 0 0); - --sidebar-primary-foreground: oklch(0.985 0 0); - --sidebar-accent: oklch(0.97 0 0); - --sidebar-accent-foreground: oklch(0.205 0 0); - --sidebar-border: oklch(0.922 0 0); - --sidebar-ring: oklch(0.708 0 0); -} - -.dark { - --background: oklch(0.145 0 0); - --foreground: oklch(0.985 0 0); - --card: oklch(0.145 0 0); - --card-foreground: oklch(0.985 0 0); - --popover: oklch(0.145 0 0); - --popover-foreground: oklch(0.985 0 0); - --primary: oklch(0.985 0 0); - --primary-foreground: oklch(0.205 0 0); - --secondary: oklch(0.269 0 0); - --secondary-foreground: oklch(0.985 0 0); - --muted: oklch(0.269 0 0); - --muted-foreground: oklch(0.708 0 0); - --accent: oklch(0.269 0 0); - --accent-foreground: oklch(0.985 0 0); - --destructive: oklch(0.396 0.141 25.723); - --destructive-foreground: oklch(0.637 0.237 25.331); - --border: oklch(0.269 0 0); - --input: oklch(0.269 0 0); - --ring: oklch(0.439 0 0); - --chart-1: oklch(0.488 0.243 264.376); - --chart-2: oklch(0.696 0.17 162.48); - --chart-3: oklch(0.769 0.188 70.08); - --chart-4: oklch(0.627 0.265 303.9); - --chart-5: oklch(0.645 0.246 16.439); - --sidebar: oklch(0.205 0 0); - --sidebar-foreground: oklch(0.985 0 0); - --sidebar-primary: oklch(0.488 0.243 264.376); - --sidebar-primary-foreground: oklch(0.985 0 0); - --sidebar-accent: oklch(0.269 0 0); - --sidebar-accent-foreground: oklch(0.985 0 0); - --sidebar-border: oklch(0.269 0 0); - --sidebar-ring: oklch(0.439 0 0); -} - -:root { - --font-sans: var(--font-geist-sans); - --font-mono: var(--font-geist-mono); - --color-background: var(--background); - --color-foreground: var(--foreground); - --color-card: var(--card); - --color-card-foreground: var(--card-foreground); - --color-popover: var(--popover); - --color-popover-foreground: var(--popover-foreground); - --color-primary: var(--primary); - --color-primary-foreground: var(--primary-foreground); - --color-secondary: var(--secondary); - --color-secondary-foreground: var(--secondary-foreground); - --color-muted: var(--muted); - --color-muted-foreground: var(--muted-foreground); - --color-accent: var(--accent); - --color-accent-foreground: var(--accent-foreground); - --color-destructive: var(--destructive); - --color-destructive-foreground: var(--destructive-foreground); - --color-border: var(--border); - --color-input: var(--input); - --color-ring: var(--ring); - --color-chart-1: var(--chart-1); - --color-chart-2: var(--chart-2); - --color-chart-3: var(--chart-3); - --color-chart-4: var(--chart-4); - --color-chart-5: var(--chart-5); - --radius-sm: calc(var(--radius) - 4px); - --radius-md: calc(var(--radius) - 2px); - --radius-lg: var(--radius); - --radius-xl: calc(var(--radius) + 4px); - --color-sidebar: var(--sidebar); - --color-sidebar-foreground: var(--sidebar-foreground); - --color-sidebar-primary: var(--sidebar-primary); - --color-sidebar-primary-foreground: var(--sidebar-primary-foreground); - --color-sidebar-accent: var(--sidebar-accent); - --color-sidebar-accent-foreground: var(--sidebar-accent-foreground); - --color-sidebar-border: var(--sidebar-border); - --color-sidebar-ring: var(--sidebar-ring); -} - -@layer base { - * { - border-color: var(--border); - outline-color: var(--ring); - outline-width: 2px; - outline-style: solid; - outline-offset: 0.5px; - } - body { - background-color: var(--background); - color: var(--foreground); - } -} -.buttonText { - background-color: var(--primary); -} diff --git a/tsconfig.json b/tsconfig.json index 0180210..65534f5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,7 @@ } ], "paths": { - "@/*": ["./*"] + "@/*": ["./src/*"] } }, "include": [