fix: add validation message to missing story field in createStory

This commit is contained in:
MTG2000
2022-06-19 19:30:52 +03:00
parent 708c6ccadc
commit adaebbe324
2 changed files with 3 additions and 3 deletions

View File

@@ -35,7 +35,7 @@ export default function StoryCard({ story }: Props) {
return (
<div className="bg-white rounded-12 overflow-hidden border-2 border-gray-200">
<img src={story.cover_image} className='h-[200px] w-full object-cover' alt="" />
{story.cover_image && <img src={story.cover_image} className='h-[200px] w-full object-cover' alt="" />}
<div className="p-24">
<Header author={story.author} date={story.createdAt} />
<Link to={createRoute({ type: 'story', id: story.id, title: story.title })}>

View File

@@ -34,7 +34,7 @@ const schema = yup.object({
title: yup.string().trim().required().min(10, 'the title is too short'),
tags: yup.array().required().min(1, 'please pick at least one relevant tag'),
body: yup.string().required().min(50, 'stories should have a minimum of 10 words'),
cover_image: yup.array().of(FileSchema as any)
cover_image: yup.array().of(FileSchema as any).min(1, "You need to add a cover image")
}).required();
@@ -110,7 +110,7 @@ export default function StoryForm() {
title: data.title,
body: data.body,
tags: data.tags.map(t => t.title),
cover_image: data.cover_image[0] as string,
cover_image: (data.cover_image[0] ?? '') as string,
},
}
})