Skip to content
Snippets Groups Projects
Commit 9c482a7c authored by Gilgard's avatar Gilgard
Browse files

added modal for rating

parent add73472
No related branches found
No related tags found
1 merge request!98Rent history
...@@ -20,15 +20,27 @@ ...@@ -20,15 +20,27 @@
Til: {{ this.getDateString(historyItem.toTime, isMultipleDays) }} Til: {{ this.getDateString(historyItem.toTime, isMultipleDays) }}
</div> </div>
</div> </div>
<colored-button :text="'Vurder'" class="px-4 flex-1" /> <colored-button
:text="'Vurder'"
class="px-4 flex-1"
@click="
$emit('rate', {
show: true,
name: user.firstName + ' ' + user.lastName,
title: historyItem.listing.title,
rentID: historyItem.rentId,
renterIsReceiverOfRating: !currentUserIsRenter,
})
"
/>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import ColoredButton from "@/components/BaseComponents/ColoredButton.vue"; import ColoredButton from "@/components/BaseComponents/ColoredButton.vue";
import { getUser } from "@/utils/apiutil";
import { parseCurrentUser } from "@/utils/token-utils"; import { parseCurrentUser } from "@/utils/token-utils";
import userService from "@/services/user.service";
export default { export default {
name: "RentHistoryItem", name: "RentHistoryItem",
...@@ -38,6 +50,7 @@ export default { ...@@ -38,6 +50,7 @@ export default {
data() { data() {
return { return {
user: {}, user: {},
isRated: false,
}; };
}, },
props: { props: {
...@@ -75,6 +88,9 @@ export default { ...@@ -75,6 +88,9 @@ export default {
} }
return this.historyItem.listing.pricePerDay; return this.historyItem.listing.pricePerDay;
}, },
currentUserIsRenter() {
return this.isCurrentUser(this.historyItem.renterId);
},
}, },
methods: { methods: {
getDateString(milliseconds) { getDateString(milliseconds) {
...@@ -87,21 +103,19 @@ export default { ...@@ -87,21 +103,19 @@ export default {
} }
return dateString; return dateString;
}, },
async getUser(historyItem) {
if (this.isCurrentUser(historyItem.renterId)) {
this.user = await getUser(historyItem.listing.userID);
}
if (this.isCurrentUser(historyItem.listing.userID)) {
this.user = await getUser(historyItem.renterId);
}
},
isCurrentUser(id) { isCurrentUser(id) {
return id == this.currentUser.accountId; return id == this.currentUser.accountId;
}, },
}, },
beforeMount() { async beforeCreate() {
this.getUser(this.historyItem); if (this.currentUserIsRenter) {
console.log(this.user); this.user = await userService.getUserFromId(
this.historyItem.listing.userID
);
} else {
this.user = await userService.getUserFromId(this.historyItem.renterId);
}
this.isRated = await userService.isRated(this.historyItem.rentId);
}, },
}; };
</script> </script>
...@@ -27,7 +27,7 @@ const routes = [ ...@@ -27,7 +27,7 @@ const routes = [
beforeEnter: guardRoute, beforeEnter: guardRoute,
}, },
{ {
path: "/profile/rent/history", path: "/profile/history",
name: "history", name: "history",
component: () => import("../views/UserProfileViews/RentHistoryView.vue"), component: () => import("../views/UserProfileViews/RentHistoryView.vue"),
beforeEnter: guardRoute, beforeEnter: guardRoute,
......
<template> <template>
<rating-modal
:visible="modal.show"
:name="modal.name"
:title="modal.title"
:rentID="modal.rentID"
:renterIsReceiverOfRating="modal.renterIsReceiverOfRating"
@close="modal.show = false"
@reload="this.$forceUpdate()"
/>
<ul> <ul>
<li v-for="historyItem in fullHistory" :key="historyItem.rentId"> <li v-for="historyItem in fullHistory" :key="historyItem.rentId">
<rent-history-item :historyItem="historyItem" /> <rent-history-item
:historyItem="historyItem"
@rate="(modal) => openModal(modal)"
/>
</li> </li>
</ul> </ul>
</template> </template>
<script> <script>
import RentHistoryItem from "@/components/UserProfileComponents/RentHistoryComponents/RentHistoryItem.vue"; import RentHistoryItem from "@/components/UserProfileComponents/RentHistoryComponents/RentHistoryItem.vue";
import UserService from "@/services/user.service" import RatingModal from "@/components/UserProfileComponents/RatingComponents/RatingModal.vue";
import UserService from "@/services/user.service";
export default { export default {
components: { components: {
RentHistoryItem, RentHistoryItem,
RatingModal,
}, },
data() { data() {
return { return {
renterHistory: [], renterHistory: [],
ownerHistory: [], ownerHistory: [],
} modal: {
show: false,
name: "",
title: "",
rentID: -1,
renterIsReceiverOfRating: false,
},
};
}, },
computed: { computed: {
fullHistory() { fullHistory() {
...@@ -37,15 +58,18 @@ export default { ...@@ -37,15 +58,18 @@ export default {
fullHistory.sort(compareHistoryItems); fullHistory.sort(compareHistoryItems);
return fullHistory; return fullHistory;
}, },
hasNoHistory() {
return this.renterHistory.length == 0 && this.ownerHistory.length == 0;
},
}, },
methods: { methods: {
getHistories() { openModal(modal) {
this.renterHistory = UserService.getRenterHistory(); this.modal = modal;
this.ownerHistory = UserService.getOwnerHistory(); },
}
}, },
beforeMount() { async beforeCreate() {
this.getHistories() this.renterHistory = await UserService.getRenterHistory();
this.ownerHistory = await UserService.getOwnerHistory();
}, },
}; };
</script> </script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment