Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d5338d9
Create user profile image
ilham-saleh Feb 16, 2024
2483071
small changes to profile page
ilham-saleh Feb 16, 2024
761b276
FEAT: added dummy data, some new placeholders
PeachyOmnivore Feb 19, 2024
61578a7
BUILD: CSS page and formatting of look.
PeachyOmnivore Feb 19, 2024
d3bc3c9
FEAT: spacing under header.
PeachyOmnivore Feb 19, 2024
41f3378
ADD: new translation.
PeachyOmnivore Feb 19, 2024
5da86cf
FEAT: disabled capability
PeachyOmnivore Feb 19, 2024
6637e3b
FEAT: starting disabled functionality
PeachyOmnivore Feb 19, 2024
4044c1b
ADD: "Save" to translations.
PeachyOmnivore Feb 19, 2024
a95572a
FEAT: some button CSS
PeachyOmnivore Feb 19, 2024
b957c57
FEAT: button flipper.
PeachyOmnivore Feb 19, 2024
6e534b5
FEAT: working CSS for save button.
PeachyOmnivore Feb 19, 2024
0e08d1b
FEAT: flipping capability to buttons.
PeachyOmnivore Feb 19, 2024
f2a2c69
BUILD: functions for future use.
PeachyOmnivore Feb 19, 2024
edce053
Merge branch 'main' into 189-create-user-profile-page
PeachyOmnivore Feb 20, 2024
563b5ba
RENAME: wrongly named file removed and added in right name.
PeachyOmnivore Feb 20, 2024
7700047
FEAT: new components added.
PeachyOmnivore Feb 20, 2024
33ae68c
Merge branch 'main' into 189-create-user-profile-page
PeachyOmnivore Feb 20, 2024
97447b4
FEAT: state built for holding temp user information.
PeachyOmnivore Feb 20, 2024
07c4955
FEAT: profile page now locks text and changes style based on if editing.
PeachyOmnivore Feb 20, 2024
d60dc41
FEAT: splitword is working, all components have new conditional style
PeachyOmnivore Feb 20, 2024
eef10cf
FEAT: Revert function works.
PeachyOmnivore Feb 20, 2024
0544233
UPDATE: preparing for get request.
PeachyOmnivore Feb 20, 2024
d77d90b
FEAT: retrieving users.
PeachyOmnivore Feb 20, 2024
7c64f3d
Merge branch 'main' into 189-create-user-profile-page
PeachyOmnivore Feb 20, 2024
53ffb4a
SAVE: Commiting current work for move to another branch.
PeachyOmnivore Feb 20, 2024
8e3929f
Merge branch 'main' into 189-create-user-profile-page
PeachyOmnivore Feb 20, 2024
3ffe679
Playing around with cancel button.
PeachyOmnivore Feb 22, 2024
6ae8141
FIX: dummy data
PeachyOmnivore Feb 22, 2024
3206e9e
Merge branch 'main' into 189-create-user-profile-page
PeachyOmnivore Feb 22, 2024
87c83db
BUILD: apiClient getUserProfileById()
PeachyOmnivore Feb 23, 2024
3ec87cc
UPDATE: new GET request added
PeachyOmnivore Feb 23, 2024
29d8374
Merge branch 'main' into 189-create-user-profile-page
PeachyOmnivore Feb 23, 2024
6ed88e1
FEAT: UpdateProfile on save
PeachyOmnivore Feb 23, 2024
9959ac1
UPDATE: where profile info comes from.
PeachyOmnivore Feb 23, 2024
73ac371
UPDATE: Save function also resets tempUser.
PeachyOmnivore Feb 23, 2024
07aa166
Merge branch 'main' into 189-create-user-profile-page
PeachyOmnivore Feb 23, 2024
8384688
FEAT: checks for teacher role.
PeachyOmnivore Feb 23, 2024
d3e3915
FEAT: mostly working profile page
PeachyOmnivore Feb 23, 2024
98aa8cb
REMOVE: setIsTeacher. Not implemented.
PeachyOmnivore Feb 23, 2024
57cea16
Merge branch 'main' into 189-create-user-profile-page
PeachyOmnivore Feb 23, 2024
04745d2
FEAT: Buttons only appear if you are viewing your profile.
PeachyOmnivore Feb 23, 2024
e22e4b4
FIX: changed isTeacher to false.
PeachyOmnivore Feb 23, 2024
a7c6c09
FEAT: added console.logs
PeachyOmnivore Feb 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
text-align: center;
}

