From 2018b79b19eb50c396df4c7deea461100524cb4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cemalettin=20Ta=C5=9F?= Date: Thu, 19 Nov 2020 14:54:43 +0300 Subject: [PATCH] Fix double warning messages on report forms Test report form for validation when it is not cancelled --- client/src/models/Report.js | 128 +++++++++++++++--------------------- 1 file changed, 52 insertions(+), 76 deletions(-) diff --git a/client/src/models/Report.js b/client/src/models/Report.js index 60c37e6435..d72d8b9881 100644 --- a/client/src/models/Report.js +++ b/client/src/models/Report.js @@ -171,85 +171,61 @@ export default class Report extends Model { reportPeople: yup .array() .nullable() - .test( - "primary-principal", - "primary principal error", - // can't use arrow function here because of binding to 'this' - function(reportPeople) { - const err = Report.checkPrimaryAttendee( - reportPeople, - Person.ROLE.PRINCIPAL - ) - return err ? this.createError({ message: err }) : true - } - ) - .test( - "primary-advisor", - "primary advsior error", - // can't use arrow function here because of binding to 'this' - function(reportPeople) { - const err = Report.checkPrimaryAttendee( - reportPeople, - Person.ROLE.ADVISOR - ) - return err ? this.createError({ message: err }) : true - } - ) - .test( - "attending-author", - "no attending author error", - // can't use arrow function here because of binding to 'this' - function(reportPeople) { - const err = Report.checkAttendingAuthor(reportPeople) - return err ? this.createError({ message: err }) : true - } - ) - .test( - "no-author", - "no author error", - // can't use arrow function here because of binding to 'this' - function(reportPeople) { - const err = Report.checkAnyAuthor(reportPeople) - return err ? this.createError({ message: err }) : true - } - ) - .test( - "purposeless-people", - "purposeless people error", - // can't use arrow function here because of binding to 'this' - function(reportPeople) { - const err = Report.checkUnInvolvedPeople(reportPeople) - return err ? this.createError({ message: err }) : true - } - ) - .when("cancelled", (cancelled, schema) => - cancelled - ? schema.nullable() - : schema.test( - "primary-advisor", - "primary advisor error", - // can't use arrow function here because of binding to 'this' - function(reportPeople) { - const err = Report.checkPrimaryAttendee( - reportPeople, - Person.ROLE.ADVISOR - ) - return err ? this.createError({ message: err }) : true - } - ) - ) .when("cancelled", (cancelled, schema) => cancelled ? schema.nullable() - : schema.test( - "attending-author", - "no attending author error", - // can't use arrow function here because of binding to 'this' - function(reportPeople) { - const err = Report.checkAttendingAuthor(reportPeople) - return err ? this.createError({ message: err }) : true - } - ) + : schema // Only do validation warning when engagement not cancelled + .test( + "primary-principal", + "primary principal error", + // can't use arrow function here because of binding to 'this' + function(reportPeople) { + const err = Report.checkPrimaryAttendee( + reportPeople, + Person.ROLE.PRINCIPAL + ) + return err ? this.createError({ message: err }) : true + } + ) + .test( + "primary-advisor", + "primary advisor error", + // can't use arrow function here because of binding to 'this' + function(reportPeople) { + const err = Report.checkPrimaryAttendee( + reportPeople, + Person.ROLE.ADVISOR + ) + return err ? this.createError({ message: err }) : true + } + ) + .test( + "no-author", + "no author error", + // can't use arrow function here because of binding to 'this' + function(reportPeople) { + const err = Report.checkAnyAuthor(reportPeople) + return err ? this.createError({ message: err }) : true + } + ) + .test( + "attending-author", + "no attending author error", + // can't use arrow function here because of binding to 'this' + function(reportPeople) { + const err = Report.checkAttendingAuthor(reportPeople) + return err ? this.createError({ message: err }) : true + } + ) + .test( + "purposeless-people", + "purposeless people error", + // can't use arrow function here because of binding to 'this' + function(reportPeople) { + const err = Report.checkUnInvolvedPeople(reportPeople) + return err ? this.createError({ message: err }) : true + } + ) ) .default([]), principalOrg: yup.object().nullable().default({}),