Refactor navigation links and update profile

component
This commit is contained in:
Pattadon 2023-11-27 15:37:39 +07:00
parent f0d54d6423
commit 0c60f48d18
3 changed files with 108 additions and 38 deletions

View File

@ -39,12 +39,12 @@ export function NavBar() {
tabIndex={0} tabIndex={0}
className="mt-3 z-[10] p-2 shadow menu menu-sm dropdown-content bg-base-100 rounded-box w-52"> className="mt-3 z-[10] p-2 shadow menu menu-sm dropdown-content bg-base-100 rounded-box w-52">
<li> <li>
<a href={settings.Profile} className="justify-between"> <a onClick={() => Navigate(settings.Profile)} className="justify-between">
Profile Profile
</a> </a>
</li> </li>
<li> <li>
<a href={settings.Account}>Settings</a> <a onClick={() => Navigate(settings.Account)}>Settings</a>
</li> </li>
<li> <li>
<a onClick={logout}>Logout</a> <a onClick={logout}>Logout</a>

View File

@ -1,13 +1,30 @@
import { useState, useRef } from "react"; import { useState, useRef } from "react";
import { ApiUpdateUserProfile } from "src/api/UserProfileApi"; import { ApiUpdateUserProfile } from "src/api/UserProfileApi";
import { axiosInstance } from "src/api/AxiosConfig";
import { useEffect } from "react";
export function ProfileUpdateComponent() { export function ProfileUpdateComponent() {
const [file, setFile] = useState(null); const [file, setFile] = useState(null);
const [username, setUsername] = useState(""); const [firstName, setFirstName] = useState("");
const [fullName, setFullName] = useState(""); const [about, setAbout] = useState();
const [about, setAbout] = useState("");
const defaultImage = "https://i1.sndcdn.com/artworks-cTz48e4f1lxn5Ozp-L3hopw-t500x500.jpg";
const fileInputRef = useRef(null); const fileInputRef = useRef(null);
const [profile_pic, setProfilePic] = useState(undefined);
useEffect(() => {
const fetchUser = async () => {
try {
const response = await axiosInstance.get("/user/data/");
const fetchedProfilePic = response.data.profile_pic;
const fetchedName = response.data.first_name;
const fetchedAbout = response.data.about;
setProfilePic(fetchedProfilePic);
setAbout(fetchedAbout);
setFirstName(fetchedName);
} catch (error) {
console.error("Error fetching user:", error);
}
};
fetchUser();
}, []);
const handleImageUpload = () => { const handleImageUpload = () => {
if (fileInputRef.current) { if (fileInputRef.current) {
@ -25,7 +42,7 @@ export function ProfileUpdateComponent() {
const handleSave = () => { const handleSave = () => {
const formData = new FormData(); const formData = new FormData();
formData.append("profile_pic", file); formData.append("profile_pic", file);
formData.append("first_name", username); formData.append("first_name", firstName);
formData.append("about", about); formData.append("about", about);
ApiUpdateUserProfile(formData); ApiUpdateUserProfile(formData);
@ -45,12 +62,19 @@ export function ProfileUpdateComponent() {
ref={fileInputRef} ref={fileInputRef}
/> />
</label> </label>
<div className="avatar w-32 h-32 cursor-pointer hover:blur" onClick={handleImageUpload}> <div
className="avatar w-32 h-32 cursor-pointer hover:blur"
onClick={handleImageUpload}
>
{file ? ( {file ? (
<img src={URL.createObjectURL(file)} alt="Profile" className="rounded-full" /> <img
src={URL.createObjectURL(file)}
alt="Profile"
className="rounded-full"
/>
) : ( ) : (
<> <>
<img src={defaultImage} alt="Default" className="rounded-full" /> <img src={profile_pic} alt="Default" className="rounded-full" />
<i className="fas fa-camera text-white text-2xl absolute bottom-0 right-0 mr-2 mb-2"></i> <i className="fas fa-camera text-white text-2xl absolute bottom-0 right-0 mr-2 mb-2"></i>
<i className="fas fa-arrow-up text-white text-2xl absolute top-0 right-0 mr-2 mt-2"></i> <i className="fas fa-arrow-up text-white text-2xl absolute top-0 right-0 mr-2 mt-2"></i>
</> </>
@ -58,7 +82,7 @@ export function ProfileUpdateComponent() {
</div> </div>
</div> </div>
{/* Username Field */} {/* Username Field
<div className="w-96"> <div className="w-96">
<label className="block mb-2 text-gray-600">Username</label> <label className="block mb-2 text-gray-600">Username</label>
<input <input
@ -68,16 +92,16 @@ export function ProfileUpdateComponent() {
value={username} value={username}
onChange={(e) => setUsername(e.target.value)} onChange={(e) => setUsername(e.target.value)}
/> />
</div> </div> */}
{/* Full Name Field */} {/* Full Name Field */}
<div className="w-96"> <div className="w-96">
<label className="block mb-2 text-gray-600">Full Name</label> <label className="block mb-2 text-gray-600">First Name</label>
<input <input
type="text" type="text"
placeholder="Enter your full name" placeholder="Enter your first name"
className="input w-full" className="input w-full"
value={fullName} value={firstName}
onChange={(e) => setFullName(e.target.value)} onChange={(e) => setFullName(e.target.value)}
/> />
</div> </div>

View File

@ -1,36 +1,63 @@
import { ProfileUpdateComponent } from "./ProfileUpdateComponent"; import { ProfileUpdateComponent } from "./ProfileUpdateComponent";
import { axiosInstance } from "src/api/AxiosConfig";
import { useEffect, useState } from "react";
export function ProfileUpdatePage() { export function ProfileUpdatePage() {
const [profile_pic, setProfilePic] = useState(undefined);
const [about, setAbout] = useState();
useEffect(() => {
const fetchUser = async () => {
try {
const response = await axiosInstance.get("/user/data/");
const fetchedProfilePic = response.data.profile_pic;
const fetchedAbout = response.data.about;
setProfilePic(fetchedProfilePic);
setAbout(fetchedAbout);
} catch (error) {
console.error("Error fetching user:", error);
}
};
fetchUser();
}, []);
return ( return (
<div> <div>
<div className="stats shadow mt-3"> <div className="stats shadow mt-3">
<div className="stat"> <div className="stat">
<div className="stat-title truncate">Username</div> <div className="stat-title truncate">Firstname</div>
<div className="stat-value truncate">Sirin</div> <div className="stat-value truncate">Sirin</div>
<div className="stat-desc truncate">User ID</div> {/* <div className="stat-desc truncate">User ID</div> */}
<div className="stat-figure text-secondary"> <div className="stat-figure text-secondary">
<div className="avatar online"> <div className="avatar online">
<div className="w-20 rounded-full"> <div className="w-20 rounded-full">
<img src="https://us-tuna-sounds-images.voicemod.net/f322631f-689a-43ac-81ab-17a70f27c443-1692187175560.png" /> <img src={profile_pic} alt="Profile Picture" />
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div className="stat"> {/* <div className="stat">
<div className="stat-title">Health</div> <div className="stat-title">Health</div>
<div className="stat-value flex truncate"> <div className="stat-value flex truncate">
234/3213 234/3213
<div className="stat-figure text-secondary px-2"> <div className="stat-figure text-secondary px-2">
<svg xmlns="http://www.w3.org/2000/svg" fill="red" viewBox="0 0 24 24" className="inline-block w-8 h-8"> <svg
xmlns="http://www.w3.org/2000/svg"
fill="red"
viewBox="0 0 24 24"
className="inline-block w-8 h-8"
>
<path d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0"></path> <path d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0"></path>
</svg> </svg>
</div> </div>
</div> </div>
<div className="stat-desc py-2">32% Remain</div> <div className="stat-desc py-2">32% Remain</div>
<progress className="progress progress-error w-56" value={20} max="100"></progress> <progress
</div> className="progress progress-error w-56"
value={20}
max="100"
></progress>
</div> */}
{/*
<div className="stat"> <div className="stat">
<div className="stat-title truncate">Level</div> <div className="stat-title truncate">Level</div>
<div className="stat-value flex"> <div className="stat-value flex">
@ -40,13 +67,18 @@ export function ProfileUpdatePage() {
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
fill="#3abff8" fill="#3abff8"
viewBox="0 0 24 24" viewBox="0 0 24 24"
className="inline-block w-8 h-8"> className="inline-block w-8 h-8"
>
<path d="M13 10V3L4 14h7v7l9-11h-7z"></path> <path d="M13 10V3L4 14h7v7l9-11h-7z"></path>
</svg> </svg>
</div> </div>
</div> </div>
<div className="stat-desc py-2">3213/321312321 points</div> <div className="stat-desc py-2">3213/321312321 points</div>
<progress className="progress progress-info w-36" value="10" max="100"></progress> <progress
className="progress progress-info w-36"
value="10"
max="100"
></progress>
</div> </div>
<div className="stat"> <div className="stat">
@ -58,34 +90,43 @@ export function ProfileUpdatePage() {
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
fill="none" fill="none"
viewBox="0 0 24 24" viewBox="0 0 24 24"
className="inline-block w-8 h-8 stroke-current"> className="inline-block w-8 h-8 stroke-current"
>
<path <path
strokeLinecap="round" strokeLinecap="round"
strokeLinejoin="round" strokeLinejoin="round"
strokeWidth="2" strokeWidth="2"
stroke="gold" stroke="gold"
d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"></path> d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"
></path>
</svg> </svg>
</div> </div>
</div> </div>
<div className="stat-desc py-2">Top 12% of Global Ranking</div> <div className="stat-desc py-2">Top 12% of Global Ranking</div>
<progress className="progress progress-warning w-56" value={20} max="100"></progress> <progress
</div> className="progress progress-warning w-56"
value={20}
max="100"
></progress>
</div> */}
</div> </div>
<div className="card bg-base-100 shadow"> <div className="card bg-base-100 shadow">
<div className="card-body"> <div className="card-body">
<h2 className="card-title">About me</h2> <h2 className="card-title">About me</h2>
<div className="card-actions justify-end"></div> <div className="card-actions justify-end"></div>
<textarea className="textarea textarea-bordered textarea-lg w-full" disabled> <textarea
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum dolores recusandae, officiis consequuntur className="textarea textarea-bordered textarea-lg w-full"
nam, non ab commodi totam mollitia iusto nemo voluptatum error aliquam similique perspiciatis, eligendi disabled
nulla. Animi, sit? placeholder="Enter your about me"
>
{about}
</textarea> </textarea>
</div> </div>
</div> </div>
<div className="grid grid-cols-2 grid-rows-2 gap-4 my-2"> {/* <div className="grid grid-cols-2 grid-rows-2 gap-4 my-2">
<div className="col-span-full"> <div className="col-span-full">
<div className="card bg-base-100 shadow"> <div className="card bg-base-100 shadow">
<div className="card-body"> <div className="card-body">
@ -110,18 +151,21 @@ export function ProfileUpdatePage() {
</div> </div>
</div> </div>
</div> </div>
</div> </div> */}
<div className="fixed bottom-4 right-4"> <div className="fixed bottom-4 right-4">
<ul className="menu menu-horizontal bg-base-200 rounded-box"> <ul className="menu menu-horizontal bg-base-200 rounded-box">
<li> <li>
<a onClick={() => document.getElementById("my_modal_4").showModal()}> <a
onClick={() => document.getElementById("my_modal_4").showModal()}
>
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
className="h-5 w-5" className="h-5 w-5"
fill="currentColor" fill="currentColor"
viewBox="0 0 16 16" viewBox="0 0 16 16"
stroke="currentColor"> stroke="currentColor"
>
<path d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z" /> <path d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z" />
</svg> </svg>
<p className="text-xl font-bold">Edit</p> <p className="text-xl font-bold">Edit</p>
@ -135,7 +179,9 @@ export function ProfileUpdatePage() {
<div className="modal-box w-11/12 max-w-5xl flex flex-col"> <div className="modal-box w-11/12 max-w-5xl flex flex-col">
<form method="dialog"> <form method="dialog">
<ProfileUpdateComponent /> <ProfileUpdateComponent />
<button className="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"></button> <button className="btn btn-sm btn-circle btn-ghost absolute right-2 top-2">
</button>
</form> </form>
</div> </div>
</dialog> </dialog>