Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions frontend/app/components/Toast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use client";

// Toast component — re-exports from ToastContext for convenience
// The actual rendering is handled inside ToastProvider in ToastContext.tsx
export { useToast, ToastProvider } from "@/app/context/ToastContext";
66 changes: 66 additions & 0 deletions frontend/app/context/ToastContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"use client";

import { createContext, useContext, useState, useCallback, ReactNode } from "react";

type ToastType = "success" | "error" | "info";

interface Toast {
id: number;
message: string;
type: ToastType;
}

interface ToastContextValue {
showToast: (message: string, type?: ToastType) => void;
}

const ToastContext = createContext<ToastContextValue>({
showToast: () => {},
});

export function useToast() {
return useContext(ToastContext);
}

export function ToastProvider({ children }: { children: ReactNode }) {
const [toasts, setToasts] = useState<Toast[]>([]);

const showToast = useCallback((message: string, type: ToastType = "info") => {
const id = Date.now();
setToasts((prev) => [...prev, { id, message, type }]);
setTimeout(() => {
setToasts((prev) => prev.filter((t) => t.id !== id));
}, 4000);
}, []);

const removeToast = (id: number) => {
setToasts((prev) => prev.filter((t) => t.id !== id));
};

return (
<ToastContext.Provider value={{ showToast }}>
{children}
{/* Toast container — fixed top-right */}
<div className="fixed top-4 right-4 z-50 flex flex-col gap-3 pointer-events-none">
{toasts.map((toast) => (
<div
key={toast.id}
className={`pointer-events-auto flex items-start gap-3 min-w-[280px] max-w-sm px-4 py-3 rounded-xl shadow-lg text-sm font-medium transition-all duration-300 animate-slide-in
${toast.type === "success" ? "bg-emerald-600 text-white" : ""}
${toast.type === "error" ? "bg-red-600 text-white" : ""}
${toast.type === "info" ? "bg-slate-800 text-white" : ""}
`}
>
<span className="flex-1">{toast.message}</span>
<button
onClick={() => removeToast(toast.id)}
className="ml-2 text-white opacity-70 hover:opacity-100 transition text-lg leading-none"
>
×
</button>
</div>
))}
</div>
</ToastContext.Provider>
);
}
14 changes: 14 additions & 0 deletions frontend/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,17 @@ body {
background: var(--accent-strong);
}

@keyframes slide-in {
from {
opacity: 0;
transform: translateX(100%);
}
to {
opacity: 1;
transform: translateX(0);
}
}

.animate-slide-in {
animation: slide-in 0.3s ease-out;
}
5 changes: 4 additions & 1 deletion frontend/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./globals.css";
import AppShell from "@/app/components/AppShell";
import { ToastProvider } from "@/app/context/ToastContext";

export default function RootLayout({
children,
Expand All @@ -9,7 +10,9 @@ export default function RootLayout({
return (
<html lang="en">
<body>
<AppShell>{children}</AppShell>
<ToastProvider>
<AppShell>{children}</AppShell>
</ToastProvider>
</body>
</html>
);
Expand Down
13 changes: 5 additions & 8 deletions frontend/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import Link from "next/link";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { isSupabaseConfigured, supabase } from "@/app/lib/supabase";
import { useToast } from "@/app/context/ToastContext";

export default function Login() {
const router = useRouter();
const { showToast } = useToast();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [loading, setLoading] = useState(false);
Expand All @@ -21,17 +23,12 @@ export default function Login() {

const handleLogin = async () => {
if (!supabase) {
alert("Supabase is not configured. Add NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY in frontend/.env.local.");
showToast("Supabase is not configured. Add NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY in frontend/.env.local.", "error");
return;
}

if (!email || !password) {
alert("Please enter your email and password.");
return;
}

if (!supabase) {
alert("Supabase is not configured.");
showToast("Please enter your email and password.", "error");
return;
}

Expand All @@ -42,7 +39,7 @@ export default function Login() {
});
setLoading(false);

if (error) alert(error.message);
if (error) showToast(error.message, "error");
else router.push(redirectPath);
};

Expand Down
Loading