Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double warning messages on report forms #3311

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 52 additions & 76 deletions client/src/models/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({}),
Expand Down