koel/resources/assets/js/components/invitation/AcceptInvitation.vue

93 lines
2.7 KiB
Vue
Raw Normal View History

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>
<Btn :disabled="loading" data-testid="submit" type="submit">Accept &amp; 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>
<script setup lang="ts">
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'
import { useDialogBox, useRouter } from '@/composables'
import { parseValidationError } from '@/utils'
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'
2023-08-20 22:35:58 +00:00
const { showErrorDialog } = useDialogBox()
2024-04-04 22:20:42 +00:00
const { getRouteParam } = useRouter()
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 = '/'
} catch (err: any) {
const msg = err.response.status === 422 ? parseValidationError(err.response.data)[0] : 'Unknown error.'
showErrorDialog(msg, '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)
} catch (err: any) {
2024-02-25 19:32:53 +00:00
if (err.response?.status === 404) {
2023-08-20 22:35:58 +00:00
validToken.value = false
return
}
2024-02-25 19:32:53 +00:00
const msg = err.response?.status === 422 ? parseValidationError(err.response?.data)[0] : 'Unknown error.'
2023-08-20 22:35:58 +00:00
showErrorDialog(msg, 'Error')
}
})
</script>