Skip to content

Commit 57f721b

Browse files
committed
Device auth and event list selection
1 parent 4c8f4da commit 57f721b

File tree

6 files changed

+108
-2
lines changed

6 files changed

+108
-2
lines changed

hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sak:3670
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<script setup>
2+
import { useLoadingStore } from '@/stores/loading'
3+
import { ref, onMounted, watchEffect } from 'vue'
4+
import { useEventyayEventStore } from '@/stores/eventyayEvent'
5+
import StandardButton from '@/components/Common/StandardButton.vue'
6+
const loadingStore = useLoadingStore()
7+
8+
const apiToken = ref('')
9+
const organiser = ref('')
10+
const url = ref('')
11+
const eventyayEventStore = useEventyayEventStore()
12+
const selectedEvent = ref(null)
13+
14+
const { events, loading, error, fetchEvents } = eventyayEventStore
15+
16+
watchEffect(() => {
17+
apiToken.value = localStorage.getItem('api_token')
18+
organiser.value = localStorage.getItem('organizer')
19+
url.value = localStorage.getItem('url')
20+
21+
if (apiToken.value && organiser.value && url.value) {
22+
fetchEvents(url.value, apiToken.value, organiser.value)
23+
loadingStore.contentLoaded()
24+
}
25+
})
26+
27+
const submitForm = () => {
28+
if (selectedEvent.value) {
29+
console.log('Selected event:', selectedEvent.value)
30+
} else {
31+
console.error('Please select an event.')
32+
}
33+
}
34+
</script>
35+
<template>
36+
<div class="-mt-16 flex h-screen flex-col justify-center">
37+
<div v-if="loading">Loading events...</div>
38+
<div v-if="error" class="text-danger">{{ error }}</div>
39+
<form v-if="events.length" @submit.prevent="submitForm">
40+
<div v-for="event in events" :key="event.slug" class="mb-2">
41+
<label>
42+
<input type="radio" :value="event.slug" v-model="selectedEvent" />
43+
{{ event.name.en }}
44+
</label>
45+
</div>
46+
<div>
47+
<StandardButton
48+
:type="'submit'"
49+
:text="'Select Event'"
50+
class="btn-primary mt-6 w-full justify-center"
51+
/>
52+
</div>
53+
</form>
54+
<div v-if="!loading && !events.length && !error">No events available</div>
55+
</div>
56+
</template>

src/components/Registration/Device/Device.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@ loadingStore.contentLoaded()
1111
class="-mt-16 grid h-screen w-full grid-cols-1 place-items-center items-center justify-center align-middle"
1212
>
1313
<QRCamera :qr-type="'device'" :scan-type="'Device Registration'" />
14+
<div>
15+
<input type="text" placeholder="Device Key" class="input" />
16+
<StandardButton :text="'Register Device'" class="btn-primary mt-6 w-full justify-center" />
17+
</div>
1418
</div>
1519
</template>

src/router/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import AuthTemplate from '@/AuthTemplate.vue'
22
import CheckInCamera from '@/components/CheckIn/CheckInCamera.vue'
33
import CheckInStats from '@/components/CheckIn/CheckInStats.vue'
4+
import EventyayEvents from '@/components/Eventyay/EventyayEvents.vue'
45
import Device from '@/components/Registration/Device/Device.vue'
56
import RegistrationKiosk from '@/components/Registration/Kiosk/KioskOverview.vue'
67
import RegistrationStats from '@/components/Registration/Station/RegistrationStats.vue'
@@ -26,6 +27,11 @@ const router = createRouter({
2627
name: 'device',
2728
component: Device
2829
},
30+
{
31+
path: '/eventyayevents',
32+
name: 'eventyayevents',
33+
component: EventyayEvents
34+
},
2935
{
3036
path: '/panel',
3137
name: 'auth',

src/stores/eventyayEvent.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { mande } from 'mande'
2+
import { defineStore } from 'pinia'
3+
import { ref } from 'vue'
4+
5+
export const useEventyayEventStore = defineStore('eventyayEvent', () => {
6+
const events = ref([])
7+
const loading = ref(false)
8+
const error = ref(null)
9+
10+
async function fetchEvents(url, apiToken, organizer) {
11+
loading.value = true
12+
error.value = null
13+
14+
try {
15+
const api = mande(url, { headers: { Authorization: `Device ${apiToken}` } })
16+
console.log(`/api/v1/organizers/${organizer}/events/`)
17+
const response = await api.get(`/api/v1/organizers/${organizer}/events/`)
18+
console.log('Hello', response)
19+
events.value = response.results
20+
} catch (err) {
21+
error.value = err.message
22+
} finally {
23+
loading.value = false
24+
}
25+
}
26+
27+
return {
28+
events,
29+
loading,
30+
error,
31+
fetchEvents
32+
}
33+
})

src/stores/processDevice.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { useCameraStore } from '@/stores/camera'
2+
import { mande } from 'mande'
23
import { defineStore } from 'pinia'
34
import { computed, ref } from 'vue'
4-
5+
import { useRouter } from 'vue-router'
56
export const useProcessDeviceStore = defineStore('processDevice', () => {
67
const cameraStore = useCameraStore()
7-
8+
const router = useRouter()
89
const message = ref('')
910
const showSuccess = ref(false)
1011
const showError = ref(false)
@@ -71,12 +72,17 @@ export const useProcessDeviceStore = defineStore('processDevice', () => {
7172
if (response) {
7273
const data = response
7374
console.log(data.api_token)
75+
localStorage.setItem('api_token', data.api_token)
76+
localStorage.setItem('organizer', data.organizer)
77+
localStorage.setItem('url', url)
78+
router.push({ name: 'eventyayevents' })
7479
showSuccessMsg()
7580
} else {
7681
console.log('Something happend')
7782
showErrorMsg()
7883
}
7984
} catch (error) {
85+
console.log(error)
8086
console.log('Error in catch')
8187
showErrorMsg()
8288
}

0 commit comments

Comments
 (0)