Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

113 rader
2.5 KiB

  1. <template>
  2. <div class="invalidation-view">
  3. <qrcode-stream
  4. v-if="!token"
  5. @decode="onDecode"
  6. @init="onInit">
  7. </qrcode-stream>
  8. <div v-else>
  9. <div v-if="status && !status.valid">
  10. reservation {{ token }} from {{status.anzeigename}} is not valid!<br>
  11. reason: {{status.reason || status.detail}}<br><br>
  12. <button @click="onReset" class="btn reset-btn">reset</button>
  13. </div>
  14. <div v-if="status && status.valid">
  15. reservation from {{status.anzeigename}} is valid :) <br>
  16. <div>
  17. <button @click="onInvalidate" class="btn invalidate-btn">invalidate now</button>
  18. <button @click="onReset" class="btn reset-btn">reset</button>
  19. </div>
  20. <div v-if="error">
  21. {{error}}
  22. </div>
  23. </div>
  24. </div>
  25. <!-- {{status}} -->
  26. </div>
  27. </template>
  28. <script>
  29. import { QrcodeStream } from 'vue-qrcode-reader'
  30. export default {
  31. name: 'Invalidate',
  32. components: {
  33. QrcodeStream,
  34. },
  35. data() {
  36. return {
  37. token: null,
  38. status: null,
  39. success: null,
  40. error: null,
  41. }
  42. },
  43. methods: {
  44. async onDecode(token) {
  45. this.token = token
  46. this.status = await this.getStatus(token)
  47. },
  48. async getStatus (token) {
  49. const response = await fetch(`${process.env.VUE_APP_API_URL}guest/${token}`)
  50. const data = await response.json()
  51. return data
  52. },
  53. onInit(promise) {
  54. promise
  55. .then(console.log)
  56. .catch(console.error)
  57. },
  58. onReset() {
  59. this.token = null
  60. this.status = null
  61. this.success = null
  62. this.error = null
  63. },
  64. async onInvalidate() {
  65. let data = {
  66. token: this.token
  67. }
  68. const response = await fetch(
  69. `${process.env.VUE_APP_API_URL}guest/invalidate`, {
  70. method: 'POST',
  71. headers: { 'Content-Type': 'application/json' },
  72. body: JSON.stringify(data),
  73. }
  74. )
  75. if (response.status === 200) {
  76. this.success = true
  77. this.onReset()
  78. } else {
  79. this.error = await response.json()
  80. }
  81. }
  82. },
  83. }
  84. </script>
  85. <style>
  86. .invalidation-view {
  87. min-height: 100vh;
  88. display: flex;
  89. align-items: center;
  90. justify-content: center;
  91. text-align: center;
  92. }
  93. .btn {
  94. padding: 1em;
  95. font-size: 2em;
  96. border: none;
  97. outline: none;
  98. margin: .2em 0;
  99. }
  100. .invalidate-btn {
  101. background: rgb(255, 255, 255);
  102. color: #000;
  103. margin-right: 1em;
  104. }
  105. .reset-btn {
  106. background: rgb(138, 138, 138);
  107. color: #000;
  108. }
  109. </style>