mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 10:19:22 +03:00
25 lines
932 B
TypeScript
25 lines
932 B
TypeScript
import yup from '@educt/schema';
|
|
|
|
const FILE_SIZE = 1000 * 1024;
|
|
const SUPPORTED_FORMATS = ['image/jpg', 'image/jpeg', 'image/png', 'image/webp'];
|
|
|
|
const CreateCourseSchema = yup.object().shape({
|
|
title: yup.string().required('Title field name is required').max(90, 'Title must be at most 90 characters'),
|
|
description: yup.string().required('Description field name is required'),
|
|
image: yup
|
|
.mixed()
|
|
.test('fileSize', 'File size is too large', (value: File) => {
|
|
if (!value) return true;
|
|
return value && value.size <= FILE_SIZE;
|
|
})
|
|
.test('fileFormat', 'This file format is not supported', (value: File) => {
|
|
if (!value) return true;
|
|
return value && SUPPORTED_FORMATS.includes(value.type);
|
|
})
|
|
.optional(),
|
|
category_id: yup.string().required('Category field is required'),
|
|
teacher_id: yup.string().required('Teacher field is required'),
|
|
});
|
|
|
|
export default CreateCourseSchema;
|