Skip to content
Snippets Groups Projects
UserProfile.vue 6.05 KiB
Newer Older
Gilgard's avatar
Gilgard committed
<template>
  <div
    class="w-full max-w-xl m-auto md:ring-1 ring-gray-300 overflow-hidden rounded-xl p-4"
Håkon Eilertsen Røskaft's avatar
Håkon Eilertsen Røskaft committed
    <DeleteUserModal
      :visible="show"
      @close="this.show = false"
      @deleteUser="deleteUser"
    />
Titus Netland's avatar
Titus Netland committed
    <div v-show="isCurrentUser" class="float-right px-4 pt-4">
      <button
Gilgard's avatar
Gilgard committed
        id="dropdownDefault"
        data-dropdown-toggle="dropdown"
Gilgard's avatar
Gilgard committed
        @click="dropdown = !dropdown"
Titus Netland's avatar
Titus Netland committed
        class="w-10 h-10 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 rounded-lg float-right text-sm p-1.5"
        type="button"
      >
        <svg
          class="w-6 h-6"
          fill="currentColor"
          viewBox="0 0 20 20"
          xmlns="http://www.w3.org/2000/svg"
        >
          <path
            d="M10 6a2 2 0 110-4 2 2 0 010 4zM10 12a2 2 0 110-4 2 2 0 010 4zM10 18a2 2 0 110-4 2 2 0 010 4z"
          ></path>
        </svg>
      </button>
Gilgard's avatar
Gilgard committed

      <div
        id="dropdown"
Gilgard's avatar
Gilgard committed
        v-show="dropdown"
Gilgard's avatar
Gilgard committed
        class="z-10 w-44 text-base list-none bg-white rounded divide-y divide-gray-100 shadow dark:bg-gray-700"
Gilgard's avatar
Gilgard committed
        <ul
          class="py-1 absolute bg-white ring-1 ring-gray-300 rounded-xl"
          aria-labelledby="dropdownDefault"
        >
          <li>
            <router-link
henrikburmann's avatar
henrikburmann committed
              to="/user/userItems"
              class="block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"
              >Mine gjenstander</router-link
            >
          </li>
          <li>
            <router-link
Gilgard's avatar
Gilgard committed
              :to="'/profile/communities'"
              class="block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"
              >Mine grupper
            </router-link>
          </li>
          <li>
            <router-link
Titus Netland's avatar
Titus Netland committed
              to="/profile/history"
              class="block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"
              >Leiehistorikk</router-link
            >
          </li>
          <li>
            <div
Gilgard's avatar
Gilgard committed
              @click="logout"
              class="cursor-pointer block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"
            >
              Logg ut
            </div>
          </li>
          <li>
            <router-link
Gilgard's avatar
Gilgard committed
              to="/newPassword"
              class="block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"
              >Endre passord</router-link
            >
          </li>
          <li>
Håkon Eilertsen Røskaft's avatar
Håkon Eilertsen Røskaft committed
            <div
              class="block py-2 px-4 text-sm text-error-dark cursor-pointer"
              @click="toggleModal"
            >
Titus Netland's avatar
Titus Netland committed
              Slett bruker
            </div>
          </li>
        </ul>
      </div>
    </div>
Gilgard's avatar
Gilgard committed

Titus Netland's avatar
Titus Netland committed
    <div class="flex flex-col items-center pb-10 mt-16 z-5">
      <img
        class="mb-3 w-24 h-24 rounded-full shadow-lg"
        :src="getProfilePicture"
        alt="Profile picture"
      />
      <h5 class="mb-1 text-xl font-medium text-gray-900 dark:text-white">
Gilgard's avatar
Gilgard committed
        {{ user.firstName }} {{ user.lastName }}
      </h5>
      <div>
        <rating-component :rating="renterRating" :ratingType="'Leietaker'" />
        <rating-component :rating="ownerRating" :ratingType="'Utleier'" />
      </div>
