Ignore:
Timestamp:
01/27/26 14:03:17 (6 months ago)
Author:
Filip Gavrilovski <filipgavrilovski28@…>
Branches:
main
Children:
3238007
Parents:
4e5cf92
Message:

add toasts on frontend

File:
1 edited

Legend:

Unmodified
Added
Removed
  • frontend/src/pages/Register.tsx

    r4e5cf92 rb70fbeb  
    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();
     
    2830        const handleRegister = async (e: React.FormEvent) => {
    2931                e.preventDefault();
    30                 // todo: add proper error handling
    3132                if (profilePhotoFile && profilePhotoFile.size > 5 * 1024 * 1024) {
    3233                        alert("Max file size is 5MB");
     
    5354                        setUser(response.data.user);
    5455                        navigate("/");
    55                 } catch (error) {
    56                         console.error("Registration failed:", error);
     56                        toast.success("Registration successful!");
     57                } catch (error: any) {
     58                        const errorMessage =
     59                                error.response?.data?.error || "Registration failed. Please try again.";
     60                        setError(errorMessage);
     61                        toast.error(errorMessage);
    5762                }
    5863        };
     
    6267                        <h2 className="text-2xl mb-4">Register</h2>
    6368                        <form className="bg-white p-6 rounded shadow-md w-80">
     69                                {error && <p className="text-red-500 mb-4">{error}</p>}
    6470                                <div className="mb-4">
    6571                                        <label className="block text-gray-700 mb-2" htmlFor="username">
Note: See TracChangeset for help on using the changeset viewer.