Switch newsletter form to SvelteKit Form Actions
- remove api endpoint and use latest SK form actions - create reusable server page function for form handling - handling the errors in the server function
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
import { error } from '@sveltejs/kit'
|
||||
import type { PageServerLoad } from './$types'
|
||||
import type { Actions, PageServerLoad } from './$types'
|
||||
import { fetchAPI } from '$utils/api'
|
||||
import { getRandomItems } from '$utils/functions'
|
||||
import subscribe from '$utils/forms/subscribe'
|
||||
|
||||
|
||||
/**
|
||||
* Page Data
|
||||
*/
|
||||
export const load: PageServerLoad = async ({ setHeaders }) => {
|
||||
try {
|
||||
// Get total of published photos
|
||||
@@ -52,4 +57,13 @@ export const load: PageServerLoad = async ({ setHeaders }) => {
|
||||
} catch (err) {
|
||||
throw error(500, err.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Form Data
|
||||
*/
|
||||
export const actions: Actions = {
|
||||
// Form newsletter subscription
|
||||
subscribe,
|
||||
}
|
||||
Reference in New Issue
Block a user