refactor: centralize route configuration

This commit is contained in:
Your Name
2026-04-11 13:45:49 +05:30
parent a3d727d0c9
commit ddbf2bc4d1
9 changed files with 119 additions and 86 deletions
+12 -9
View File
@@ -1,8 +1,10 @@
import { useEffect } from "react"; import { useEffect } from "react";
import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom"; import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom";
import Logo from "./components/Logo"; import Logo from "./components/Logo";
import { ROUTES } from "./config/routes";
import Activate from "./pages/Activate"; import Activate from "./pages/Activate";
import Drawer from "./pages/Drawer"; import Drawer from "./pages/Drawer";
import Editor from "./pages/Editor";
import Home from "./pages/Home"; import Home from "./pages/Home";
import Login from "./pages/Login"; import Login from "./pages/Login";
import Register from "./pages/Register"; import Register from "./pages/Register";
@@ -30,17 +32,18 @@ export default function App() {
return ( return (
<BrowserRouter> <BrowserRouter>
<div className="min-h-screen bg-base-200 p-8 flex items-center justify-center"> <main className="min-h-screen bg-base-200 flex items-center justify-center w-full">
<Routes> <Routes>
<Route path="/" element={<Home />} /> <Route path={ROUTES.HOME} element={<Home />} />
<Route path="/onboard" element={<Register />} /> <Route path={ROUTES.ONBOARD} element={<Register />} />
<Route path="/verify-email" element={<VerifyEmail />} /> <Route path={ROUTES.VERIFY_EMAIL} element={<VerifyEmail />} />
<Route path="/activate/:uidb64/:token" element={<Activate />} /> <Route path={ROUTES.ACTIVATE} element={<Activate />} />
<Route path="/login" element={<Login />} /> <Route path={ROUTES.LOGIN} element={<Login />} />
<Route path="/drawer" element={<Drawer />} /> <Route path={ROUTES.DRAWER} element={<Drawer />} />
<Route path="*" element={<Navigate to="/" replace />} /> <Route path={ROUTES.WRITE} element={<Editor />} />
<Route path="*" element={<Navigate to={ROUTES.HOME} replace />} />
</Routes> </Routes>
</div> </main>
</BrowserRouter> </BrowserRouter>
); );
} }
+2
View File
@@ -4,6 +4,8 @@ import "@fontsource/knewave/400.css";
export default function Logo() { export default function Logo() {
return ( return (
<span <span
role="img"
aria-label="Pi Ku"
className="inline-flex items-baseline justify-center leading-none select-none" className="inline-flex items-baseline justify-center leading-none select-none"
style={{ fontFamily: "'Knewave', serif" }} style={{ fontFamily: "'Knewave', serif" }}
> >
@@ -0,0 +1,28 @@
interface DateDisplayProps {
date?: Date;
className?: string;
}
export default function DateDisplay({
date = new Date(),
className = "",
}: DateDisplayProps) {
const formattedDate = date.toLocaleDateString("en-US", {
month: "long",
day: "numeric",
year: "numeric",
});
return (
<div
className={`text-right flex flex-col gap-2 min-w-[140px] ${className}`}
>
<span className="text-[10px] uppercase tracking-[0.4em] text-accent font-bold">
Date
</span>
<span className="text-sm font-serif text-secondary-content italic whitespace-nowrap">
{formattedDate}
</span>
</div>
);
}
+3 -2
View File
@@ -19,19 +19,20 @@ export default function FormField({
<div className="form-control"> <div className="form-control">
<label <label
htmlFor={registration.name} htmlFor={registration.name}
className="field-label font-display text-primary-content" className="field-label font-display text-base-content/90 font-medium"
> >
{label} {label}
</label> </label>
<input <input
{...registration} {...registration}
id={registration.name}
type={type} type={type}
placeholder={placeholder} placeholder={placeholder}
className={`input input-bordered focus:input-primary ${ className={`input input-bordered focus:input-primary ${
error ? "input-error" : "" error ? "input-error" : ""
}`} }`}
/> />
{error && <p className="text-error-content">{error}</p>} {error && <p className="text-error">{error}</p>}
</div> </div>
); );
} }
+10
View File
@@ -0,0 +1,10 @@
export const ROUTES = {
HOME: "/",
ONBOARD: "/onboard",
VERIFY_EMAIL: "/verify-email",
ACTIVATE: "/activate/:uidb64/:token",
LOGIN: "/login",
DRAWER: "/drawer",
WRITE: "/quill",
READ: "/read",
};
+2 -8
View File
@@ -70,15 +70,9 @@ export default function Activate() {
{status === "error" && ( {status === "error" && (
<div className="flex flex-col items-center gap-6 animate-in fade-in zoom-in duration-500"> <div className="flex flex-col items-center gap-6 animate-in fade-in zoom-in duration-500">
<div className="bg-error/10 p-4 rounded-full"> <div className="bg-error/10 p-4 rounded-full">
<XCircleIcon <XCircleIcon size={64} weight="duotone" className="text-error" />
size={64}
weight="duotone"
className="text-error-content"
/>
</div> </div>
<h2 className="font-display text-xl text-error-content"> <h2 className="font-display text-xl text-error">Activation Failed</h2>
Activation Failed
</h2>
<p className="opacity-70 mb-8 leading-relaxed"> <p className="opacity-70 mb-8 leading-relaxed">
The link might be expired or already used. Please try registering The link might be expired or already used. Please try registering
again. again.
+9 -11
View File
@@ -6,6 +6,7 @@ import { useNavigate } from "react-router-dom";
import { z } from "zod"; import { z } from "zod";
import Logo from "../components/Logo"; import Logo from "../components/Logo";
import FormField from "../components/ui/FormField"; import FormField from "../components/ui/FormField";
import { ROUTES } from "../config/routes";
import { useAuth } from "../store/useAuth"; import { useAuth } from "../store/useAuth";
const loginSchema = z.object({ const loginSchema = z.object({
@@ -34,7 +35,7 @@ export default function Login() {
setApiError(null); setApiError(null);
try { try {
await login(data); await login(data);
navigate("/drawer"); navigate(ROUTES.DRAWER);
} catch (err) { } catch (err) {
console.error("Login error:", err); console.error("Login error:", err);
let message = "Invalid email or password"; let message = "Invalid email or password";
@@ -48,13 +49,11 @@ export default function Login() {
} }
}; };
return (
<div className="flex min-h-screen items-center justify-center bg-base-200">
<div className="glass-card w-full max-w-sm p-2 transition-all duration-500 hover:shadow-2xl fade-zoom"> <div className="glass-card w-full max-w-sm p-2 transition-all duration-500 hover:shadow-2xl fade-zoom">
<form onSubmit={handleSubmit(onSubmit)} className="card-body gap-4"> <form onSubmit={handleSubmit(onSubmit)} className="card-body gap-4">
<h2 className="card-title font-display text-2xl font-bold justify-center text-primary tracking-tight"> <h1 className="card-title font-display text-2xl font-bold justify-center text-primary tracking-tight">
Sign in to <Logo /> Sign in to <Logo />
</h2> </h1>
{apiError && ( {apiError && (
<div className="alert alert-error text-xs py-2 rounded-md"> <div className="alert alert-error text-xs py-2 rounded-md">
@@ -82,6 +81,7 @@ export default function Login() {
<button <button
type="submit" type="submit"
disabled={isLoading} disabled={isLoading}
aria-label="Sign In"
className="btn btn-primary w-full shadow-lg" className="btn btn-primary w-full shadow-lg"
> >
{isLoading ? ( {isLoading ? (
@@ -92,18 +92,16 @@ export default function Login() {
</button> </button>
</div> </div>
<div className="text-center text-sm opacity-70"> <div className="text-center text-sm font-medium text-base-content/70">
Don't have an account?{" "} Don't have an account?{" "}
<button <button
type="button" type="button"
onClick={() => navigate("/register")} onClick={() => navigate(ROUTES.ONBOARD)}
className="link link-primary text-primary-content no-underline hover:underline" className="link link-primary no-underline hover:underline font-bold"
> >
Register Register
</button> </button>
</div> </div>
</form> </form>
</div> </div>;
</div>
);
} }
+7 -10
View File
@@ -62,9 +62,9 @@ export default function Register() {
return ( return (
<div className="glass-card w-full max-w-sm p-2 transition-all duration-500 hover:shadow-2xl fade-zoom"> <div className="glass-card w-full max-w-sm p-2 transition-all duration-500 hover:shadow-2xl fade-zoom">
<form onSubmit={handleSubmit(onSubmit)} className="card-body gap-4"> <form onSubmit={handleSubmit(onSubmit)} className="card-body gap-4">
<h2 className="card-title font-display text-2xl font-bold justify-center text-primary tracking-tight"> <h1 className="card-title font-display text-2xl font-bold justify-center text-primary tracking-tight">
Create a <Logo /> Account Create a <Logo /> Account
</h2> </h1>
{apiError && ( {apiError && (
<div className="alert alert-error text-xs py-2 rounded-md"> <div className="alert alert-error text-xs py-2 rounded-md">
@@ -104,15 +104,11 @@ export default function Register() {
/> />
{/* Warning */} {/* Warning */}
<div className="bg-warning/10 border-l-2 border-warning p-3 rounded-r-md flex gap-2"> <div className="alert alert-warning items-start text-left p-3 gap-2 rounded-md border-warning/20">
<InfoIcon <InfoIcon size={20} weight="duotone" className="mt-0.5 shrink-0" />
size={20} <p className="text-sm font-semibold">
weight="duotone"
className="text-warning mt-0.5 shrink-0"
/>
<p className="text-sm text-warning-content font-medium opacity-90">
Choose a password you won't forget. <br /> Choose a password you won't forget. <br />
<span className="font-semibold underline">There is no reset.</span>{" "} <span className="underline decoration-2">There is no reset.</span>{" "}
If you lose it, your letters cannot be recovered. If you lose it, your letters cannot be recovered.
</p> </p>
</div> </div>
@@ -121,6 +117,7 @@ export default function Register() {
<button <button
type="submit" type="submit"
disabled={isLoading} disabled={isLoading}
aria-label="Register"
className="btn btn-primary w-full shadow-lg" className="btn btn-primary w-full shadow-lg"
> >
{isLoading ? ( {isLoading ? (
+1 -1
View File
@@ -22,7 +22,7 @@ export default function VerifyEmail() {
<div className="divider opacity-10"></div> <div className="divider opacity-10"></div>
<div className="bg-base-200/50 p-4 rounded-lg text-xs leading-relaxed text-left opacity-70"> <div className="alert bg-base-200/50 p-4 rounded-lg text-xs leading-relaxed text-left opacity-70">
<p> <p>
Didn't receive it? Check your spam folder or wait for a few minutes. Didn't receive it? Check your spam folder or wait for a few minutes.
The link will expire in 24 hours. The link will expire in 24 hours.