Skip to content

Commit

Permalink
worker profile view
Browse files Browse the repository at this point in the history
  • Loading branch information
Koryakinaisen committed Dec 16, 2024
1 parent 83ab5b2 commit 09c7357
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 33 deletions.
18 changes: 12 additions & 6 deletions frontend/src/components/ProfileSideBar.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<template>
<div class="sidebar">
<div :class="{ active: isActive('/profile/dashboard') }">
<router-link to="/profile/dashboard">
<router-link :to="{name: 'profile-dashboard', props: {role: role}}">
<p>
Мой профиль
</p>
</router-link>
</div>
<div :class="{ active: isActive('/profile/rents') }">
<router-link to="/profile/rents">
<div v-if="role === 'client'" :class="{ active: isActive('/profile/rents') }">
<router-link :to="{name: 'profile-rents', props: {role: role}}">
<p>
Мои аренды
</p>
</router-link>
</div>
<div :class="{ active: isActive('/profile/edit') }">
<router-link to="/profile/edit">
<router-link :to="{name: 'profile-edit', props: {role: role}}">
<p>
Редактировать профиль
</p>
</router-link>
</div>
<div :class="{ active: isActive('/profile/change-password') }">
<router-link to="/profile/change-password">
<router-link :to="{name: 'profile-change-password', props: {role: role}}">
<p>
Изменить пароль
</p>
Expand All @@ -41,10 +41,16 @@ import {logoutUser} from "@/services/authService.js";
export default {
name: "ProfileSideBar",
props: {
role: {
type: String,
default: "client"
}
},
methods: {
logoutUser,
isActive(route) {
return this.$route.path === route;
return this.$route.path.startsWith(route);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/TheHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default {
<button v-if="!isAuthenticated">
<img src="../assets/svg/profile.svg" alt="profile" @click="openLogin"/>
</button>
<router-link v-if="isAuthenticated" to="/profile/dashboard">
<router-link v-if="isAuthenticated" :to="{ name: 'profile-dashboard', params: {role: (isAdmin ? 'admin' : 'client')}}">
<img src="../assets/svg/profile.svg" alt="profile"/>
</router-link>
<button>
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,37 @@ const router = createRouter({
},
},
{
path: '/profile/dashboard',
path: '/profile/dashboard/:role',
name: 'profile-dashboard',
component: ProfileView,
props: true,
meta: {
requiresLogin: true
}
},
{
path: '/profile/rents',
path: '/profile/rents/:role',
name: 'profile-rents',
component: MyRents,
props: true,
meta: {
requiresLogin: true
}
},
{
path: '/profile/edit',
path: '/profile/edit/:role',
name: 'profile-edit',
component: EditProfile,
props: true,
meta: {
requiresLogin: true
}
},
{
path: '/profile/change-password',
path: '/profile/change-password/:role',
name: 'profile-change-password',
component: ChangePassword,
props: true,
meta: {
requiresLogin: true
}
Expand Down
56 changes: 56 additions & 0 deletions frontend/src/services/adminProfileServices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import axios from 'axios';
import { useToast } from 'vue-toastification'

const toast = useToast()

const API_URL = 'http://localhost:8000/api/workers';


export const getAdminProfileData = async (userData) => {
try{
const response = await axios.get(`${API_URL}/${localStorage.getItem('id')}/private`);
return response.data
} catch (error) {
const errorMessage = error.response
? error.response.data.message // Если есть ответ от сервера
: error.message || 'Ошибка соединения';
toast.error(errorMessage)
return "ERROR"
}
};

export const updateAdminProfileData = async (profileData) => {
try{
const response = await axios.patch(`${API_URL}/${localStorage.getItem('id')}`, profileData, {
headers: {
'Content-Type': 'application/json'
}
});
toast.success("Данные успешно обновлены!")
return "SUCCESS"
} catch (error) {
const errorMessage = error.response
? error.response.data.message // Если есть ответ от сервера
: error.message || 'Ошибка соединения';
toast.error(errorMessage)
return "ERROR"
}
}

export const changeAdminPassword = async (formData) => {
try{
const response = await axios.patch(`${API_URL}/${localStorage.getItem('id')}/password`, formData, {
headers: {
'Content-Type': 'application/json'
}
});
toast.success("Пароль успешно обновлен!")
return "SUCCESS"
} catch (error) {
const errorMessage = error.response
? error.response.data.message // Если есть ответ от сервера
: error.message || 'Ошибка соединения';
toast.error(errorMessage)
return "ERROR"
}
}
17 changes: 13 additions & 4 deletions frontend/src/views/profile/ChangePassword.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<UploadProgress v-if="isLoading" />
<main>
<ProfileSideBar />
<ProfileSideBar :role="role"/>
<div class="content">
<h2>Изменить пароль</h2>
<form @submit.prevent="handleSubmit" novalidate>
Expand Down Expand Up @@ -34,10 +34,12 @@ import ProfileSideBar from "@/components/ProfileSideBar.vue";
import UploadProgress from "@/components/UploadProgress.vue";
import {changePassword} from "@/services/profileServices.js";
import {useToast} from "vue-toastification";
import {changeAdminPassword} from "@/services/adminProfileServices.js";
export default {
name: "ChangePassword",
components: {UploadProgress, ProfileSideBar},
props: ['role'],
setup() {
const toast = useToast();
return {toast}
Expand Down Expand Up @@ -65,9 +67,16 @@ export default {
return
}
this.isLoading = true
changePassword(this.form).then((res) => {
this.isLoading = false
})
if(this.role === 'client'){
changePassword(this.form).then((res) => {
this.isLoading = false
})
} else {
changeAdminPassword(this.form).then((res) => {
this.isLoading = false
})
}
}
},
}
Expand Down
45 changes: 33 additions & 12 deletions frontend/src/views/profile/EditProfile.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<UploadProgress v-if="isLoading" />
<main>
<ProfileSideBar />
<ProfileSideBar :role="role" />
<div class="content">
<h2>Редактировать профиль</h2>
<form @submit.prevent="handleSubmit" novalidate>
Expand Down Expand Up @@ -54,10 +54,12 @@
import ProfileSideBar from "@/components/ProfileSideBar.vue";
import UploadProgress from "@/components/UploadProgress.vue";
import {getProfileData, updateProfileData} from "@/services/profileServices.js";
import {getAdminProfileData, updateAdminProfileData} from "@/services/adminProfileServices.js";
export default {
name: "EditProfile",
components: {UploadProgress, ProfileSideBar},
props: ['role'],
data(){
return {
isLoading: true,
Expand All @@ -72,14 +74,26 @@ export default {
}
},
beforeMount() {
getProfileData().then((data) => {
this.profile = data
this.form.newName = data.name
this.form.newSurname = data.surname
this.form.newImage = data.image
this.form.newPhone = data.phone
this.isLoading = false
})
if(this.role === 'client') {
getProfileData().then((data) => {
this.profile = data
this.form.newName = data.name
this.form.newSurname = data.surname
this.form.newImage = data.image
this.form.newPhone = data.phone
this.isLoading = false
})
}
else {
getAdminProfileData().then((data) => {
this.profile = data
this.form.newName = data.name
this.form.newSurname = data.surname
this.form.newImage = data.image
this.form.newPhone = data.phone
this.isLoading = false
})
}
},
computed: {
isButtonDisabled() {
Expand Down Expand Up @@ -115,9 +129,16 @@ export default {
if(this.form.newPhone !== this.profile.phone){
data.phone = this.form.newPhone
}
updateProfileData(data).then((res) => {
this.isLoading = false
})
if(this.role === 'client'){
updateProfileData(data).then((res) => {
this.isLoading = false
})
} else {
updateAdminProfileData(data).then((res) => {
this.isLoading = false
})
}
}
},
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/views/profile/MyRents.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<main>
<ProfileSideBar />
<ProfileSideBar :role="role"/>
</main>
</template>

Expand All @@ -9,6 +9,7 @@ import ProfileSideBar from "@/components/ProfileSideBar.vue";
export default {
name: "MyRents",
props: ['role'],
components: {ProfileSideBar}
}
</script>
Expand Down
38 changes: 33 additions & 5 deletions frontend/src/views/profile/ProfileView.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<UploadProgress v-if="isLoading" />
<main>
<ProfileSideBar />
<ProfileSideBar :role="role"/>
<div class="content">
<div class="img-container" :style="backgroundImageStyle"></div>
<div class="name-email">
Expand All @@ -12,6 +12,14 @@
{{profile.email}}
</p>
</div>
<div class="ml-32">
<p v-if="profile.jobTitle" class="phone">
Должность: {{profile.jobTitle}}
</p>
<p v-if="profile.phone" class="phone">
Контакты: {{profile.phone}}
</p>
</div>
</div>
</main>

Expand All @@ -21,6 +29,7 @@
import ProfileSideBar from "@/components/ProfileSideBar.vue";
import {getProfileData} from "@/services/profileServices.js";
import UploadProgress from "@/components/UploadProgress.vue";
import {getAdminProfileData} from "@/services/adminProfileServices.js";
export default {
name: "ProfileView",
Expand All @@ -31,11 +40,21 @@ export default {
profile: {}
}
},
props: ['role'],
beforeMount() {
getProfileData().then((data) => {
this.profile = data
this.isLoading = false
})
if(this.role === 'client'){
getProfileData().then((data) => {
this.profile = data
this.isLoading = false
})
}
else {
getAdminProfileData().then((data) => {
this.profile = data
this.isLoading = false
})
}
},
computed: {
backgroundImageStyle() {
Expand Down Expand Up @@ -86,4 +105,13 @@ main {
font-size: 20px;
font-weight: 600;
}
.ml-32 {
margin-left: 64px;
}
.phone {
font-weight: 500;
font-size: 18px;
}
</style>

0 comments on commit 09c7357

Please sign in to comment.