71 lines
1.5 KiB
Vue
71 lines
1.5 KiB
Vue
<template>
|
|
<div>
|
|
Hello World
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { generateSlug } from '~/server/utils/auth'
|
|
|
|
const form = reactive({
|
|
title: '',
|
|
date: '',
|
|
bibleReferences: [''],
|
|
personalApplication: '',
|
|
pastorChallenge: ''
|
|
})
|
|
|
|
const loading = ref(false)
|
|
const successMessage = ref('')
|
|
|
|
const addBibleReference = () => {
|
|
form.bibleReferences.push('')
|
|
}
|
|
|
|
const removeBibleReference = (index: number) => {
|
|
if (form.bibleReferences.length > 1) {
|
|
form.bibleReferences.splice(index, 1)
|
|
}
|
|
}
|
|
|
|
const resetForm = () => {
|
|
form.title = ''
|
|
form.date = ''
|
|
form.bibleReferences = ['']
|
|
form.personalApplication = ''
|
|
form.pastorChallenge = ''
|
|
successMessage.value = ''
|
|
}
|
|
|
|
const handleSubmit = async () => {
|
|
loading.value = true
|
|
successMessage.value = ''
|
|
|
|
try {
|
|
await $fetch('/api/sermons', {
|
|
method: 'POST',
|
|
body: {
|
|
title: form.title,
|
|
date: form.date,
|
|
bibleReferences: form.bibleReferences.filter(ref => ref.trim() !== ''),
|
|
personalApplication: form.personalApplication,
|
|
pastorChallenge: form.pastorChallenge
|
|
}
|
|
})
|
|
|
|
successMessage.value = 'Sermon created successfully!'
|
|
resetForm()
|
|
} catch (error: any) {
|
|
console.error('Failed to create sermon:', error)
|
|
// Error handling is done by Nuxt automatically
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
const handleLogout = async () => {
|
|
await $fetch('/api/auth/logout', { method: 'POST' })
|
|
await navigateTo('/')
|
|
}
|
|
</script>
|