-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8563345
commit 8e909bd
Showing
9 changed files
with
218 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
.profile { | ||
border: 2px solid var(--color-primary); | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
width: 100%; | ||
justify-content: space-around; | ||
gap: 20px; | ||
padding: 20px; | ||
} | ||
|
||
.item-group { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 10px; | ||
background: var(--color-bg); | ||
padding: 20px; | ||
border-radius: 10px; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.item-group h2 { | ||
color: var(--color-primary); | ||
font-size: 1.5rem; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.item { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
gap: 10px; | ||
width: 100%; | ||
justify-content: space-between; | ||
padding: 10px; | ||
border-radius: 10px; | ||
background: var(--color-bg); | ||
} | ||
|
||
.item label { | ||
color: var(--color-primary); | ||
font-size: 1.2rem; | ||
} | ||
|
||
.item input { | ||
padding: 10px; | ||
border-radius: 5px; | ||
border: 1px solid var(--color-primary); | ||
width: 100%; | ||
} | ||
|
||
.item input:focus { | ||
outline: none; | ||
border: 1px solid var(--color-primary-variant); | ||
} | ||
|
||
.item input:disabled { | ||
background: var(--color-bg); | ||
} | ||
|
||
.item button { | ||
padding: 10px; | ||
border-radius: 5px; | ||
border: none; | ||
background: var(--color-primary); | ||
color: var(--color-bg); | ||
font-size: 1.2rem; | ||
cursor: pointer; | ||
display: flex; | ||
align-items: center; | ||
gap: 10px; | ||
} | ||
|
||
.item button:hover { | ||
background: var(--color-primary-variant); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { GiCheckMark } from 'react-icons/gi'; | ||
import { MdOutlineModeEdit } from 'react-icons/md'; | ||
import { RxCross1 } from 'react-icons/rx'; | ||
import { getStudent, updateStudent } from '../../api/studentApi'; | ||
import getUser from '../../utils/user.js'; | ||
import './Profile.css'; | ||
|
||
const Profile = () => { | ||
const userDetails = getUser(); | ||
const [user, setUser] = useState({}); | ||
const [isEditing, setIsEditing] = useState(''); | ||
|
||
useEffect(() => { | ||
const fetchStudentDetails = async () => { | ||
try { | ||
const student = await getStudent(userDetails.id); | ||
setUser(student.data); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
fetchStudentDetails(); | ||
}, [userDetails.id]); | ||
|
||
const handleInputChange = (name, value) => { | ||
setUser((prevState) => ({ | ||
...prevState, | ||
[name]: value | ||
})); | ||
}; | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
try { | ||
await updateStudent(userDetails.id, user); | ||
setUser(user); | ||
setIsEditing(''); | ||
} catch (error) { | ||
console.log(error.response.data.message); | ||
} | ||
}; | ||
|
||
const onCancel = () => { | ||
const input = document.getElementById(isEditing); | ||
input.disabled = true; | ||
setIsEditing(''); | ||
}; | ||
|
||
const item = (label, name, value) => { | ||
return ( | ||
<div className="item"> | ||
<label htmlFor={name}>{label}</label> | ||
<input | ||
type="text" | ||
name={name} | ||
value={value} | ||
id={name} | ||
onChange={(e) => handleInputChange(name, e.target.value)} | ||
disabled={isEditing !== name} | ||
/> | ||
{isEditing === name ? ( | ||
<> | ||
<button onClick={handleSubmit}> | ||
<GiCheckMark /> | ||
</button> | ||
<button onClick={onCancel}> | ||
<RxCross1 /> | ||
</button> | ||
</> | ||
) : ( | ||
<button | ||
onClick={() => { | ||
document.getElementById(name).disabled = false; | ||
setIsEditing(name); | ||
}} | ||
> | ||
<MdOutlineModeEdit /> | ||
</button> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="container"> | ||
<h1>My Profile</h1> | ||
{Object.keys(user).length !== 0 && ( | ||
<div className="profile"> | ||
<div className="item-group"> | ||
<h2>Personal Information</h2> | ||
{item('Name', 'Name', user.name)} | ||
{item('Email', 'email', user.email)} | ||
{item('Roll No', 'rollNo', user.rollNo)} | ||
</div> | ||
<div className="item-group"> | ||
<h2>Company Information</h2> | ||
{item('Company', 'company', user.placedAt.companyName)} | ||
{item('Location', 'location', user.placedAt.location)} | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Profile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters