From 199346a5497302418738c1cb51e3f72e2c60ecb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Palma?= Date: Mon, 9 Oct 2023 21:34:44 +0100 Subject: [PATCH] fix: editing profile without altering image now works --- .../Company/Edit/EditCompanySchema.js | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/components/Company/Edit/EditCompanySchema.js b/src/components/Company/Edit/EditCompanySchema.js index be2fa69d..f91fe7f7 100644 --- a/src/components/Company/Edit/EditCompanySchema.js +++ b/src/components/Company/Edit/EditCompanySchema.js @@ -2,17 +2,31 @@ import * as yup from "yup"; import { HumanValidationReasons } from "../../../utils"; import FinishCompanyRegistrationSchema from "../Registration/Finish/FinishCompanyRegistrationSchema"; import { generateValidationRule } from "./EditCompanyUtils"; +import { FinishCompanyRegistrationConstants } from "../Registration/Finish/FinishCompanyRegistrationUtils"; -// export default FinishCompanyRegistrationSchema.concat(yup.object().shape({ -// name: yup.string() -// .required(HumanValidationReasons.REQUIRED) -// .min(...generateValidationRule("name", "minLength", HumanValidationReasons.TOO_SHORT)) -// .max(...generateValidationRule("name", "maxLength", HumanValidationReasons.TOO_LONG)), -// })); +const contactSchema = { + value: yup.string().required("Cannot be empty."), +}; export default yup.object().shape({ + logo: yup.mixed().when('image', { + is: (value) => value !== undefined, + then: + yup.mixed() + .test("fileSize", + HumanValidationReasons.FILE_TOO_BIG(`${FinishCompanyRegistrationConstants.logo.maxSize / 1e6}MB`), + (value) => value[0]?.size <= FinishCompanyRegistrationConstants.logo.maxSize) + .test("fileType", + HumanValidationReasons.FILE_TYPE_ALLOWED(FinishCompanyRegistrationConstants.logo.allowedTypes), + (value) => !value[0] || FinishCompanyRegistrationConstants.logo.allowedTypes.includes(value[0].type)), + }), name: yup.string() .required(HumanValidationReasons.REQUIRED) .min(...generateValidationRule("name", "minLength", HumanValidationReasons.TOO_SHORT)) .max(...generateValidationRule("name", "maxLength", HumanValidationReasons.TOO_LONG)), + bio: yup.string() + .required(HumanValidationReasons.REQUIRED) + .max(...generateValidationRule("bio", "maxLength", HumanValidationReasons.TOO_LONG)), + contacts: yup.array() + .of(yup.object().shape(contactSchema)), });