client: client-side validation of new post page
This commit is contained in:
parent
009aefdb8a
commit
871b57ea3c
1 changed files with 25 additions and 0 deletions
|
@ -16,6 +16,7 @@ const Post = () => {
|
||||||
const { setToast } = useToasts()
|
const { setToast } = useToasts()
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [title, setTitle] = useState<string>()
|
const [title, setTitle] = useState<string>()
|
||||||
|
|
||||||
const [docs, setDocs] = useState<DocumentType[]>([{
|
const [docs, setDocs] = useState<DocumentType[]>([{
|
||||||
title: '',
|
title: '',
|
||||||
content: '',
|
content: '',
|
||||||
|
@ -61,6 +62,30 @@ const Post = () => {
|
||||||
}
|
}
|
||||||
setSubmitting(true)
|
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', {
|
await sendRequest('/server-api/posts/create', {
|
||||||
title,
|
title,
|
||||||
files: docs,
|
files: docs,
|
||||||
|
|
Loading…
Reference in a new issue