-
Notifications
You must be signed in to change notification settings - Fork 15
/
ViewTeamExampleWidget.jsx
84 lines (79 loc) · 2.88 KB
/
ViewTeamExampleWidget.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from 'react';
import PropTypes from 'prop-types';
import { Grid, Header, List } from 'semantic-ui-react';
import _ from 'lodash';
import { withTracker } from 'meteor/react-meteor-data';
import { WantsToJoin } from '../../../api/team/WantToJoinCollection';
import { Participants } from '../../../api/user/ParticipantCollection';
import { TeamParticipants } from '../../../api/team/TeamParticipantCollection';
import { defineMethod } from '../../../api/base/BaseCollection.methods';
import { Teams } from '../../../api/team/TeamCollection';
import { Slugs } from '../../../api/slug/SlugCollection';
class ViewTeamExampleWidget extends React.Component {
handleClick(e, inst) {
console.log(e, inst);
const collectionName = WantsToJoin.getCollectionName();
const teamDoc = Teams.findDoc(inst.id);
const team = Slugs.getNameFromID(teamDoc.slugID);
const definitionData = {
team,
};
console.log(collectionName, definitionData);
defineMethod.call({ collectionName, definitionData }, (error) => {
if (error) {
console.error('Failed to define', error);
}
});
}
render() {
const allParticipants = this.props.participants;
function getTeamParticipants(teamID, teamParticipants) {
const data = [];
const participants = _.filter(teamParticipants, { teamID: teamID });
for (let i = 0; i < participants.length; i++) {
for (let j = 0; j < allParticipants.length; j++) {
if (participants[i].participantID === allParticipants[j]._id) {
data.push({
compliant: allParticipants[j].isCompliant,
});
}
}
}
return data;
}
return (
<Grid celled>
<Grid.Row columns={3}>
<Grid.Column>
<Header>{this.props.team.name}</Header>
</Grid.Column>
<Grid.Column>
<List bulleted>
{this.props.teamMembers.map((t) => <List.Item key={t}>{t}</List.Item>)}
</List>
</Grid.Column>
<Grid.Column>
{ (_.every(getTeamParticipants(this.props.team._id, this.props.teamParticipants),
function (value) { return (value.compliant !== false); }))
? <Header>Team is Compliant</Header> : <Header>Team is not Compliant</Header> }
</Grid.Column>
</Grid.Row>
</Grid>
);
}
}
ViewTeamExampleWidget.propTypes = {
team: PropTypes.object.isRequired,
participants: PropTypes.array.isRequired,
teamParticipants: PropTypes.arrayOf(PropTypes.object).isRequired,
teamMembers: PropTypes.arrayOf(
PropTypes.string,
).isRequired,
teamCompliance: PropTypes.arrayOf(
PropTypes.boolean,
).isRequired,
};
export default withTracker(() => ({
participants: Participants.find({}).fetch(),
teamParticipants: TeamParticipants.find({}).fetch(),
}))(ViewTeamExampleWidget);