Changeset c1d2f07 for frontend/src


Ignore:
Timestamp:
01/27/26 15:56:00 (6 months ago)
Author:
Dimitar Arsov <dimitararsov04@…>
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.
Message:

Merge branch 'main' into follow-user

Location:
frontend/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • frontend/src/App.tsx

    r77e572b rc1d2f07  
    11import { createBrowserRouter, Outlet, RouterProvider } from "react-router-dom";
     2import { ToastContainer } from "react-toastify";
     3import "react-toastify/dist/ReactToastify.css";
    24import AllUsers from "./pages/AllUsers";
    35import LandingPage from "./pages/LandingPage";
     
    1113                <div className="flex flex-col min-h-screen">
    1214                        <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                        />
    1327                        <main className="grow">
    1428                                <Outlet />
  • frontend/src/api/axiosInstance.ts

    r77e572b rc1d2f07  
    7070                        [401, 403].includes(error.response?.status) &&
    7171                        !originalConfig._retry &&
    72                         originalConfig.url !== "/auth/refresh"
     72                        originalConfig.url !== "/auth/refresh" &&
     73                        originalConfig.url !== "/auth/login" &&
     74                        originalConfig.url !== "/auth/register"
    7375                ) {
    7476                        originalConfig._retry = true;
  • frontend/src/pages/Login.tsx

    r77e572b rc1d2f07  
    11import { useState } from "react";
    22import { useNavigate } from "react-router-dom";
     3import { toast } from "react-toastify";
    34import axiosInstance, { scheduleTokenRefresh } from "../api/axiosInstance";
    45import { useAuth } from "../context/authContext";
     
    2223                        setUser(response.data.user);
    2324                        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}`);
    2631                }
    2732        };
  • frontend/src/pages/Nav.tsx

    r77e572b rc1d2f07  
    11import { Link } from "react-router-dom";
     2import { toast } from "react-toastify";
    23import axiosInstance, { baseURL } from "../api/axiosInstance";
    34import Logo from "../assets/logo-finkwave.png";
     
    1213                        await axiosInstance.post("/auth/logout");
    1314                        setUser(undefined);
     15                        toast.success("Logout successful!");
    1416                } catch (error) {
    1517                        console.error("Logout failed:", error);
     18                        toast.error("Logout failed!");
    1619                }
    1720        };
  • frontend/src/pages/Register.tsx

    r77e572b rc1d2f07  
    11import { useEffect, useState } from "react";
    22import { useNavigate } from "react-router";
     3import { toast } from "react-toastify";
    34import axiosInstance, { scheduleTokenRefresh } from "../api/axiosInstance";
    45import { useAuth } from "../context/authContext";
     
    1516                null,
    1617        );
     18        const [error, setError] = useState<string | null>(null);
    1719
    1820        const navigate = useNavigate();
     
    2628        }, [previewProfilePhoto]);
    2729
     30        const handleRemoveFile = () => {
     31                if (previewProfilePhoto) {
     32                        URL.revokeObjectURL(previewProfilePhoto);
     33                }
     34                setProfilePhotoFile(null);
     35                setPreviewProfilePhoto(null);
     36        };
     37
    2838        const handleRegister = async (e: React.FormEvent) => {
    2939                e.preventDefault();
    30                 // todo: add proper error handling
    3140                if (profilePhotoFile && profilePhotoFile.size > 5 * 1024 * 1024) {
    3241                        alert("Max file size is 5MB");
     42                        return;
     43                }
     44
     45                if (username === "" || password === "" || fullname === "" || email === "") {
     46                        setError("Please fill in all required fields.");
    3347                        return;
    3448                }
     
    5367                        setUser(response.data.user);
    5468                        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}`);
    5773                }
    5874        };
     
    6177                <div className="flex flex-col items-center justify-center min-h-[90vh] bg-gray-100">
    6278                        <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>}
    6481                                <div className="mb-4">
    6582                                        <label className="block text-gray-700 mb-2" htmlFor="username">
     
    115132                                                <label
    116133                                                        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"
    118135                                                >
    119136                                                        Choose File
    120137                                                </label>
    121                                                 <span className="text-gray-600 text-sm">
     138                                                <span className="text-gray-600 text-sm flex-1">
    122139                                                        {profilePhotoFile ? profilePhotoFile.name : "No file chosen"}
    123140                                                </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                                                )}
    124150                                        </div>
    125151                                        <input
Note: See TracChangeset for help on using the changeset viewer.