Changeset 3de009b for frontend/src


Ignore:
Timestamp:
02/05/26 16:11:26 (5 months ago)
Author:
Filip Gavrilovski <filipgavrilovski28@…>
Branches:
main
Children:
929e93c
Parents:
0792d02
Message:

enable registering as listener and artist

Location:
frontend/src
Files:
2 edited

Legend:

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

    r0792d02 r3de009b  
    44import axiosInstance, { scheduleTokenRefresh } from "../api/axiosInstance";
    55import { useAuth } from "../context/authContext";
    6 import type { User } from "../utils/types";
     6import type { User, UserRegisterType } from "../utils/types";
    77
    88const Register = () => {
     
    1111        const [password, setPassword] = useState("");
    1212        const [fullname, setFullname] = useState("");
     13        const [userType, setUserType] = useState<UserRegisterType[]>([]);
    1314        const [email, setEmail] = useState("");
    1415        const [profilePhotoFile, setProfilePhotoFile] = useState<File | null>(null);
     
    4344                }
    4445
    45                 if (username === "" || password === "" || fullname === "" || email === "") {
     46                if (
     47                        username === "" ||
     48                        password === "" ||
     49                        fullname === "" ||
     50                        email === "" ||
     51                        userType.length === 0
     52                ) {
    4653                        setError("Please fill in all required fields.");
    4754                        return;
    4855                }
    49 
    5056                if (profilePhotoFile && !profilePhotoFile.type.startsWith("image/")) {
    5157                        alert("Only images allowed");
     
    5864                formData.append("email", email);
    5965                formData.append("password", password);
     66                userType.forEach((type) => formData.append("userType", type));
    6067
    6168                try {
     
    7784                <div className="flex flex-col items-center justify-center min-h-[90vh] bg-gray-100">
    7885                        <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                        >
    8090                                {error && <p className="text-red-500 mb-4">{error}</p>}
    8191                                <div className="mb-4">
     
    126136                                                onChange={(e) => setEmail(e.target.value)}
    127137                                        />
     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>
    128175                                </div>
    129176                                <div className="mb-4">
  • frontend/src/utils/types.ts

    r0792d02 r3de009b  
    11export 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";
    77}
    88
    99export 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;
    1616}
    1717
    1818export 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;
    2525}
    2626
    2727export interface Song extends MusicalEntity {
    28   type: "SONG";
     28        type: "SONG";
    2929}
    3030
    3131export interface Album extends MusicalEntity {
    32   type: "ALBUM";
    33   songs: Song[];
     32        type: "ALBUM";
     33        songs: Song[];
    3434}
    3535
    3636export 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;
    4343}
    4444
    4545export 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;
    5353}
     54
     55export type UserRegisterType = "ARTIST" | "LISTENER";
Note: See TracChangeset for help on using the changeset viewer.