Changeset c1d2f07 for frontend/src
- Timestamp:
- 01/27/26 15:56:00 (6 months ago)
- Branches:
- main
- Children:
- 6de2873
- Parents:
- 77e572b (diff), 16aed54 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- frontend/src
- Files:
-
- 5 edited
-
App.tsx (modified) (2 diffs)
-
api/axiosInstance.ts (modified) (1 diff)
-
pages/Login.tsx (modified) (2 diffs)
-
pages/Nav.tsx (modified) (2 diffs)
-
pages/Register.tsx (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/App.tsx
r77e572b rc1d2f07 1 1 import { createBrowserRouter, Outlet, RouterProvider } from "react-router-dom"; 2 import { ToastContainer } from "react-toastify"; 3 import "react-toastify/dist/ReactToastify.css"; 2 4 import AllUsers from "./pages/AllUsers"; 3 5 import LandingPage from "./pages/LandingPage"; … … 11 13 <div className="flex flex-col min-h-screen"> 12 14 <Nav /> 15 <ToastContainer 16 position="top-right" 17 autoClose={2000} 18 hideProgressBar={false} 19 newestOnTop={false} 20 closeOnClick 21 rtl={false} 22 pauseOnFocusLoss 23 draggable 24 pauseOnHover 25 theme="light" 26 /> 13 27 <main className="grow"> 14 28 <Outlet /> -
frontend/src/api/axiosInstance.ts
r77e572b rc1d2f07 70 70 [401, 403].includes(error.response?.status) && 71 71 !originalConfig._retry && 72 originalConfig.url !== "/auth/refresh" 72 originalConfig.url !== "/auth/refresh" && 73 originalConfig.url !== "/auth/login" && 74 originalConfig.url !== "/auth/register" 73 75 ) { 74 76 originalConfig._retry = true; -
frontend/src/pages/Login.tsx
r77e572b rc1d2f07 1 1 import { useState } from "react"; 2 2 import { useNavigate } from "react-router-dom"; 3 import { toast } from "react-toastify"; 3 4 import axiosInstance, { scheduleTokenRefresh } from "../api/axiosInstance"; 4 5 import { useAuth } from "../context/authContext"; … … 22 23 setUser(response.data.user); 23 24 navigate("/"); 24 } catch (error) { 25 setError("Login failed. Please check your credentials."); 25 toast.success("Login successful!"); 26 } catch (error: any) { 27 const errorMessage = 28 error.response?.data?.error || 29 "Login failed. Please check your credentials."; 30 setError(`Login failed: ${errorMessage}`); 26 31 } 27 32 }; -
frontend/src/pages/Nav.tsx
r77e572b rc1d2f07 1 1 import { Link } from "react-router-dom"; 2 import { toast } from "react-toastify"; 2 3 import axiosInstance, { baseURL } from "../api/axiosInstance"; 3 4 import Logo from "../assets/logo-finkwave.png"; … … 12 13 await axiosInstance.post("/auth/logout"); 13 14 setUser(undefined); 15 toast.success("Logout successful!"); 14 16 } catch (error) { 15 17 console.error("Logout failed:", error); 18 toast.error("Logout failed!"); 16 19 } 17 20 }; -
frontend/src/pages/Register.tsx
r77e572b rc1d2f07 1 1 import { useEffect, useState } from "react"; 2 2 import { useNavigate } from "react-router"; 3 import { toast } from "react-toastify"; 3 4 import axiosInstance, { scheduleTokenRefresh } from "../api/axiosInstance"; 4 5 import { useAuth } from "../context/authContext"; … … 15 16 null, 16 17 ); 18 const [error, setError] = useState<string | null>(null); 17 19 18 20 const navigate = useNavigate(); … … 26 28 }, [previewProfilePhoto]); 27 29 30 const handleRemoveFile = () => { 31 if (previewProfilePhoto) { 32 URL.revokeObjectURL(previewProfilePhoto); 33 } 34 setProfilePhotoFile(null); 35 setPreviewProfilePhoto(null); 36 }; 37 28 38 const handleRegister = async (e: React.FormEvent) => { 29 39 e.preventDefault(); 30 // todo: add proper error handling31 40 if (profilePhotoFile && profilePhotoFile.size > 5 * 1024 * 1024) { 32 41 alert("Max file size is 5MB"); 42 return; 43 } 44 45 if (username === "" || password === "" || fullname === "" || email === "") { 46 setError("Please fill in all required fields."); 33 47 return; 34 48 } … … 53 67 setUser(response.data.user); 54 68 navigate("/"); 55 } catch (error) { 56 console.error("Registration failed:", error); 69 toast.success("Registration successful!"); 70 } catch (error: any) { 71 const errorMessage = error.response?.data?.error || "Please try again."; 72 setError(`Registration failed: ${errorMessage}`); 57 73 } 58 74 }; … … 61 77 <div className="flex flex-col items-center justify-center min-h-[90vh] bg-gray-100"> 62 78 <h2 className="text-2xl mb-4">Register</h2> 63 <form className="bg-white p-6 rounded shadow-md w-80"> 79 <form className="bg-white p-6 rounded shadow-md w-full max-w-md"> 80 {error && <p className="text-red-500 mb-4">{error}</p>} 64 81 <div className="mb-4"> 65 82 <label className="block text-gray-700 mb-2" htmlFor="username"> … … 115 132 <label 116 133 htmlFor="profilePhoto" 117 className="px-4 py-2 bg-blue-500 text-white rounded cursor-pointer hover:bg-blue-600 transition-colors text-sm font-medium "134 className="px-4 py-2 bg-blue-500 text-white rounded cursor-pointer hover:bg-blue-600 transition-colors text-sm font-medium text-center" 118 135 > 119 136 Choose File 120 137 </label> 121 <span className="text-gray-600 text-sm ">138 <span className="text-gray-600 text-sm flex-1"> 122 139 {profilePhotoFile ? profilePhotoFile.name : "No file chosen"} 123 140 </span> 141 {profilePhotoFile && ( 142 <button 143 type="button" 144 onClick={handleRemoveFile} 145 className="px-3 py-2 bg-red-500 text-white rounded hover:bg-red-600 transition-colors text-sm font-medium" 146 > 147 Remove 148 </button> 149 )} 124 150 </div> 125 151 <input
Note:
See TracChangeset
for help on using the changeset viewer.
