All files / munch-ease-frontend/src/components LoginPage.vue

0% Statements 0/104
0% Branches 0/1
0% Functions 0/1
0% Lines 0/104

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105                                                                                                                                                                                                                 
<template>
  <div class="login">
    <h1>Login Page</h1>
    <ul class="button-group">
      <li
        v-for="(person, index) in persons"
        :key="person.id ?? index"
      >
        <button
          type="button"
          class="btn btn-primary"
          @click="onLogin(person)"
        >
          {{ person.name }}
        </button>
      </li>
    </ul>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { getPersonsInHome } from '@/api/sdk'
import { login as loginApi } from '@/api/auth'
import type { Person } from '@/domain/types'

const props = defineProps({
  redirect: { type: String, default: '/' },
})

const router = useRouter()
const persons = ref<Person[]>([])

onMounted(async () => {
  const page = await getPersonsInHome()
  persons.value = page.items
})

async function onLogin(selectedPerson: Person) {
  const person = await loginApi(selectedPerson.name)
  if (person?.id >= 0) {
    router.push(props.redirect)
    return
  }
  alert('Login failed')
}
</script>

<style scoped>
/* Remove the default list styling */
ul {
  list-style-type: none;
  padding: 0;
}

/* Center the buttons in the middle of the page, and let them wrap */

.button-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

/* Display each button as a large round circle */

button {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  margin: 10px;
  font-size: 1.5em;

  /* Center the text in the middle of the button */
  display: flex;
  justify-content: center;
  align-items: center;

  /* Add a shadow to make the buttons look like they are floating */
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

/* Some nice flat nuetral shades for the user buttons */

li:nth-child(1) > button {
  background-color: #3939ff;
  color: white;
}

li:nth-child(2) > button {
  background-color: #156a14;
  color: white;
}

li:nth-child(3) > button {
  background-color: #325293;
  color: white;
}

li:nth-child(4) > button {
  background-color: #9a1f1f;
  color: white;
}
</style>