Gilgard's avatar
Gilgard committed

      <div v-show="!isCurrentUser" @click="$router.push('/messages?userID=' + id)" class="flex mt-4 space-x-3 lg:mt-6">
        <a
          href="#"
          class="inline-flex items-center py-2 px-4 text-sm font-medium text-center text-gray-900 bg-white rounded-lg border border-gray-300 hover:bg-gray-100 focus:ring-4 focus:outline-none focus:ring-gray-200 dark:bg-gray-800 dark:text-white dark:border-gray-600 dark:hover:bg-gray-700 dark:hover:border-gray-700 dark:focus:ring-gray-700"
          >Åpne chat</a
        >
      </div>
    </div>
  </div>
Gilgard's avatar
Gilgard committed
</template>

<script>
Gilgard's avatar
Gilgard committed
import RatingComponent from "@/components/UserProfileComponents/RatingComponents/Rating.vue";
Gilgard's avatar
Gilgard committed
import { parseCurrentUser } from "@/utils/token-utils";
Gilgard's avatar
Gilgard committed
import { getUser } from "@/utils/apiutil";
import UserService from "@/services/user.service";
Titus Netland's avatar
Titus Netland committed
import DeleteUserModal from "@/components/UserAuthComponents/DeleteUserModal";
Gilgard's avatar
Gilgard committed

export default {
  name: "LargeProfileCard",
  data() {
    return {
      user: {},
      currentUser: {},
      id: -1,
      isCurrentUser: false,
Gilgard's avatar
Gilgard committed
      renterRating: -1,
      ownerRating: -1,
Gilgard's avatar
Gilgard committed
      dropdown: false,
      profileImage: {
        src: require("../../assets/defaultUserProfileImage.jpg"),
      },
Titus Netland's avatar
Titus Netland committed
      show: false,
Gilgard's avatar
Gilgard committed
    };
  },
  components: {
    RatingComponent,
Titus Netland's avatar
Titus Netland committed
    DeleteUserModal,
Gilgard's avatar
Gilgard committed
  },
  computed: {
    getProfilePicture() {
      if (this.user.picture !== "" && this.user.picture != null) {
        return this.user.picture;
      }
      return this.profileImage.src;
    },
    adminList() {
      return this.$store.state.user.adminList;
    },
  methods: {
    async getUser() {
Gilgard's avatar
Gilgard committed
      this.currentUser = await parseCurrentUser();
      this.id = await this.$router.currentRoute.value.params.id;

      if (this.id === this.currentUser.accountId) {
        this.isCurrentUser = true;
        this.user = this.currentUser;
        this.user = await UserService.getUserFromId(this.user.accountId);
Gilgard's avatar
Gilgard committed
      this.user = await getUser(this.id);
      let ratingAsOwner = await UserService.getUserRatingAsOwner(this.id);
Gilgard's avatar
Gilgard committed
      let ratingAsRenter = await UserService.getUserRatingAsRenter(this.id);

      if (ratingAsOwner >= 0 && ratingAsOwner <= 5) {
        this.ownerRating = ratingAsOwner;
      }
Gilgard's avatar
Gilgard committed
      if (ratingAsRenter >= 0 && ratingAsRenter <= 5) {
        this.renterRating = ratingAsRenter;
Gilgard's avatar
Gilgard committed
      }
Gilgard's avatar
Gilgard committed
    logout() {
      this.$store.commit("logout");
      this.$router.push("/");
    },
Titus Netland's avatar
Titus Netland committed
    toggleModal() {
      this.show = !this.show;
    },
Håkon Eilertsen Røskaft's avatar
Håkon Eilertsen Røskaft committed
    async deleteUser() {
Titus Netland's avatar
Titus Netland committed
      await UserService.deleteUser();
Håkon Eilertsen Røskaft's avatar
Håkon Eilertsen Røskaft committed
      this.logout();
Gilgard's avatar
Gilgard committed
  },
  beforeMount() {
    this.getUser();
  },
Gilgard's avatar
Gilgard committed
};
</script>