2024-08-12 07:55:15 +00:00
|
|
|
<template>
|
|
|
|
<div class="flex items-center">
|
|
|
|
<div class="flex-grow-1">
|
|
|
|
<v-card class="mb-3">
|
|
|
|
<v-list density="compact" color="primary">
|
|
|
|
<v-list-item
|
|
|
|
v-for="(item, idx) in factors ?? []"
|
|
|
|
:key="idx"
|
|
|
|
:prepend-icon="getFactorType(item)?.icon"
|
|
|
|
:title="getFactorType(item)?.label"
|
|
|
|
:active="focus === item.id"
|
|
|
|
:disabled="getFactorAvailable(item)"
|
|
|
|
@click="focus = item.id"
|
|
|
|
/>
|
|
|
|
</v-list>
|
|
|
|
</v-card>
|
|
|
|
|
|
|
|
<v-expand-transition>
|
|
|
|
<v-alert v-show="error" variant="tonal" type="error" class="text-xs mb-3">
|
2024-08-13 09:43:44 +00:00
|
|
|
{{ t("errorOccurred", [error]) }}
|
2024-08-12 07:55:15 +00:00
|
|
|
</v-alert>
|
|
|
|
</v-expand-transition>
|
|
|
|
|
|
|
|
<div class="flex justify-end">
|
|
|
|
<v-btn variant="text" color="primary" class="justify-self-end" append-icon="mdi-arrow-right" @click="submit">
|
2024-08-13 09:43:44 +00:00
|
|
|
{{ t("next") }}
|
2024-08-12 07:55:15 +00:00
|
|
|
</v-btn>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2024-08-13 09:43:44 +00:00
|
|
|
const { t } = useI18n()
|
2024-08-12 07:55:15 +00:00
|
|
|
const config = useRuntimeConfig()
|
|
|
|
|
|
|
|
const focus = ref<number | null>(null)
|
|
|
|
const factors = ref<any[]>([])
|
|
|
|
|
|
|
|
const error = ref<string | null>(null)
|
|
|
|
|
|
|
|
const props = defineProps<{ ticket?: any }>()
|
|
|
|
const emits = defineEmits(["swap", "update:loading", "update:currentFactor"])
|
|
|
|
|
|
|
|
async function load() {
|
|
|
|
emits("update:loading", true)
|
2024-08-17 15:56:03 +00:00
|
|
|
const res = await fetch(`${config.public.solarNetworkApi}/cgi/id/auth/factors?ticketId=${props.ticket.id}`)
|
2024-08-12 07:55:15 +00:00
|
|
|
if (res.status !== 200) {
|
|
|
|
error.value = await res.text()
|
|
|
|
} else {
|
|
|
|
factors.value = (await res.json()).filter((e: any) => e.type != 0)
|
|
|
|
}
|
|
|
|
emits("update:loading", false)
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => load())
|
|
|
|
|
|
|
|
async function submit() {
|
|
|
|
if (!focus.value) return
|
|
|
|
|
|
|
|
emits("update:loading", true)
|
2024-08-17 15:56:03 +00:00
|
|
|
const res = await fetch(`${config.public.solarNetworkApi}/cgi/id/auth/factors/${focus.value}`, {
|
2024-08-12 07:55:15 +00:00
|
|
|
method: "POST",
|
|
|
|
})
|
|
|
|
if (res.status !== 200 && res.status !== 204) {
|
|
|
|
error.value = await res.text()
|
|
|
|
} else {
|
|
|
|
const item = factors.value.find((item: any) => item.id === focus.value)
|
|
|
|
emits("update:currentFactor", item)
|
|
|
|
emits("swap", "applicator")
|
|
|
|
error.value = null
|
|
|
|
focus.value = null
|
|
|
|
}
|
|
|
|
emits("update:loading", false)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFactorType(item: any) {
|
|
|
|
switch (item.type) {
|
|
|
|
case 1:
|
2024-08-13 09:43:44 +00:00
|
|
|
return { icon: "mdi-email-fast", label: t('multiFactorTypeEmail') }
|
2024-08-12 07:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFactorAvailable(factor: any) {
|
|
|
|
const blacklist: number[] = props.ticket?.blacklist_factors ?? []
|
|
|
|
return blacklist.includes(factor.id)
|
|
|
|
}
|
|
|
|
</script>
|