Newer
Older
<!-- A card for a rent history containing the item's title,
name of the person who rented it, dates/renting period, and a button
to rate if not already rated it. -->
<div
class="bg-white shadow dark:bg-gray-800 select-none cursor-pointer hover:bg-gray-50"
>
<p class="font-bold mx-4" id="title">
{{ historyItem.listing.title }}
</p>
<div class="flex flex-row items-center">
<div class="flex flex-col px-4 flex-1">
<router-link :to="{ path: '/profile/' + user.userId }">
<div>
Fra:
{{ this.getDateString(historyItem.fromTime, isMultipleDays) }}
</div>
<div>
Til: {{ this.getDateString(historyItem.toTime, isMultipleDays) }}
</div>
</div>
: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,
})
"
/>
import ColoredButton from "@/components/BaseComponents/ColoredButton.vue";
import { parseCurrentUser } from "@/utils/token-utils";
components: {
ColoredButton,
},
data() {
return {
user: {},
fromTime: Number,
toTime: Number,
isAccepted: Boolean,
listing: {
listingID: Number,
title: String,
pricePerDay: Number,
address: String,
userID: Number,
},
renterId: Number,
},
},
computed: {
currentUser() {
return parseCurrentUser();
},
//Checks if the rent period was multiple days or not
if (this.historyItem.toTime - this.historyItem.fromTime < 86400000) {
/**
* computed the total price based on how long the renting period was.
*/
price() {
if (this.isMultipleDays) {
let numDays = Math.round(
(this.historyItem.toTime - this.historyItem.fromTime) / 86400000
/**
* Checks if the user rented its own item
*/
currentUserIsRenter() {
return this.isCurrentUser(this.historyItem.renterId);
},
const shortMonthOfRentHistoryItem = date.toLocaleString("default", {
month: "short",
});
let dateString = date.getDate() + ". " + shortMonthOfRentHistoryItem;
if (date.getFullYear() != today.getFullYear()) {
dateString += "." + date.getFullYear();
}
return dateString;
},
isCurrentUser(id) {
return id == this.currentUser.accountId;
},
},
/**
* Gets the user and checks if a rating is saved, before mounting the page.
*/
async beforeCreate() {
if (this.currentUserIsRenter) {
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);