mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
20 lines
No EOL
658 B
TypeScript
20 lines
No EOL
658 B
TypeScript
import { toast } from 'svelte-sonner'
|
|
import { message, type ErrorStatus, type SuperValidated } from 'sveltekit-superforms'
|
|
|
|
export type Message = {
|
|
type: 'error' | 'success' | 'info'
|
|
text: string
|
|
}
|
|
|
|
export function errorMessage(form: SuperValidated<any>, text: string | null, status: ErrorStatus = 500) {
|
|
return message(form, { text: text || 'Error', type: 'error' }, { status })
|
|
}
|
|
|
|
export function successMessage(form: SuperValidated<any>, text: string | null) {
|
|
return message(form, { text: text || 'Success', type: 'success' })
|
|
}
|
|
|
|
export function toastMessage(message: Message | undefined) {
|
|
if (!message) return
|
|
toast[message.type](message.text)
|
|
} |