Skip to content

Commit

Permalink
Making "setFieldValue" in "componentDidUpdate" of forms more typed
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaVR committed Feb 3, 2019
1 parent e162342 commit 8c37e12
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
1 change: 0 additions & 1 deletion web/src/components/departments/DepartmentsFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class DepartmentFormModal extends React.Component<DepartmentFormModalProps, IDep
initialValue: departmentToEdit.name,
});
capacityFieldIds.forEach((capacityFieldId) => {
// TODO: extract this string interpolation thing to a central place (it's being used multiple times)
this.props.form.getFieldDecorator(`${this.capacityPerEducationFieldName}[${capacityFieldId}].${this.educationIdFieldName}`, {
initialValue: departmentToEdit.capacityPerEducation[capacityFieldId].educationId,
});
Expand Down
6 changes: 4 additions & 2 deletions web/src/components/educations/EducationsFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ class EducationFormModal extends React.Component<EducationFormModalProps, IEduca
if (this.props.educationToEdit !== undefined
&& this.props.isVisible === true
&& prevProps.isVisible === false) {
this.props.form.setFieldsValue({

const educationFields: Partial<Education> = {
name: this.props.educationToEdit.name,
});
};
this.props.form.setFieldsValue(educationFields);
}
}

Expand Down
5 changes: 3 additions & 2 deletions web/src/components/planning/PlanningsFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ class PlanningsFormModal extends React.Component<PlanningsFormModalProps, IPlann
&& prevProps.isVisible === false
&& this.props.studentToPlan !== undefined
&& this.props.internshipToEdit !== undefined) {

const internship = this.props.internshipToEdit;
const fields: Partial<Internship> = {
const internshipFields: Partial<Internship> = {
hours: internship.hours,
startDate: internship.startDate,
endDate: internship.endDate,
departmentId: internship.departmentId,
};
this.props.form.setFieldsValue(fields);
this.props.form.setFieldsValue(internshipFields);
}
}

Expand Down
6 changes: 4 additions & 2 deletions web/src/components/schools/SchoolsFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ class SchoolsFormModal extends React.Component<SchoolFormModalProps, ISchoolsFor
if (this.props.schoolToEdit !== undefined
&& this.props.isVisible === true
&& prevProps.isVisible === false) {
this.props.form.setFieldsValue({

const schoolFields: Partial<School> = {
name: this.props.schoolToEdit.name,
});
};
this.props.form.setFieldsValue(schoolFields);
}
}

Expand Down
6 changes: 4 additions & 2 deletions web/src/components/students/StudentsFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ class StudentsFormModal extends React.Component<StudentFormModalProps, IStudents
: undefined;
}

this.props.form.setFieldsValue({ // TODO: fill these keys dynamically
const studentFields: Partial<Student> = {
firstName: this.props.studentToEdit.firstName,
lastName: this.props.studentToEdit.lastName,
isConfirmed: this.props.studentToEdit.isConfirmed,
schoolId,
educationId,
});
};

this.props.form.setFieldsValue(studentFields);
}
}

Expand Down

1 comment on commit 8c37e12

@BenjaVR
Copy link
Owner

@BenjaVR BenjaVR commented on 8c37e12 Feb 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#33

Please sign in to comment.