Skip to content

Commit

Permalink
fix: editing profile without altering image now works
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaspalma committed Oct 9, 2023
1 parent f799c95 commit 199346a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/components/Company/Edit/EditCompanySchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
});

0 comments on commit 199346a

Please sign in to comment.