Skip to content
Snippets Groups Projects
NewRent.vue 5.16 KiB
Newer Older
henrikburmann's avatar
henrikburmann committed
<template>
henrikburmann's avatar
henrikburmann committed
  <div id="confirmationBox">
    <div id="rentTitle">
henrikburmann's avatar
henrikburmann committed
      <h1>
        {{ title }}
henrikburmann's avatar
henrikburmann committed
      </h1>
    </div>
henrikburmann's avatar
henrikburmann committed
    <div id="fromTime">
      <p>Fra: {{ fromTimeString }}</p>
henrikburmann's avatar
henrikburmann committed
    </div>
henrikburmann's avatar
henrikburmann committed
    <div id="toTime">
      <p>Til: {{ toTimeString }}</p>
henrikburmann's avatar
henrikburmann committed
    </div>
henrikburmann's avatar
henrikburmann committed
    <div id="price">
      <p>Totaltpris: {{ price }} kr</p>
henrikburmann's avatar
henrikburmann committed
    </div>
henrikburmann's avatar
henrikburmann committed
    <div id="message">
henrikburmann's avatar
henrikburmann committed
      <label
        class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-400"
        id="descriptionLabel"
henrikburmann's avatar
henrikburmann committed
        >Skriv en melding til utleier:</label
henrikburmann's avatar
henrikburmann committed
      >
      <textarea
        id="description"
        rows="4"
        v-model="message"
        class="block p-2.5 w-full text-sm text-gray-900 bg-gray-200 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
        required
      ></textarea>
henrikburmann's avatar
henrikburmann committed
    </div>
henrikburmann's avatar
henrikburmann committed
    <button id="cancelButton" @click="cancelRent" class="text-primary-medium">
      Tilbake
    </button>
henrikburmann's avatar
henrikburmann committed
    <div id="confirm">
henrikburmann's avatar
henrikburmann committed
      <colored-button
        id="confirmButton"
        @click="sendRent"
        :text="'Send'"
      ></colored-button>
henrikburmann's avatar
henrikburmann committed
    </div>
  </div>
  <div>
henrikburmann's avatar
henrikburmann committed
    <notification-modal
henrikburmann's avatar
henrikburmann committed
      @click="routeToHome"
      :visible="confirmed"
      :title="'Vellykket'"
      :message="'Forespørsel sendt!'"
    >
    </notification-modal>
  </div>
henrikburmann's avatar
henrikburmann committed
</template>

