Skip to content

Commit 0210849

Browse files
Refactored ProfileFormContainer to remove boilerplate
1 parent 7714374 commit 0210849

File tree

1 file changed

+24
-74
lines changed

1 file changed

+24
-74
lines changed

static/js/containers/ProfileFormContainer.js

Lines changed: 24 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -81,78 +81,18 @@ class ProfileFormContainer extends React.Component {
8181
}
8282
dispatch(updateProfile(username, profile));
8383
this.updateProfileValidation(this.props, profile, validator);
84-
}
84+
};
8585

8686
setProfileStep: Function = (step: string): void => {
8787
const { dispatch } = this.props;
8888
dispatch(setProfileStep(step));
8989
};
9090

91-
setDeletionIndex: Function = (index: number): void => {
92-
const { dispatch } = this.props;
93-
dispatch(setDeletionIndex(index));
94-
}
95-
96-
setShowEducationDeleteDialog: Function = (bool: boolean): void => {
97-
const { dispatch } = this.props;
98-
dispatch(setShowEducationDeleteDialog(bool));
99-
}
100-
101-
setShowWorkDeleteDialog: Function = (bool: boolean): void => {
102-
const { dispatch } = this.props;
103-
dispatch(setShowWorkDeleteDialog(bool));
104-
}
105-
106-
setShowWorkDeleteAllDialog: Function = (bool: boolean): void => {
107-
const { dispatch } = this.props;
108-
dispatch(setShowWorkDeleteAllDialog(bool));
109-
};
110-
111-
setShowEducationDeleteAllDialog: Function = (bool: boolean): void => {
112-
const { dispatch } = this.props;
113-
dispatch(setShowEducationDeleteAllDialog(bool));
114-
};
115-
116-
setUserPageDialogVisibility: Function = (bool: boolean): void => {
117-
const { dispatch } = this.props;
118-
dispatch(setUserPageDialogVisibility(bool));
119-
};
120-
12191
setWorkHistoryEdit: AsyncActionHelper = (bool: boolean) => {
12292
const { dispatch } = this.props;
12393
return dispatch(setWorkHistoryEdit(bool));
12494
}
12595

126-
setWorkDialogVisibility: Function = (bool: boolean): void => {
127-
const { dispatch } = this.props;
128-
dispatch(setWorkDialogVisibility(bool));
129-
}
130-
131-
setWorkDialogIndex: Function = (index: number): void => {
132-
const { dispatch } = this.props;
133-
dispatch(setWorkDialogIndex(index));
134-
}
135-
136-
clearProfileEdit: Function = (): void => {
137-
const { dispatch } = this.props;
138-
dispatch(clearProfileEdit(SETTINGS.username));
139-
}
140-
141-
setEducationDialogVisibility: Function = (bool: boolean): void => {
142-
const { dispatch } = this.props;
143-
dispatch(setEducationDialogVisibility(bool));
144-
}
145-
146-
setEducationDialogIndex: Function = (index: number): void => {
147-
const { dispatch } = this.props;
148-
dispatch(setEducationDialogIndex(index));
149-
}
150-
151-
setEducationDegreeLevel: Function = (level: string): void => {
152-
const { dispatch } = this.props;
153-
dispatch(setEducationDegreeLevel(level));
154-
};
155-
15696
setEducationDegreeInclusions: AsyncActionHelper = (inclusions: Object) => {
15797
const { dispatch } = this.props;
15898
return dispatch(setEducationDegreeInclusions(inclusions));
@@ -177,6 +117,28 @@ class ProfileFormContainer extends React.Component {
177117
}
178118
}
179119

120+
createActionHelper: Function = (actionCreator: Function): (...args: any) => void => {
121+
const { dispatch } = this.props;
122+
return (...args) => dispatch(actionCreator(...args));
123+
};
124+
125+
simpleActionHelpers: Function = (): {[k: string]: (...args: any) => void}[] => [
126+
[setWorkDialogVisibility, "setWorkDialogVisibility"],
127+
[setWorkDialogIndex, "setWorkDialogIndex"],
128+
[clearProfileEdit, "clearProfileEdit"],
129+
[setEducationDialogVisibility, "setEducationDialogVisibility"],
130+
[setEducationDialogIndex, "setEducationDialogIndex"],
131+
[setEducationDegreeLevel, "setEducationDegreeLevel"],
132+
[setUserPageDialogVisibility, "setUserPageDialogVisibility"],
133+
[setShowEducationDeleteDialog, "setShowEducationDeleteDialog"],
134+
[setShowWorkDeleteDialog, "setShowWorkDeleteDialog"],
135+
[setDeletionIndex, "setDeletionIndex"],
136+
[setShowWorkDeleteAllDialog, "setShowWorkDeleteAllDialog"],
137+
[setShowEducationDeleteAllDialog, "setShowEducationDeleteAllDialog"],
138+
].map(([actionCreator, actionCreatorName]) => (
139+
{ [actionCreatorName]: this.createActionHelper(actionCreator) }
140+
));
141+
180142
profileProps: Function = (profileFromStore: ProfileGetResult) => {
181143
let { ui } = this.props;
182144
let errors, isEdit, profile;
@@ -204,21 +166,9 @@ class ProfileFormContainer extends React.Component {
204166
updateProfile: this.updateProfile.bind(this, isEdit),
205167
saveProfile: this.saveProfile.bind(this, isEdit),
206168
setWorkHistoryEdit: this.setWorkHistoryEdit,
207-
setWorkDialogVisibility: this.setWorkDialogVisibility,
208-
setWorkDialogIndex: this.setWorkDialogIndex,
209-
clearProfileEdit: this.clearProfileEdit,
210-
setEducationDialogVisibility: this.setEducationDialogVisibility,
211-
setEducationDialogIndex: this.setEducationDialogIndex,
212-
setEducationDegreeLevel: this.setEducationDegreeLevel,
213169
setEducationDegreeInclusions: this.setEducationDegreeInclusions,
214170
fetchProfile: this.fetchProfile,
215-
setUserPageDialogVisibility: this.setUserPageDialogVisibility,
216-
setShowEducationDeleteDialog: this.setShowEducationDeleteDialog,
217-
setShowWorkDeleteDialog: this.setShowWorkDeleteDialog,
218-
setDeletionIndex: this.setDeletionIndex,
219-
setShowWorkDeleteAllDialog: this.setShowWorkDeleteAllDialog,
220-
setShowEducationDeleteAllDialog: this.setShowEducationDeleteAllDialog
221-
});
171+
}, ...this.simpleActionHelpers());
222172
};
223173

224174
childrenWithProps: Function = (profileFromStore: ProfileGetResult) => {

0 commit comments

Comments
 (0)