Changeset 16aed54 for frontend/src


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

minor changes with error handling

Location:
frontend/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • frontend/src/api/axiosInstance.ts

    r3238007 r16aed54  
    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/Register.tsx

    r3238007 r16aed54  
    2828        }, [previewProfilePhoto]);
    2929
     30        const handleRemoveFile = () => {
     31                if (previewProfilePhoto) {
     32                        URL.revokeObjectURL(previewProfilePhoto);
     33                }
     34                setProfilePhotoFile(null);
     35                setPreviewProfilePhoto(null);
     36        };
     37
    3038        const handleRegister = async (e: React.FormEvent) => {
    3139                e.preventDefault();
    3240                if (profilePhotoFile && profilePhotoFile.size > 5 * 1024 * 1024) {
    3341                        alert("Max file size is 5MB");
     42                        return;
     43                }
     44
     45                if (username === "" || password === "" || fullname === "" || email === "") {
     46                        setError("Please fill in all required fields.");
    3447                        return;
    3548                }
     
    5669                        toast.success("Registration successful!");
    5770                } catch (error: any) {
    58                         const errorMessage =
    59                                 error.response?.data?.error || "Registration failed. Please try again.";
     71                        const errorMessage = error.response?.data?.error || "Please try again.";
    6072                        setError(`Registration failed: ${errorMessage}`);
    6173                }
     
    6577                <div className="flex flex-col items-center justify-center min-h-[90vh] bg-gray-100">
    6678                        <h2 className="text-2xl mb-4">Register</h2>
    67                         <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">
    6880                                {error && <p className="text-red-500 mb-4">{error}</p>}
    6981                                <div className="mb-4">
     
    120132                                                <label
    121133                                                        htmlFor="profilePhoto"
    122                                                         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"
    123135                                                >
    124136                                                        Choose File
    125137                                                </label>
    126                                                 <span className="text-gray-600 text-sm">
     138                                                <span className="text-gray-600 text-sm flex-1">
    127139                                                        {profilePhotoFile ? profilePhotoFile.name : "No file chosen"}
    128140                                                </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                                                )}
    129150                                        </div>
    130151                                        <input
Note: See TracChangeset for help on using the changeset viewer.