Skip to content

Commit 47314bc

Browse files
timdavishbbmoz
authored andcommitted
Feature/#154707873 - Mary tags a project with a tech stack (#165)
* feature(server): add technologies to Project model * chore(data): add technologies to project seed data * feature(client): reuse handleCheckbox for both lists * feature(client): send project techs in createProject api request * chore(client): send techs to projectsApiClient
1 parent eaf3272 commit 47314bc

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

.setup/db/seedData/projects.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"role": "Mary Org Role 1",
77
"email": "[email protected]",
88
"causes": ["Animal"],
9+
"technologies": ["JavaScript"],
910
"applications": [],
1011
"createdAt": { "$date": "2018-01-29T21:03:46.266Z" },
1112
"updatedAt": { "$date": "2018-01-29T21:03:46.266Z" },
@@ -18,6 +19,7 @@
1819
"role": "Mary Org Role 2",
1920
"email": "[email protected]",
2021
"causes": ["Environment", "Animal", "International NGO", "Health"],
22+
"technologies": ["Ruby"],
2123
"applications": [
2224
{ "$oid": "5a1658a0327c0286c39a1aaa" }
2325
],
@@ -32,6 +34,7 @@
3234
"role": "Role1",
3335
"email": "[email protected]",
3436
"causes": ["International NGO"],
37+
"technologies": ["Java"],
3538
"applications": [],
3639
"createdAt": { "$date": "2018-01-29T21:03:46.266Z" },
3740
"updatedAt": { "$date": "2018-01-29T21:03:46.266Z" },
@@ -44,6 +47,7 @@
4447
"role": "Role2",
4548
"email": "[email protected]",
4649
"causes": ["Health"],
50+
"technologies": ["Python"],
4751
"applications": [
4852
{ "$oid": "5a1658a0327c0286c39a1aab" }
4953
],
@@ -58,6 +62,7 @@
5862
"role": "Role3",
5963
"email": "[email protected]",
6064
"causes": ["Education"],
65+
"technologies": ["PHP"],
6166
"applications": [],
6267
"createdAt": { "$date": "2018-01-29T21:03:46.266Z" },
6368
"updatedAt": { "$date": "2018-01-29T21:03:46.266Z" },
@@ -70,6 +75,7 @@
7075
"role": "Role4",
7176
"email": "[email protected]",
7277
"causes": ["Arts & Culture"],
78+
"technologies": ["C++"],
7379
"applications": [],
7480
"createdAt": { "$date": "2018-01-29T21:03:46.266Z" },
7581
"updatedAt": { "$date": "2018-01-29T21:03:46.266Z" },
@@ -82,6 +88,7 @@
8288
"role": "Role5",
8389
"email": "[email protected]",
8490
"causes": ["Other"],
91+
"technologies": ["Other"],
8592
"applications": [],
8693
"createdAt": { "$date": "2018-01-29T21:03:46.266Z" },
8794
"updatedAt": { "$date": "2018-01-29T21:03:46.266Z" },
@@ -94,6 +101,7 @@
94101
"role": "Role6",
95102
"email": "[email protected]",
96103
"causes": [],
104+
"technologies": [],
97105
"applications": [],
98106
"createdAt": { "$date": "2018-01-29T21:03:46.266Z" },
99107
"updatedAt": { "$date": "2018-01-29T21:03:46.266Z" },

client/api/projects.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ const projectsApiClient = {
1515
return apiRequest.get('/projects', apiOptions, query)
1616
},
1717

18-
async createProject (name, causes, organization) {
18+
async createProject (name, causes, technologies, organization) {
1919
const options = {
2020
method: 'POST',
2121
headers: {
2222
'Content-Type': 'application/json'
2323
},
24-
body: JSON.stringify({ name, causes, organization })
24+
body: JSON.stringify({ name, causes, technologies, organization })
2525
}
2626
return fetch('/api/projects/', options)
2727
}

client/components/CreateProjectForm/CreateProjectForm.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class CreateProjectForm extends Component {
2424
this.state = {
2525
error: '',
2626
projectName: '',
27-
causes: []
27+
causes: [],
28+
technologies: []
2829
}
2930
}
3031

@@ -38,19 +39,26 @@ class CreateProjectForm extends Component {
3839
}
3940

4041
async createProject () {
41-
const response = await projectsApiClient.createProject(this.state.projectName, this.state.causes, this.props.user.organization)
42+
const response = await projectsApiClient.createProject(
43+
this.state.projectName,
44+
this.state.causes,
45+
this.state.technologies,
46+
this.props.user.organization
47+
)
4248
if (response.status === 500) {
4349
this.setState({error: response.statusText})
4450
}
4551
}
4652

4753
handleCheckbox (event, checked) {
48-
const { causes } = this.state
49-
const cause = event.target.value
54+
const value = event.target.value
55+
const listName = causes.includes(value) ? 'causes' : 'technologies'
56+
const list = this.state[listName]
57+
5058
this.setState({
51-
causes: checked
52-
? [...causes, cause]
53-
: causes.filter(c => c !== cause)
59+
[listName]: checked
60+
? [...list, value]
61+
: list.filter(i => i !== value)
5462
})
5563
}
5664

server/database/models/Project.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const ProjectSchema = mongoose.Schema({
1212
type: String,
1313
enum: ['Animal', 'Environment', 'International NGO', 'Health', 'Education', 'Arts & Culture', 'Other']
1414
}],
15+
technologies: [{
16+
type: String,
17+
enum: ['JavaScript', 'Ruby', 'Java', 'Python', 'PHP', 'C++', 'Other']
18+
}],
1519
applications: [{
1620
type: mongoose.Schema.Types.ObjectId,
1721
ref: 'Application'
@@ -26,6 +30,7 @@ ProjectSchema.methods.toJSON = function () {
2630
role: this.role,
2731
email: this.email,
2832
causes: this.causes,
33+
technologies: this.technologies,
2934
applications: this.applications,
3035
createdAt: this.createdAt,
3136
updatedAt: this.updatedAt

0 commit comments

Comments
 (0)