Skip to content

Commit 2bf4b02

Browse files
Merge pull request #1023 from DemocracyLab/1014-Restrict-Volunteering
#1014 Restrict volunteering with project to only listed roles
2 parents 314aa3f + 158562e commit 2bf4b02

File tree

2 files changed

+31
-55
lines changed

2 files changed

+31
-55
lines changed

common/components/common/projects/ProjectVolunteerButton.jsx

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type LeaveProjectParams = {|
1919
type Props = {|
2020
project: ?ProjectDetailsAPIData,
2121
positionToJoin: ?PositionInfo,
22+
positions: $ReadOnlyArray<PositionInfo>,
2223
onVolunteerClick: () => void,
2324
|};
2425
type State = {|
@@ -151,28 +152,35 @@ class ProjectVolunteerButton extends React.PureComponent<Props, State> {
151152
}
152153

153154
_renderVolunteerButton(): React$Node {
154-
return this.state.isAlreadyVolunteering ? (
155+
const hasProjectPositions = !_.isEmpty(this.state.project.project_positions) && this.state.project.project_positions.some(position => !position.isHidden);
156+
if (this.state.isAlreadyVolunteering) {
155157
// TODO: Make this its own component and hook up to My Projects page
156-
<Button
157-
className="AboutProject-button"
158-
type="button"
159-
variant="destructive"
160-
onClick={this.handleShowLeaveModal}
161-
>
162-
Leave Project
163-
</Button>
164-
) : (
165-
<Button
166-
variant="primary"
167-
className="AboutProject-button"
168-
type="button"
169-
disabled={this.state.buttonDisabled}
170-
title={this.state.buttonTitle}
171-
onClick={this.handleShowJoinModal}
172-
>
173-
Volunteer With Project
174-
</Button>
175-
);
158+
return (
159+
<Button
160+
className="AboutProject-button"
161+
type="button"
162+
variant="destructive"
163+
onClick={this.handleShowLeaveModal}
164+
>
165+
Leave Project
166+
</Button>
167+
);
168+
} else if (hasProjectPositions) {
169+
return (
170+
<Button
171+
variant="primary"
172+
className="AboutProject-button"
173+
type="button"
174+
disabled={this.state.buttonDisabled}
175+
title={this.state.buttonTitle}
176+
onClick={this.handleShowJoinModal}
177+
>
178+
Volunteer With Project
179+
</Button>
180+
);
181+
} else {
182+
return null;
183+
}
176184
}
177185

178186
_renderLinkToSignInButton(): React$Node {

common/components/common/projects/ProjectVolunteerModal.jsx

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const volunteerPeriodsInDays: $ReadOnlyArray<SelectOption> = [
4444
["6 months - 1 year", 365],
4545
].map(textDaysPair => ({ label: textDaysPair[0], value: textDaysPair[1] }));
4646

47-
const OtherRoleOption: SelectOption = { label: "Other", value: "Other" };
4847

4948
/**
5049
* Modal for volunteering to join a project
@@ -80,7 +79,6 @@ class ProjectVolunteerModal extends React.PureComponent<Props, State> {
8079
value: position.roleTag.tag_name,
8180
label: tagOptionDisplay(position.roleTag),
8281
}))
83-
.concat(OtherRoleOption)
8482
);
8583

8684
let state: State = {
@@ -187,12 +185,6 @@ class ProjectVolunteerModal extends React.PureComponent<Props, State> {
187185
{!_.isEmpty(this.props.positions)
188186
? this._renderExistingPositionDropdown()
189187
: null}
190-
{_.isEmpty(this.props.positions) ||
191-
(this.state.existingPositionOption &&
192-
this.state.existingPositionOption.value ===
193-
OtherRoleOption.value)
194-
? this._renderOtherRoleDropdown()
195-
: null}
196188
<Form.Label>
197189
How long do you expect to be able to contribute to this
198190
project?
@@ -242,21 +234,12 @@ class ProjectVolunteerModal extends React.PureComponent<Props, State> {
242234
);
243235
}
244236

245-
_selectedExistingPositionTag(): ?string {
246-
return this.state.existingPositionOption &&
247-
this.state.existingPositionOption.value !== OtherRoleOption.value
237+
_selectedTag(): ?string {
238+
return this.state.existingPositionOption
248239
? this.state.existingPositionOption.value
249240
: null;
250241
}
251242

252-
_selectedOtherRoleTag(): ?string {
253-
return this.state.roleTag && this.state.roleTag.tag_name;
254-
}
255-
256-
_selectedTag(): ?string {
257-
return this._selectedExistingPositionTag() || this._selectedOtherRoleTag();
258-
}
259-
260243
_renderExistingPositionDropdown(): React$Node {
261244
return (
262245
<div className="form-group">
@@ -276,21 +259,6 @@ class ProjectVolunteerModal extends React.PureComponent<Props, State> {
276259
);
277260
}
278261

279-
_renderOtherRoleDropdown(): React$Node {
280-
return (
281-
<div className="form-group">
282-
<label htmlFor="project_technologies">Role You are Applying For</label>
283-
<TagSelector
284-
value={[this.state.roleTag]}
285-
category={TagCategory.ROLE}
286-
allowMultiSelect={false}
287-
isClearable={false}
288-
onSelection={this.onRoleChange.bind(this)}
289-
/>
290-
</div>
291-
);
292-
}
293-
294262
_renderVolunteerPeriodDropdown(): React$Node {
295263
return (
296264
<Select

0 commit comments

Comments
 (0)