|
| 1 | +// @flow |
| 2 | + |
| 3 | +import React from 'react'; |
| 4 | +import _ from 'lodash'; |
| 5 | +import type {BioPersonData} from "./BioPersonData.jsx"; |
| 6 | +import url from "../../utils/url.js"; |
| 7 | +import Section from "../../enums/Section.js"; |
| 8 | +import LoadingMessage from "../../chrome/LoadingMessage.jsx"; |
| 9 | +import type {ProjectDetailsAPIData, TeamAPIData, VolunteerDetailsAPIData} from "../../utils/ProjectAPIUtils.js"; |
| 10 | +import BioThumbnail from "./BioThumbnail.jsx"; |
| 11 | +import {VolunteerDetailsAPIDataEqualsBioPersonData, VolunteerUserDataToBioPersonData} from "./BioPersonData.jsx"; |
| 12 | +import GroupBy from "../../utils/groupBy.js"; |
| 13 | +import BioModal from "./BioModal.jsx"; |
| 14 | +import Sort from "../../utils/sort.js"; |
| 15 | +import array from "../../utils/array.js"; |
| 16 | +import type {Dictionary} from "../../types/Generics.jsx"; |
| 17 | + |
| 18 | +type Props = {| |
| 19 | + teamResponse: TeamAPIData |
| 20 | +|}; |
| 21 | + |
| 22 | +type State = {| |
| 23 | + project: ?ProjectDetailsAPIData, |
| 24 | + board_of_directors: ?$ReadOnlyArray<BioPersonData>, |
| 25 | + project_volunteers: ?{ [key: string]: BioPersonData }, |
| 26 | + showBiographyModal: boolean, |
| 27 | + allowModalUnsafeHtml: boolean, |
| 28 | + modalPerson: ?BioPersonData, |
| 29 | + personTitle: string |
| 30 | +|}; |
| 31 | + |
| 32 | +type SectionConfig = {| |
| 33 | + title: string, |
| 34 | + sectionRoleCategory: string, |
| 35 | + topRoles: ?$ReadOnlyArray<string> |
| 36 | +|}; |
| 37 | + |
| 38 | +const SectionConfigs: $ReadOnlyArray<SectionConfig> = [ |
| 39 | + { |
| 40 | + title: "Development", |
| 41 | + sectionRoleCategory: "Software Development", |
| 42 | + topRoles: ["technical-director", "technical-lead"] |
| 43 | + }, { |
| 44 | + title: "Design", |
| 45 | + sectionRoleCategory: "Design", |
| 46 | + topRoles: ["design-lead", "creative-director"] |
| 47 | + }, { |
| 48 | + title: "Product Management", |
| 49 | + sectionRoleCategory: "Product Management", |
| 50 | + topRoles: ["product-manager-lead"] |
| 51 | + }, { |
| 52 | + title: "Marketing", |
| 53 | + sectionRoleCategory: "Marketing", |
| 54 | + topRoles: ["marketing-lead"] |
| 55 | + }, { |
| 56 | + title: "Salesforce Dev/Admin", |
| 57 | + sectionRoleCategory: "Operations", |
| 58 | + topRoles: ["business-operations-lead"] |
| 59 | + }, { |
| 60 | + title: "Operations", |
| 61 | + sectionRoleCategory: "Business", |
| 62 | + topRoles: [] |
| 63 | + } |
| 64 | +]; |
| 65 | + |
| 66 | +const roleNameOverride: Dictionary<string> = { |
| 67 | + "business-operations-lead": "Salesforce Team Lead" |
| 68 | +}; |
| 69 | + |
| 70 | +class TeamSections extends React.PureComponent<Props, State> { |
| 71 | + constructor(props: Props): void { |
| 72 | + super(props); |
| 73 | + this.state = { |
| 74 | + project: null, |
| 75 | + board_of_directors: null, |
| 76 | + showBiographyModal: false, |
| 77 | + modalPerson: null |
| 78 | + }; |
| 79 | + this.handleShowBio = this.handleShowBio.bind(this); |
| 80 | + this.handleClose = this.handleClose.bind(this); |
| 81 | + } |
| 82 | + |
| 83 | + componentWillReceiveProps(nextProps: Props): void { |
| 84 | + let state: State = { showModal: nextProps.showModal }; |
| 85 | + state = this.loadTeamDetails(state, nextProps.teamResponse); |
| 86 | + this.setState(state); |
| 87 | + } |
| 88 | + |
| 89 | + loadTeamDetails(state: State, response: TeamAPIData): State { |
| 90 | + state.board_of_directors = response.board_of_directors && JSON.parse(response.board_of_directors); |
| 91 | + |
| 92 | + if(response.project) { |
| 93 | + state.project = response.project; |
| 94 | + const activeVolunteers: $ReadOnlyArray<VolunteerDetailsAPIData> = response.project.project_volunteers.filter( (pv) => pv.isApproved); |
| 95 | + const sortedVolunteers: $ReadOnlyArray<VolunteerDetailsAPIData> = _.sortBy(activeVolunteers, ["platform_date_joined"]); |
| 96 | + // Remove board members from volunteer list |
| 97 | + const uniqueVolunteers: $ReadOnlyArray<BioPersonData> = _.differenceWith( |
| 98 | + sortedVolunteers, |
| 99 | + state.board_of_directors, |
| 100 | + VolunteerDetailsAPIDataEqualsBioPersonData); |
| 101 | + state.project_volunteers = GroupBy.andTransform( |
| 102 | + uniqueVolunteers, |
| 103 | + (pv: VolunteerDetailsAPIData) => pv.roleTag.subcategory, |
| 104 | + (pv: VolunteerDetailsAPIData) => { |
| 105 | + return VolunteerUserDataToBioPersonData(pv.user, pv.roleTag.display_name, pv.roleTag.tag_name, roleNameOverride); |
| 106 | + }); |
| 107 | + } |
| 108 | + |
| 109 | + return state; |
| 110 | + } |
| 111 | + |
| 112 | + //handlers for biography modal |
| 113 | +//show passes information to the modal on whose information to display, close clears that out of state (just in case) |
| 114 | +//title is passed separately from the rest because of our data structure for owner and volunteer not matching up |
| 115 | + handleShowBio(allowModalUnsafeHtml: boolean, person: BioPersonData) { |
| 116 | + this.setState({ |
| 117 | + modalPerson: person, |
| 118 | + showBiographyModal: true, |
| 119 | + allowModalUnsafeHtml: allowModalUnsafeHtml |
| 120 | + }); |
| 121 | + } |
| 122 | + handleClose() { |
| 123 | + this.setState({ |
| 124 | + modalPerson: null, |
| 125 | + showBiographyModal: false, |
| 126 | + allowModalUnsafeHtml: false |
| 127 | + }); |
| 128 | + } |
| 129 | + |
| 130 | + render(): ?React$Node { |
| 131 | + return ( |
| 132 | + <React.Fragment> |
| 133 | + {this._boardOfDirectors()} |
| 134 | + {this._ourTeam()} |
| 135 | + {this._renderBioModal()} |
| 136 | + </React.Fragment> |
| 137 | + ); |
| 138 | + } |
| 139 | + |
| 140 | + _boardOfDirectors(): ?React$Node { |
| 141 | + return (this.state.board_of_directors ? |
| 142 | + <div className="about-us-team col"> |
| 143 | + <h2>Board of Directors</h2> |
| 144 | + <p className="about-us-team-description"> |
| 145 | + Please review our <a href="https://d1agxr2dqkgkuy.cloudfront.net/documents/2019%20DemocracyLab%20Annual%20Report.pdf" >2019 Annual Report</a> to learn about the impact of our programs and platform last year. |
| 146 | + </p> |
| 147 | + <div className="about-us-team-card-container about-us-board-container"> |
| 148 | + {this._renderBios(this.state.board_of_directors, true)} |
| 149 | + </div> |
| 150 | + <hr /> |
| 151 | + </div> : null); |
| 152 | + } |
| 153 | + |
| 154 | + _ourTeam(): ?React$Node { |
| 155 | + if(this.state.project) { |
| 156 | + const teamSections: $ReadOnlyArray<?React$Node> = SectionConfigs |
| 157 | + .filter((sc: SectionConfig) => sc.sectionRoleCategory in this.state.project_volunteers) |
| 158 | + .map((sc: SectionConfig) => this._renderTeamSection(sc)); |
| 159 | + |
| 160 | + return ( |
| 161 | + <div className="about-us-team col"> |
| 162 | + <h2>Our Team</h2> |
| 163 | + <p className="about-us-team-description"> |
| 164 | + We are volunteer engineers, marketers, organizers, strategists, designers, project managers, and citizens |
| 165 | + committed to our vision, and driven by our mission. |
| 166 | + Please visit our <a href={url.section(Section.AboutProject, {id: this.state.project.project_id})}>project |
| 167 | + profile</a> to learn how you can get involved! |
| 168 | + </p> |
| 169 | + {array.join(teamSections, <hr/>)} |
| 170 | + </div>); |
| 171 | + } else { |
| 172 | + return <div className="about-us-team col"><LoadingMessage message="Loading our team information..."/></div>; |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + _renderTeamSection(sectionConfig: SectionConfig): ?React$Node { |
| 177 | + if(sectionConfig.sectionRoleCategory in this.state.project_volunteers) { |
| 178 | + const team: $ReadOnlyArray<BioPersonData> = this.state.project_volunteers[sectionConfig.sectionRoleCategory]; |
| 179 | + const sortedTeam: $ReadOnlyArray<BioPersonData> = Sort.byNamedEntries(team, sectionConfig.topRoles, (p: BioPersonData) => p.title_tag); |
| 180 | + |
| 181 | + return ( |
| 182 | + <React.Fragment> |
| 183 | + <h4>{sectionConfig.title}</h4> |
| 184 | + <div className="about-us-team-card-container"> |
| 185 | + {this._renderBios(sortedTeam, false)} |
| 186 | + </div> |
| 187 | + </React.Fragment> |
| 188 | + ); |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + _renderBioModal(): ?React$Node { |
| 193 | + return <BioModal |
| 194 | + size="lg" |
| 195 | + showModal={this.state.showBiographyModal} |
| 196 | + allowUnsafeHtml={this.state.allowModalUnsafeHtml} |
| 197 | + handleClose={this.handleClose} |
| 198 | + person={this.state.modalPerson} |
| 199 | + /> |
| 200 | + } |
| 201 | + |
| 202 | + _renderBios(volunteers: $ReadOnlyArray<BioPersonData>, allowUnsafeHtml: boolean): ?React$Node { |
| 203 | + return ( |
| 204 | + volunteers.map((volunteer, i) => { |
| 205 | + return ( |
| 206 | + <BioThumbnail key={i} person={volunteer} handleClick={this.handleShowBio.bind(this, allowUnsafeHtml)}/> |
| 207 | + )} |
| 208 | + ) |
| 209 | + ); |
| 210 | + } |
| 211 | + |
| 212 | +} |
| 213 | + |
| 214 | +export default TeamSections; |
0 commit comments