From 3e8b66bf40c87acb946379632a3f5a3a2de32d9e Mon Sep 17 00:00:00 2001 From: Gabriel Borges Date: Mon, 3 Jun 2024 23:42:05 -0300 Subject: [PATCH] feat(frontend): create schemas for data validation --- .../src/components/Schemas/AuthorSchema.tsx | 21 ++++++++++--------- .../src/components/Schemas/BookSchema.tsx | 10 +++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 frontend/src/components/Schemas/BookSchema.tsx diff --git a/frontend/src/components/Schemas/AuthorSchema.tsx b/frontend/src/components/Schemas/AuthorSchema.tsx index 6dc8bf8..10d01fc 100644 --- a/frontend/src/components/Schemas/AuthorSchema.tsx +++ b/frontend/src/components/Schemas/AuthorSchema.tsx @@ -1,13 +1,14 @@ -import * as yup from "yup" +import * as yup from "yup"; const AuthorSchema = yup - .object({ - name: yup.string().required().min(1).max(300), - email: yup.string().email().min(1).max(320), - nationality: yup.string().min(1).max(100), - birthDate: yup.string().matches(/^(?:(?:19|20)\d{2})-(?:(?:0[1-9]|1[0-2]))-(?:(?:0[1-9]|[12]\d|3[01]))$/, { message: "Follow the format AAAA-MM-DD" }), - }) - .required() + .object({ + name: yup.string().required().min(1).max(300), + email: yup.string().email().min(1).max(320), + nationality: yup.string().min(1).max(100), + birthDate: yup.string().matches(/^(?:(?:19|20)\d{2})-(?:(?:0[1-9]|1[0-2]))-(?:(?:0[1-9]|[12]\d|3[01]))$/, { + message: "Follow the format AAAA-MM-DD", + }), + }) + .required(); - -export default AuthorSchema +export default AuthorSchema; diff --git a/frontend/src/components/Schemas/BookSchema.tsx b/frontend/src/components/Schemas/BookSchema.tsx new file mode 100644 index 0000000..57f37bd --- /dev/null +++ b/frontend/src/components/Schemas/BookSchema.tsx @@ -0,0 +1,10 @@ +import * as yup from "yup"; + +const BookSchema = yup + .object({ + title: yup.string().min(1).max(300).required(), + pages: yup.number().min(1).required(), + }) + .required(); + +export default BookSchema;