<script>
henrikburmann's avatar
henrikburmann committed
import ColoredButton from "@/components/BaseComponents/ColoredButton.vue";
import { postNewRent } from "@/utils/apiutil";
henrikburmann's avatar
henrikburmann committed
import NotificationModal from "@/components/BaseComponents/NotificationModal.vue";
henrikburmann's avatar
henrikburmann committed
export default {
  name: "NewRent",
henrikburmann's avatar
henrikburmann committed
  components: {
    ColoredButton,
henrikburmann's avatar
henrikburmann committed
    NotificationModal,
henrikburmann's avatar
henrikburmann committed
  },
henrikburmann's avatar
henrikburmann committed
  data() {
    return {
      confirmed: false,
henrikburmann's avatar
henrikburmann committed
      title: this.newRentBox.title,
      fromTime: this.newRentBox.fromTime,
henrikburmann's avatar
henrikburmann committed
      fromTimeString: "",
      toTime: this.newRentBox.toTime,
henrikburmann's avatar
henrikburmann committed
      toTimeString: "",
      fromTimeMilliseconds: new Date(this.newRentBox.fromTime).valueOf(),
      toTimeMilliseconds: new Date(this.newRentBox.toTime).valueOf(),
henrikburmann's avatar
henrikburmann committed
      message: "",
henrikburmann's avatar
henrikburmann committed
      price: this.newRentBox.price,
henrikburmann's avatar
henrikburmann committed
    };
  },
  props: {
    newRentBox: {
henrikburmann's avatar
henrikburmann committed
      renterId: Number,
henrikburmann's avatar
henrikburmann committed
      title: String,
henrikburmann's avatar
henrikburmann committed
      fromTime: Date,
      toTime: Date,
      listingID: Number,
      isAccepted: Boolean,
henrikburmann's avatar
henrikburmann committed
      price: Number,
henrikburmann's avatar
henrikburmann committed
    },
  },
henrikburmann's avatar
henrikburmann committed
  created() {
    this.fromTimeString = this.convertDates(this.fromTime);
    this.toTimeString = this.convertDates(this.toTime);
  },

henrikburmann's avatar
henrikburmann committed
  methods: {
    //Converts Date-object to a more readable string
henrikburmann's avatar
henrikburmann committed
    convertDates(date) {
      //Copies the chosen date
henrikburmann's avatar
henrikburmann committed
      const dateCopy = new Date(date);
      //Gets the day part of date (1-31)
henrikburmann's avatar
henrikburmann committed
      const dateDate = dateCopy.getDate();
      //Gets the month of the date (1-12)
henrikburmann's avatar
henrikburmann committed
      const dateMonth = dateCopy.getMonth();
      let monthString = "";
      //Gives the month the proper name
henrikburmann's avatar
henrikburmann committed
      switch (dateMonth) {
        case 0:
henrikburmann's avatar
henrikburmann committed
          monthString = "Januar";
          break;
        case 1:
henrikburmann's avatar
henrikburmann committed
          monthString = "Februar";
          break;
        case 2:
henrikburmann's avatar
henrikburmann committed
          monthString = "Mars";
          break;
        case 3:
henrikburmann's avatar
henrikburmann committed
          monthString = "April";
          break;
        case 4:
henrikburmann's avatar
henrikburmann committed
          monthString = "Mai";
          break;
        case 5:
henrikburmann's avatar
henrikburmann committed
          monthString = "Juni";
          break;
        case 6:
henrikburmann's avatar
henrikburmann committed
          monthString = "Juli";
          break;
        case 7:
henrikburmann's avatar
henrikburmann committed
          monthString = "August";
          break;
        case 8:
henrikburmann's avatar
henrikburmann committed
          monthString = "September";
          break;
        case 9:
henrikburmann's avatar
henrikburmann committed
          monthString = "Oktober";
          break;
        case 10:
henrikburmann's avatar
henrikburmann committed
          monthString = "November";
          break;
        case 11:
henrikburmann's avatar
henrikburmann committed
          monthString = "Desember";
          break;
        default:
          monthString = "Noe feil";
          break;
      }
      //Gets the year of the date
henrikburmann's avatar
henrikburmann committed
      const dateYear = dateCopy.getFullYear();
      return dateDate + ". " + monthString + " " + dateYear;
    },
henrikburmann's avatar
henrikburmann committed
    cancelRent() {
      this.$router.go(0);
    },
henrikburmann's avatar
henrikburmann committed
    routeToHome() {
      this.$router.push("/messages?userID=" + this.newRentBox.renterId);
henrikburmann's avatar
henrikburmann committed
    },
henrikburmann's avatar
henrikburmann committed
    sendRent: async function () {
henrikburmann's avatar
henrikburmann committed
      const rent = {
        renterId: 0,
        message: this.message,
        listingId: this.newRentBox.listingID,
henrikburmann's avatar
henrikburmann committed
        isAccepted: false,
        toTime: this.toTimeMilliseconds,
henrikburmann's avatar
henrikburmann committed
        fromTime: this.fromTimeMilliseconds,
henrikburmann's avatar
henrikburmann committed

henrikburmann's avatar
henrikburmann committed
      await postNewRent(rent);
      this.confirmed = true;
<style scoped>
henrikburmann's avatar
henrikburmann committed
#confirmationBox {
  border: 1px solid silver;
henrikburmann's avatar
henrikburmann committed
  margin-top: 60fr;
  padding: 10%;
  width: 80%;
henrikburmann's avatar
henrikburmann committed
  margin: auto;
  display: grid;
  grid-template-columns: 1fr 3fr;
henrikburmann's avatar
henrikburmann committed
  grid-template-rows: 0.5fr 1.5fr 0.7fr 0.7fr 0.7fr 3fr 1fr;
  /* max-height: 100%; */
  margin-top: 10%;
henrikburmann's avatar
henrikburmann committed
#cancelButton {
  grid-column: 1/2;
  grid-row: 1/2;
henrikburmann's avatar
henrikburmann committed
#rentTitle {
henrikburmann's avatar
henrikburmann committed
  margin-top: 10%;
  text-align: center;
  grid-column: 1/3;
henrikburmann's avatar
henrikburmann committed
  grid-row: 2/3;
  font-weight: bold;
}
henrikburmann's avatar
henrikburmann committed
#fromTime {
  grid-row: 3/4;
henrikburmann's avatar
henrikburmann committed
  grid-column: 1/3;
  display: block;
}
henrikburmann's avatar
henrikburmann committed
#toTime {
  grid-row: 4/5;
henrikburmann's avatar
henrikburmann committed
  grid-column: 1/3;
  display: block;
}
henrikburmann's avatar
henrikburmann committed
#price {
  grid-row: 5/6;
henrikburmann's avatar
henrikburmann committed
  grid-column: 1/3;
henrikburmann's avatar
henrikburmann committed
#message {
henrikburmann's avatar
henrikburmann committed
  grid-column: 1/3;
  grid-row: 6/7;
henrikburmann's avatar
henrikburmann committed
}
henrikburmann's avatar
henrikburmann committed
#confirm {
henrikburmann's avatar
henrikburmann committed
  grid-column: 1/3;
  grid-row: 7/8;
henrikburmann's avatar
henrikburmann committed
  align-content: center;
  margin: auto;
  margin-top: 10px;
henrikburmann's avatar
henrikburmann committed
}
</style>