2023-08-20 22:35:58 +00:00
|
|
|
<template>
|
2024-04-04 22:20:42 +00:00
|
|
|
<div class="flex items-center justify-center h-screen flex-col">
|
|
|
|
<form
|
|
|
|
v-if="userProspect"
|
|
|
|
autocomplete="off"
|
|
|
|
class="w-full sm:w-[320px] p-7 sm:bg-white/10 rounded-lg flex flex-col space-y-5"
|
|
|
|
@submit.prevent="submit"
|
|
|
|
>
|
|
|
|
<header class="mb-4">
|
2023-08-20 22:35:58 +00:00
|
|
|
Welcome to Koel! To accept the invitation, fill in the form below and click that button.
|
|
|
|
</header>
|
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
<FormRow>
|
|
|
|
<template #label>Your email</template>
|
|
|
|
<TextInput v-model="userProspect.email" disabled />
|
|
|
|
</FormRow>
|
|
|
|
|
|
|
|
<FormRow>
|
|
|
|
<template #label>Your name</template>
|
|
|
|
<TextInput
|
|
|
|
v-model="name"
|
|
|
|
v-koel-focus
|
|
|
|
data-testid="name"
|
|
|
|
placeholder="Erm… Bruce Dickinson?"
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
</FormRow>
|
|
|
|
|
|
|
|
<FormRow>
|
|
|
|
<template #label>Password</template>
|
|
|
|
<PasswordField v-model="password" data-testid="password" required />
|
|
|
|
<template #help>Min. 10 characters. Should be a mix of characters, numbers, and symbols.</template>
|
|
|
|
</FormRow>
|
|
|
|
|
|
|
|
<FormRow>
|
2024-04-22 21:04:03 +00:00
|
|
|
<Btn :disabled="loading" data-testid="submit" type="submit">Accept & Log In</Btn>
|
2024-04-04 22:20:42 +00:00
|
|
|
</FormRow>
|
2023-08-20 22:35:58 +00:00
|
|
|
</form>
|
|
|
|
|
|
|
|
<p v-if="!validToken">Invalid or expired invite.</p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2024-04-23 21:01:27 +00:00
|
|
|
<script lang="ts" setup>
|
2024-02-25 19:32:53 +00:00
|
|
|
import { onMounted, ref } from 'vue'
|
2023-08-20 22:35:58 +00:00
|
|
|
import { invitationService } from '@/services'
|
2024-04-23 11:24:29 +00:00
|
|
|
import { useErrorHandler, useRouter } from '@/composables'
|
2023-08-20 22:35:58 +00:00
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
import Btn from '@/components/ui/form/Btn.vue'
|
|
|
|
import PasswordField from '@/components/ui/form/PasswordField.vue'
|
|
|
|
import TextInput from '@/components/ui/form/TextInput.vue'
|
|
|
|
import FormRow from '@/components/ui/form/FormRow.vue'
|
|
|
|
|
|
|
|
const { getRouteParam } = useRouter()
|
2024-04-23 11:24:29 +00:00
|
|
|
const { handleHttpError } = useErrorHandler('dialog')
|
2023-08-20 22:35:58 +00:00
|
|
|
|
2024-02-25 19:32:53 +00:00
|
|
|
const name = ref('')
|
|
|
|
const password = ref('')
|
2023-08-20 22:35:58 +00:00
|
|
|
const userProspect = ref<User>()
|
|
|
|
const validToken = ref(true)
|
2024-02-25 19:32:53 +00:00
|
|
|
const loading = ref(false)
|
2023-08-20 22:35:58 +00:00
|
|
|
|
|
|
|
const token = String(getRouteParam('token')!)
|
|
|
|
|
|
|
|
const submit = async () => {
|
|
|
|
try {
|
2024-02-25 19:32:53 +00:00
|
|
|
loading.value = true
|
|
|
|
await invitationService.accept(token, name.value, password.value)
|
2023-08-20 22:35:58 +00:00
|
|
|
window.location.href = '/'
|
2024-04-23 11:24:29 +00:00
|
|
|
} catch (error: unknown) {
|
|
|
|
handleHttpError(error)
|
2024-02-25 19:32:53 +00:00
|
|
|
} finally {
|
|
|
|
loading.value = false
|
2023-08-20 22:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
try {
|
|
|
|
userProspect.value = await invitationService.getUserProspect(token)
|
2024-04-23 11:24:29 +00:00
|
|
|
} catch (error: unknown) {
|
|
|
|
handleHttpError(error, { 404: () => (validToken.value = false) })
|
2023-08-20 22:35:58 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|