Skip to content

Commit 67e1679

Browse files
committed
Add Lead API and Check-in API
1 parent b505113 commit 67e1679

12 files changed

+219
-58
lines changed

src/components/Common/QRCamera.vue

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { useProcessRegistrationStore } from '@/stores/processRegistration'
66
import { useProcessCheckInStore } from '@/stores/processCheckIn'
77
import { useProcessDeviceStore } from '@/stores/processDevice'
88
import { useProcessEventyayCheckInStore } from '@/stores/processEventyayCheckIn'
9+
import { useLeadScanStore } from '@/stores/leadscan'
10+
import { storeToRefs } from 'pinia'
911
1012
const props = defineProps({
1113
qrType: {
@@ -27,6 +29,9 @@ const processRegistrationStore = useProcessRegistrationStore()
2729
const processCheckInStore = useProcessCheckInStore()
2830
const processDeviceStore = useProcessDeviceStore()
2931
const processEventyayCheckIn = useProcessEventyayCheckInStore()
32+
const processLeadScan = useLeadScanStore()
33+
const { message, showSuccess, showError } = storeToRefs(processEventyayCheckIn)
34+
3035
const route = useRoute()
3136
const stationId = route.params.stationId
3237
const scannerType = route.params.scannerType
@@ -46,6 +51,9 @@ async function processQR() {
4651
if (props.qrType === 'eventyaycheckin') {
4752
await processEventyayCheckIn.checkIn()
4853
}
54+
if (props.qrType === 'eventyaylead') {
55+
await processLeadScan.scanLead()
56+
}
4957
cameraStore.paused = false
5058
}
5159
</script>
@@ -57,5 +65,8 @@ async function processQR() {
5765
</h2>
5866
<h3 v-if="details" class="mb-3">{{ details }}</h3>
5967
<QRCamera @scanned="processQR"></QRCamera>
68+
<p :class="{ 'text-green-500': showSuccess, 'text-red-500': showError }" class="mt-4">
69+
{{ message }}
70+
</p>
6071
</div>
6172
</template>

src/components/Eventyay/EventyayEventSelection.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ loadingStore.contentLoaded()
88
99
const router = useRouter()
1010
function checkIn() {
11-
router.push({ name: 'eventyayevents' })
11+
router.push({ name: 'eventyaycheckin' })
1212
}
1313
function leadscan() {
1414
router.push({ name: 'eventyayleedlogin' })

src/components/Eventyay/EventyayEvents.vue

+10-12
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@ const url = ref('')
1212
const eventyayEventStore = useEventyayEventStore()
1313
const selectedEvent = ref(null)
1414
const router = useRouter()
15-
const { events, loading, error, fetchEvents } = eventyayEventStore
15+
const { events, error, fetchEvents } = eventyayEventStore
1616
17-
watchEffect(() => {
18-
apiToken.value = localStorage.getItem('api_token')
19-
organiser.value = localStorage.getItem('organizer')
20-
url.value = localStorage.getItem('url')
17+
apiToken.value = localStorage.getItem('api_token')
18+
organiser.value = localStorage.getItem('organizer')
19+
url.value = localStorage.getItem('url')
2120
22-
if (apiToken.value && organiser.value && url.value) {
23-
fetchEvents(url.value, apiToken.value, organiser.value)
24-
loadingStore.contentLoaded()
25-
}
26-
})
21+
if (apiToken.value && organiser.value && url.value) {
22+
fetchEvents(url.value, apiToken.value, organiser.value)
23+
loadingStore.contentLoaded()
24+
}
2725
2826
const submitForm = () => {
2927
if (localStorage.getItem('selectedEventSlug') || localStorage.getItem('selectedEventName')) {
@@ -36,7 +34,7 @@ const submitForm = () => {
3634
if (selectedEventData) {
3735
localStorage.setItem('selectedEventSlug', selectedEventData.slug)
3836
localStorage.setItem('selectedEventName', selectedEventData.name.en)
39-
router.push({ name: 'eventyaycheckin' })
37+
router.push({ name: 'eventyayselect' })
4038
}
4139
} else {
4240
console.error('Please select an event.')
@@ -62,7 +60,7 @@ const submitForm = () => {
6260
/>
6361
</div>
6462
</form>
65-
<div v-if="!loading && !events.length && !error">
63+
<div v-if="!events.length && !error">
6664
No events available
6765
<StandardButton
6866
:text="'Refresh'"

src/components/Eventyay/EventyayLeedLogin.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ async function submitLogin() {
2323
email: email.value,
2424
key: password.value
2525
}
26-
console.log(payload)
2726
const response = await leedauth.leedlogin(payload)
28-
console.log(response)
27+
if (response.success) {
28+
router.push({ name: 'leadscan' })
29+
}
2930
}
3031
loadingStore.contentLoaded()
3132
</script>
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script setup>
2+
import QRCamera from '@/components/Common/QRCamera.vue'
3+
import { useLoadingStore } from '@/stores/loading'
4+
const loadingStore = useLoadingStore()
5+
loadingStore.contentLoaded()
6+
</script>
7+
8+
<template>
9+
<div
10+
class="-mt-16 grid h-screen w-full grid-cols-1 place-items-center items-center justify-center align-middle"
11+
>
12+
<QRCamera :qr-type="'eventyaylead'" :scan-type="'Lead-Scan'" />
13+
</div>
14+
</template>

src/components/LoginForm.vue

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ async function submitLogin() {
5656
}
5757
5858
function registerDevice() {
59-
console.log(server.value)
6059
if (server.value === '' || server.value === 'Select a Server') {
6160
errmessage.value = 'Please select a server first'
6261
showServerError.value = true
@@ -150,7 +149,7 @@ onMounted(() => {
150149
</p>
151150
<StandardButton
152151
:type="'button'"
153-
:text="'Register-Device'"
152+
text="Register-Device"
154153
:disabled="false"
155154
class="btn-primary mt-6 w-full justify-center"
156155
@click="registerDevice"

src/router/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import EventyayEventCheckIn from '@/components/Eventyay/EventyayEventCheckIn.vue
55
import EventyayEvents from '@/components/Eventyay/EventyayEvents.vue'
66
import EventyayEventSelection from '@/components/Eventyay/EventyayEventSelection.vue'
77
import EventyayLeedLogin from '@/components/Eventyay/EventyayLeedLogin.vue'
8+
import LeadScanning from '@/components/Eventyay/LeadScanning.vue'
89
import Device from '@/components/Registration/Device/Device.vue'
910
import RegistrationKiosk from '@/components/Registration/Kiosk/KioskOverview.vue'
1011
import RegistrationStats from '@/components/Registration/Station/RegistrationStats.vue'
@@ -50,6 +51,11 @@ const router = createRouter({
5051
name: 'eventyayleedlogin',
5152
component: EventyayLeedLogin
5253
},
54+
{
55+
path: '/leadscan',
56+
name: 'leadscan',
57+
component: LeadScanning
58+
},
5359
{
5460
path: '/panel',
5561
name: 'auth',

src/stores/eventyayEvent.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,22 @@ import { ref } from 'vue'
44

55
export const useEventyayEventStore = defineStore('eventyayEvent', () => {
66
const events = ref([])
7-
const loading = ref(false)
87
const error = ref(null)
98

109
async function fetchEvents(url, apiToken, organizer) {
11-
loading.value = true
1210
error.value = null
1311

1412
try {
15-
const api = mande(url, { headers: { Authorization: `Device ${apiToken}` } })
13+
const api = mande(url, { headers: { authorization: `Device ${apiToken}` } })
1614
const response = await api.get(`/api/v1/organizers/${organizer}/events/`)
1715
events.value = response.results
1816
} catch (err) {
1917
error.value = err.message
20-
} finally {
21-
loading.value = false
2218
}
2319
}
2420

2521
return {
2622
events,
27-
loading,
2823
error,
2924
fetchEvents
3025
}

src/stores/leadscan.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { useCameraStore } from '@/stores/camera'
2+
import { mande } from 'mande'
3+
import { defineStore } from 'pinia'
4+
import { ref } from 'vue'
5+
6+
export const useLeadScanStore = defineStore('processLeadScan', () => {
7+
const cameraStore = useCameraStore()
8+
const message = ref('')
9+
const showSuccess = ref(false)
10+
const showError = ref(false)
11+
12+
function $reset() {
13+
message.value = ''
14+
showSuccess.value = false
15+
showError.value = false
16+
}
17+
18+
function showErrorMsg(msg) {
19+
message.value = msg
20+
showSuccess.value = false
21+
showError.value = true
22+
}
23+
24+
function showSuccessMsg(msg) {
25+
message.value = msg
26+
showSuccess.value = true
27+
showError.value = false
28+
}
29+
30+
async function scanLead() {
31+
const qrData = JSON.parse(cameraStore.qrCodeValue)
32+
33+
const apiToken = localStorage.getItem('api_token')
34+
const url = localStorage.getItem('url')
35+
const key = localStorage.getItem('exhikey')
36+
const slug = localStorage.getItem('selectedEventSlug')
37+
38+
// Prepare the POST request body
39+
const requestBody = {
40+
lead: qrData.lead,
41+
scanned: 'null',
42+
scan_type: 'lead',
43+
device_name: 'Test'
44+
}
45+
46+
try {
47+
const headers = {
48+
Authorization: `Device ${apiToken}`,
49+
Accept: 'application/json',
50+
Exhibitor: key
51+
}
52+
53+
const api = mande(`${url}/api/v1/event/admin/${slug}/exhibitors/lead/create`, {
54+
headers: headers
55+
})
56+
const response = await api.post(requestBody)
57+
} catch (err) {
58+
showErrorMsg('Check-in failed: ' + err.message)
59+
}
60+
}
61+
62+
return {
63+
message,
64+
showSuccess,
65+
showError,
66+
scanLead,
67+
$reset
68+
}
69+
})

src/stores/leedauth.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ import { defineStore } from 'pinia'
44
export const useleedauth = defineStore('leedauth', () => {
55
async function leedlogin(payload) {
66
try {
7-
console.log('leedlogin')
87
const url = localStorage.getItem('url')
98
const organizer = localStorage.getItem('organizer')
109
const slug = localStorage.getItem('selectedEventSlug')
1110
const apiToken = localStorage.getItem('api_token')
12-
console.log(url, organizer, slug, apiToken, payload)
1311
const headers = {
1412
Authorization: `Device ${apiToken}`,
1513
Accept: 'application/json'
1614
}
1715
const api = mande(url, { headers: headers })
1816
const response = await api.post(`/api/v1/event/${organizer}/${slug}/exhibitors/auth`, payload)
19-
console.log('here', response)
17+
if (response.success) {
18+
if (localStorage.getItem('exhikey')) {
19+
localStorage.removeItem('exhikey')
20+
}
21+
localStorage.setItem('exhikey', payload.key)
22+
}
23+
2024
return response
2125
} catch (error) {
22-
console.log(error)
2326
console.log('error')
24-
return 'wt'
2527
}
2628
}
2729

src/stores/processDevice.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const useProcessDeviceStore = defineStore('processDevice', () => {
7272
localStorage.setItem('api_token', data.api_token)
7373
localStorage.setItem('organizer', data.organizer)
7474
localStorage.setItem('url', url)
75-
router.push({ name: 'eventyayselect' })
75+
router.push({ name: 'eventyayevents' })
7676
showSuccessMsg()
7777
} else {
7878
showErrorMsg()

0 commit comments

Comments
 (0)