.profile-container {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
gap: 4rem;
}

.headshot {
width: 50px;
height: 50px;
Expand Down
11 changes: 11 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Welcome from "./pages/welcome"
import MyCohort from "./pages/myCohort"
import Cohorts from "./pages/cohorts"
import UserSearchResult from "./pages/UserSearchResult"
import UserProfile from "./pages/userProfile"


const App = () => {
return (
Expand All @@ -23,6 +25,15 @@ const App = () => {
<Route path="loading" element={<Loading />} />
<Route path="verification" element={<Verification />} />

<Route
path="profile/:id"
element={
<ProtectedRoute>
<UserProfile />
</ProtectedRoute>
}
/>

<Route
index
element={
Expand Down
4 changes: 3 additions & 1 deletion src/components/form/textInput/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useState } from "react";

const TextInput = ({ value, onChange, name, label, icon, type = "text" , placeholder, required}) => {
const TextInput = ({ value, onChange, name, label, icon, type = "text" , placeholder, required, disabled}) => {
const [input, setInput] = useState("");
const [showpassword, setShowpassword] = useState(false);
if (type === "password") {
return (
<div className="inputwrapper">
<label htmlFor={name}>{label}</label>
<input
disabled={disabled}
type={type}
name={name}
value={value}
Expand Down Expand Up @@ -44,6 +45,7 @@ const TextInput = ({ value, onChange, name, label, icon, type = "text" , placeho
<div className="inputwrapper">
{label && <label htmlFor={name}>{label}</label>}
<input
disabled={disabled}
type={type}
name={name}
value={value}
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"register": "Register",
"required": "Required",
"requiredFields": "Required fields need to be complete",
"save" : "Save",
"searchResults": "Search Results",
"seeExercises": "See Exercises",
"sendMessage": "send message",
Expand All @@ -78,6 +79,7 @@
"submit": "Submit",
"teachers": "Teachers",
"tellUsAboutYourselfMessage": "Tell use about yourself, your educational and professional highlight to date",
"trainingInfo" : "Training Info",
"units": "Units",
"uploadValidImage": "Please upload a valid image file",
"userExist": "Already a user?",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/sv/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"register": "Registrera dig",
"required": "Obligatorisk",
"requiredFields": "Fyll i alla obligatoriska fält",
"save" : "Spara",
"searchResults": "Sökresultat",
"seeExercises": "Visa övningar",
"sendMessage": "Skicka meddelande",
Expand All @@ -78,6 +79,7 @@
"submit": "Skicka in",
"teachers": "Lärare",
"tellUsAboutYourselfMessage": "Berätta om dig själv, din pedagogiska och professionella höjdpunkt hittills",
"trainingInfo" : "Skolningsinformation",
"units": "Enheter",
"uploadValidImage": "Ladda upp en giltig bildfil",
"userExist": "Redan en användare?",
Expand Down
215 changes: 215 additions & 0 deletions src/pages/userProfile/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
import { useTranslation } from "react-i18next"
import Card from "../../components/card"
import ProfileCircle from "../../components/profileCircle"
import "./style.css"
import { useContext, useEffect, useState } from "react"
import { useParams } from "react-router-dom"
import {
getUserById,
getUserProfileById,
updateProfile,
} from "../../service/apiClient.js"
import Button from "../../components/button"
import BasicInfo from "../../components/basic-info"
import ContactInfo from "../../components/contactInfo"
import TrainingInfo from "../../components/trainingInfo"
import Bio from "../../components/bio"
import ProfessionalInfo from "../../components/professionalinfo"
import { AuthContext } from "../../context/auth"

const UserProfile = () => {
const currentUserId = useContext(AuthContext).userId
const { t } = useTranslation()
const { id } = useParams()
const [disabledText, setDisabledText] = useState(true)
const [saveButton, setSave] = useState(false)
const [isTeacher] = useState(false)
const [user, setUser] = useState()
const [profile, setProfile] = useState({
firstName: "",
lastName: "",
githubUsername: "",
bio: "",
email: "",
mobile: "",
password: "",
role: "",
specialism: "",
cohort: "",
startDate: "",
endDate: "",
imageUrl: "",
})
const [tempUser, setTempUser] = useState(profile)

useEffect(() => {
getUserProfileById(id).then((profile) => {
setProfile(profile.data.profile)
setTempUser(profile.data.profile)
})

getUserById(id).then((user) => {
setUser(user.data.user)
})
}, [id])

console.log("USER INFORMATION ---->", user)
console.log("PROFILE INFORMATION ---->", profile)

const initials =
profile && profile.firstName && profile.lastName
? `${profile.firstName.charAt(0)}${profile.lastName.charAt(0)}`
: "A"

let classes = ""
if (saveButton === false) {
classes = "locked-input"
}

// const splitWord = profile.bio.trim(/\s+/g, "").length

const onInput = (event) => {
const { name, value } = event.target

setProfile({
...profile,
[name]: value,
})
}

const revert = () => {
setProfile(tempUser)
console.log("revert")
return
}

const save = () => {
updateProfile(
id,
profile.firstName,
profile.lastName,
profile.githubUsername,
profile.bio,
profile.email,
profile.mobile,
profile.password,
profile.role,
profile.specialism,
profile.cohort,
profile.startDate,
profile.endDate,
profile.imageUrl
)
setTempUser(profile)
console.log("save")
return
}

const checkCurrentUser = () => {
console.log("CURRENT ID", currentUserId, "PROFILE ID", id)
if (Number(currentUserId) === Number(id)) {
return (
<div className="profile-buttons">
<Button
text={t("cancel")}
onClick={() => {
setSave(false)
setDisabledText(true)
revert()
}}
/>

{saveButton ? (
<Button
classes="saveButton"
text={t("save")}
onClick={() => {
setSave(false)
setDisabledText(true)
save()
}}
/>
) : (
<Button
text={t("edit")}
onClick={() => {
setSave(true)
setDisabledText(false)
}}
/>
)}
</div>
)
}
}

return (
<main>
<div className="welcome">
<h2>{t("profile")}</h2>
</div>

<Card>
<div className="profile-information">
<ProfileCircle initials={initials} />
<section>
<h4>
{profile.firstName} {profile.lastName}
</h4>
{/* <p>{user.title}</p> */}
</section>
</div>

<div className="profile-container">
<section className={`${classes}`}>
<BasicInfo
onInput={onInput}
disabledText={disabledText}
data={profile}
/>
</section>

{isTeacher ? (
<section className={`${classes}`}>
<ProfessionalInfo
onInput={onInput}
disabledText={disabledText}
data={profile}
/>
</section>
) : (
<section className={`${classes}`}>
<TrainingInfo
onInput={onInput}
disabledText={disabledText}
data={profile}
/>
</section>
)}

<section className={`${classes}`}>
<ContactInfo
onInput={onInput}
disabledText={disabledText}
data={profile}
/>
</section>

<section className={`${classes}`}>
<Bio
onInput={onInput}
disabledText={disabledText}
data={profile}
// splitWord={splitWord}
/>
</section>
</div>

<p className="text-blue1">{`*${t("required")}`}</p>
{checkCurrentUser()}
</Card>
</main>
)
}

export default UserProfile
43 changes: 43 additions & 0 deletions src/pages/userProfile/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.profile-information {
display: grid;
grid-template-columns: 70px 1fr;
}

.welcome-formheader {
border-top: solid rgba(128, 128, 128, 0.226) 2px;
margin-top: 20px;
padding-top: 20px;
}

.welcome {
margin-bottom: 20px;
}

.profile-buttons {
display: grid;
grid-template-columns: 170px 170px;
gap: 20px;
justify-content: end;
}

.profile-buttons > button {
background-color: #F0F5FA;
color: #64648C;
cursor: pointer;
}

.profile-buttons > .saveButton {
background-color: #000046;
color: #ffffff;
cursor: pointer;
}

.locked-input form input {
background: white;
color: black;
}

.locked-input textarea {
background: white;
color: black;
}
15 changes: 10 additions & 5 deletions src/service/apiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function postComment(comment) {

async function getCohorts() {
const res = await get("cohorts")
return res.data
return res.data
}

async function getTeachers() {
Expand Down Expand Up @@ -96,8 +96,12 @@ async function getUsers() {
}

async function getUserById(userId) {
  return get(`users/${userId}`)
}
return get(`users/${userId}`)
}

async function getUserProfileById(userId) {
return get(`users/profile/${userId}`)
}

async function put(endpoint, data, auth = true) {
return await request("PUT", endpoint, data, auth)
Expand Down Expand Up @@ -142,7 +146,7 @@ async function toggleLike(postId) {
}

async function getStudents() {
const response = await get('students')
const response = await get("students")
return response.data.students
}

Expand All @@ -166,5 +170,6 @@ export {
getUserById,
getStudents,
getSelfTeacher,
getSelfStudent
getSelfStudent,
getUserProfileById
}