client: client-side validation of new post page

pull/56/head
Max Leiter 4 years ago
parent 009aefdb8a
commit 871b57ea3c
No known key found for this signature in database
GPG Key ID: A3512F2F2F17EBDA

@ -16,6 +16,7 @@ const Post = () => {
const { setToast } = useToasts()
const router = useRouter();
const [title, setTitle] = useState<string>()
const [docs, setDocs] = useState<DocumentType[]>([{
title: '',
content: '',
@ -61,6 +62,30 @@ const Post = () => {
}
setSubmitting(true)
let hasErrored = false
if (!title) {
setToast({
text: 'Please fill out the post title',
type: 'error'
})
setSubmitting(false)
hasErrored = true
}
for (const doc of docs) {
if (!doc.title) {
setToast({
text: 'Please fill out all the document titles',
type: 'error'
})
setSubmitting(false)
hasErrored = true
}
}
if (hasErrored) return
await sendRequest('/server-api/posts/create', {
title,
files: docs,

Loading…
Cancel
Save