client: client-side validation of new post page

This commit is contained in:
Max Leiter 2022-03-29 17:06:11 -07:00
parent 009aefdb8a
commit 871b57ea3c
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: A3512F2F2F17EBDA

View file

@ -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,