Changeset 3de009b for frontend/src
- Timestamp:
- 02/05/26 16:11:26 (5 months ago)
- Branches:
- main
- Children:
- 929e93c
- Parents:
- 0792d02
- Location:
- frontend/src
- Files:
-
- 2 edited
-
pages/Register.tsx (modified) (6 diffs)
-
utils/types.ts (modified) (1 diff)
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"> -
frontend/src/utils/types.ts
r0792d02 r3de009b 1 1 export interface User { 2 username: string;3 fullName: string;4 email?: string;5 profilePhoto?: string | null;6 role?: "ADMIN" | "NONADMIN";2 username: string; 3 fullName: string; 4 email?: string; 5 profilePhoto?: string | null; 6 role?: "ADMIN" | "NONADMIN"; 7 7 } 8 8 9 9 export interface ArtistContribution { 10 id: number;11 title: string;12 genre: string;13 role: string;14 entityType: string;15 isLikedByCurrentUser: boolean;10 id: number; 11 title: string; 12 genre: string; 13 role: string; 14 entityType: string; 15 isLikedByCurrentUser: boolean; 16 16 } 17 17 18 18 export interface MusicalEntity { 19 id: number;20 title: string;21 genre: string;22 type: string;23 releasedBy: string;24 isLikedByCurrentUser?: boolean;19 id: number; 20 title: string; 21 genre: string; 22 type: string; 23 releasedBy: string; 24 isLikedByCurrentUser?: boolean; 25 25 } 26 26 27 27 export interface Song extends MusicalEntity { 28 type: "SONG";28 type: "SONG"; 29 29 } 30 30 31 31 export interface Album extends MusicalEntity { 32 type: "ALBUM";33 songs: Song[];32 type: "ALBUM"; 33 songs: Song[]; 34 34 } 35 35 36 36 export interface Playlist { 37 id: number;38 name: string;39 cover: string;40 creatorName: string;41 songsInPlaylist: Song[];42 isSavedByCurrentUser: boolean;37 id: number; 38 name: string; 39 cover: string; 40 creatorName: string; 41 songsInPlaylist: Song[]; 42 isSavedByCurrentUser: boolean; 43 43 } 44 44 45 45 export interface BaseNonAdminUser { 46 username: string;47 fullName: string;48 userType: string;49 profilePhoto: string;50 followers: number;51 following: number;52 isFollowedByCurrentUser: boolean;46 username: string; 47 fullName: string; 48 userType: string; 49 profilePhoto: string; 50 followers: number; 51 following: number; 52 isFollowedByCurrentUser: boolean; 53 53 } 54 55 export type UserRegisterType = "ARTIST" | "LISTENER";
Note:
See TracChangeset
for help on using the changeset viewer.
