Changeset 3de009b for frontend/src/pages/Register.tsx
- Timestamp:
- 02/05/26 16:11:26 (5 months ago)
- Branches:
- main
- Children:
- 929e93c
- Parents:
- 0792d02
- File:
-
- 1 edited
-
frontend/src/pages/Register.tsx (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/pages/Register.tsx
r0792d02 r3de009b 4 4 import axiosInstance, { scheduleTokenRefresh } from "../api/axiosInstance"; 5 5 import { useAuth } from "../context/authContext"; 6 import type { User } from "../utils/types";6 import type { User, UserRegisterType } from "../utils/types"; 7 7 8 8 const Register = () => { … … 11 11 const [password, setPassword] = useState(""); 12 12 const [fullname, setFullname] = useState(""); 13 const [userType, setUserType] = useState<UserRegisterType[]>([]); 13 14 const [email, setEmail] = useState(""); 14 15 const [profilePhotoFile, setProfilePhotoFile] = useState<File | null>(null); … … 43 44 } 44 45 45 if (username === "" || password === "" || fullname === "" || email === "") { 46 if ( 47 username === "" || 48 password === "" || 49 fullname === "" || 50 email === "" || 51 userType.length === 0 52 ) { 46 53 setError("Please fill in all required fields."); 47 54 return; 48 55 } 49 50 56 if (profilePhotoFile && !profilePhotoFile.type.startsWith("image/")) { 51 57 alert("Only images allowed"); … … 58 64 formData.append("email", email); 59 65 formData.append("password", password); 66 userType.forEach((type) => formData.append("userType", type)); 60 67 61 68 try { … … 77 84 <div className="flex flex-col items-center justify-center min-h-[90vh] bg-gray-100"> 78 85 <h2 className="text-2xl mb-4">Register</h2> 79 <form className="bg-white p-6 rounded shadow-md w-full max-w-md"> 86 <form 87 className="bg-white p-6 rounded shadow-md w-full max-w-md" 88 onSubmit={handleRegister} 89 > 80 90 {error && <p className="text-red-500 mb-4">{error}</p>} 81 91 <div className="mb-4"> … … 126 136 onChange={(e) => setEmail(e.target.value)} 127 137 /> 138 </div> 139 <div className="mb-4"> 140 <label className="block text-gray-700 mb-2" htmlFor="userType"> 141 User Type 142 </label> 143 <input 144 type="checkbox" 145 id="artist" 146 value="ARTIST" 147 onChange={(e) => { 148 if (e.target.checked) { 149 setUserType((prev) => [...prev, "ARTIST"]); 150 } else { 151 setUserType((prev) => prev.filter((type) => type !== "ARTIST")); 152 } 153 }} 154 /> 155 <label htmlFor="artist" className="ml-2 mr-4"> 156 Artist 157 </label> 158 <input 159 type="checkbox" 160 id="listener" 161 value="LISTENER" 162 onChange={(e) => { 163 if (e.target.checked) { 164 setUserType((prev) => [...prev, "LISTENER"]); 165 } else { 166 setUserType((prev) => 167 prev.filter((type) => type !== "LISTENER"), 168 ); 169 } 170 }} 171 /> 172 <label htmlFor="listener" className="ml-2"> 173 Listener 174 </label> 128 175 </div> 129 176 <div className="mb-4">
Note:
See TracChangeset
for help on using the changeset viewer.
