|
| 1 | +import { useCameraStore } from '@/stores/camera' |
| 2 | +import { defineStore } from 'pinia' |
| 3 | +import { computed, ref } from 'vue' |
| 4 | + |
| 5 | +export const useProcessEventyayCheckInStore = defineStore('processEventyayCheckIn', () => { |
| 6 | + const cameraStore = useCameraStore() |
| 7 | + const message = ref('') |
| 8 | + const showSuccess = ref(false) |
| 9 | + const showError = ref(false) |
| 10 | + function $reset() { |
| 11 | + message.value = '' |
| 12 | + showSuccess.value = false |
| 13 | + showError.value = false |
| 14 | + } |
| 15 | + |
| 16 | + const response = computed(() => { |
| 17 | + let classType = '' |
| 18 | + if (showSuccess.value) { |
| 19 | + classType = 'text-success' |
| 20 | + } |
| 21 | + if (showError.value) { |
| 22 | + classType = 'text-danger' |
| 23 | + } |
| 24 | + return { |
| 25 | + message: message.value, |
| 26 | + class: classType |
| 27 | + } |
| 28 | + }) |
| 29 | + |
| 30 | + function showErrorMsg() { |
| 31 | + showSuccess.value = false |
| 32 | + showError.value = true |
| 33 | + } |
| 34 | + |
| 35 | + function showSuccessMsg() { |
| 36 | + showSuccess.value = true |
| 37 | + showError.value = false |
| 38 | + } |
| 39 | + |
| 40 | + async function checkIn() { |
| 41 | + const qrData = JSON.parse(cameraStore.qrCodeValue) |
| 42 | + const event = localStorage.getItem('selectedEventName') |
| 43 | + |
| 44 | + if (qrData.event === event) { |
| 45 | + console.log(cameraStore.qrCodeValue) |
| 46 | + message.value = 'Check in successful' |
| 47 | + showSuccessMsg() |
| 48 | + } else { |
| 49 | + console.log(qrData.event) |
| 50 | + console.log(event) |
| 51 | + message.value = 'Invalid Event' |
| 52 | + showErrorMsg() |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + return { |
| 57 | + response, |
| 58 | + checkIn, |
| 59 | + $reset |
| 60 | + } |
| 61 | +}) |
0 commit comments