-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Device auth and event list selection
- Loading branch information
Showing
6 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sak:3670 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<script setup> | ||
import { useLoadingStore } from '@/stores/loading' | ||
import { ref, onMounted, watchEffect } from 'vue' | ||
import { useEventyayEventStore } from '@/stores/eventyayEvent' | ||
import StandardButton from '@/components/Common/StandardButton.vue' | ||
const loadingStore = useLoadingStore() | ||
const apiToken = ref('') | ||
const organiser = ref('') | ||
const url = ref('') | ||
const eventyayEventStore = useEventyayEventStore() | ||
const selectedEvent = ref(null) | ||
const { events, loading, error, fetchEvents } = eventyayEventStore | ||
watchEffect(() => { | ||
apiToken.value = localStorage.getItem('api_token') | ||
organiser.value = localStorage.getItem('organizer') | ||
url.value = localStorage.getItem('url') | ||
if (apiToken.value && organiser.value && url.value) { | ||
fetchEvents(url.value, apiToken.value, organiser.value) | ||
loadingStore.contentLoaded() | ||
} | ||
}) | ||
const submitForm = () => { | ||
if (selectedEvent.value) { | ||
console.log('Selected event:', selectedEvent.value) | ||
} else { | ||
console.error('Please select an event.') | ||
} | ||
} | ||
</script> | ||
<template> | ||
<div class="-mt-16 flex h-screen flex-col justify-center"> | ||
<div v-if="loading">Loading events...</div> | ||
<div v-if="error" class="text-danger">{{ error }}</div> | ||
<form v-if="events.length" @submit.prevent="submitForm"> | ||
<div v-for="event in events" :key="event.slug" class="mb-2"> | ||
<label> | ||
<input type="radio" :value="event.slug" v-model="selectedEvent" /> | ||
{{ event.name.en }} | ||
</label> | ||
</div> | ||
<div> | ||
<StandardButton | ||
:type="'submit'" | ||
:text="'Select Event'" | ||
class="btn-primary mt-6 w-full justify-center" | ||
/> | ||
</div> | ||
</form> | ||
<div v-if="!loading && !events.length && !error">No events available</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { mande } from 'mande' | ||
import { defineStore } from 'pinia' | ||
import { ref } from 'vue' | ||
|
||
export const useEventyayEventStore = defineStore('eventyayEvent', () => { | ||
const events = ref([]) | ||
const loading = ref(false) | ||
const error = ref(null) | ||
|
||
async function fetchEvents(url, apiToken, organizer) { | ||
loading.value = true | ||
error.value = null | ||
|
||
try { | ||
const api = mande(url, { headers: { Authorization: `Device ${apiToken}` } }) | ||
console.log(`/api/v1/organizers/${organizer}/events/`) | ||
const response = await api.get(`/api/v1/organizers/${organizer}/events/`) | ||
console.log('Hello', response) | ||
events.value = response.results | ||
} catch (err) { | ||
error.value = err.message | ||
} finally { | ||
loading.value = false | ||
} | ||
} | ||
|
||
return { | ||
events, | ||
loading, | ||
error, | ||
fetchEvents | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters