All files / src/pages/Contributors index.js

88.17% Statements 82/93
82% Branches 41/50
78.95% Functions 15/19
88.76% Lines 79/89

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554                                                                    93x   93x                                         62x   62x   62x 62x   62x   62x   62x     62x 62x 62x 62x 62x   62x     62x 7x     7x   7x   11977x 7x       7x     62x 14x   14x 14x   14x   14x   1827x 7x   1827x 1827x 1827x           14x   14x 7x     7x     14x           14x   1841x 1841x       1841x   1841x     14x 14x           1827x 1827x         14x     7x 7x       14x 14x       14x         62x 7x       7x         7x 7x 7x           62x             186x           62x                                                 62x   62x             62x         62x           62x                                                                                                                                                                                                                                                                                                                                                                                                                               61x   27x 14x 13x     13x 10x   3x       61x                                                                         61x               62x     62x                     62x                                          
/* eslint-disable max-lines-per-function */
/* eslint-disable complexity */
/* eslint-disable sort-keys */
 
import React, { useEffect, useState } from "react";
import axios from "axios";
import Box from "@material-ui/core/Box";
import Container from "@material-ui/core/Container";
import InputAdornment from "@material-ui/core/InputAdornment";
import TextField from "@material-ui/core/TextField";
import Typography from "@material-ui/core/Typography";
import Autocomplete from "@material-ui/lab/Autocomplete";
import SearchRoundedIcon from '@material-ui/icons/SearchRounded';
import NavBreadcrumbs from "../../components/NavBreadcrumbs";
import { DropdownArrow } from "../../components/DropdownArrow.js";
import { AffiliatedOrganizations } from "./AffiliatedOrganizations";
import { UnaffiliatedOrganizations } from "./UnaffiliatedOrganizations";
import { useStyles } from "./styles.js";
import GetStartedCard from '../../components/GetStartedCard'
import { TitleSection } from '../../components'
import Grid from '@material-ui/core/Grid';
import { makeStyles } from "@material-ui/core";
import PropTypes from "prop-types";
import AppBar from "@material-ui/core/AppBar";
import Tabs from "@material-ui/core/Tabs";
import Tab from "@material-ui/core/Tab";
import Checkbox from '@material-ui/core/Checkbox';
import FormGroup from "@material-ui/core/FormGroup";
import FormControlLabel from "@material-ui/core/FormControlLabel";
import { MuiThemeProvider, createMuiTheme } from "@material-ui/core/styles";
 
 
// eslint-disable-next-line
function TabPanel(props) {
  const { children, value, index, ...other } = props;
 
  return (
    <Grid
      role="tabpanel"
      hidden={value !== index}
      id={`full-width-tabpanel-${index}`}
      aria-labelledby={`full-width-tab-${index}`}
      {...other}
    >
      {value === index && (
        <Box p={3}>
          <Box>{children}</Box>
        </Box>
      )}
    </Grid>
  );
}
 
 
 
export default function Contributors({ match }) {
 
  const affiliation = match.params.affiliation;
 
  const classes = useStyles();
 
  const [organizations, setOrganizations] = useState([]);
  const [organizationNamesList, setOrganizationNamesList] = useState([]);
 
  const [affiliatedOrganizationsObject, setAffiliatedOrganizationsObject] = useState({});
 
  const [affiliatedOpen, setAffiliatedOpen] = useState(false);
 
  const [affiliatedSepOpen, setAfflnSepOpen] = useState(false);
 
 
  const [unaffiliatedOpen, setUnaffiliatedOpen] = useState(false);
  const [inputValue, setInputValue] = useState("");
  const [unaffiliated, getAffiliatedNames] = useState([]);
  const [unaffiliatedCount, getunaffiliatedCount] = useState(0);
  const [affiliatedCount, getaffiliatedCount] = useState(0);
 
  let count1 =0, count2 =0;
 
 
  useEffect(() => {
    const fetchData = async () => {
 
 
      const result = await axios.get(`${process.env.REACT_APP_API_URL}/api/organizations/`)
 
      const organization = result.data;
 
      const sorted = organization.sort((a, b) => a.id - b.id);
      setOrganizations(sorted);
 
    };
 
    fetchData();
  }, []);
 
  useEffect(() => {
    const createAffiliatedOrganizations = () =>
    {
      const input = inputValue.toLowerCase().replace(/\s/g, "");
      const affiliated = Object.create(null);
      // iterate through the json response
      const names = [];
 
      const addToAffiliated = (organization) => {
 
        if (!affiliated["Code for All"]) {
          affiliated["Code for All"] = [];
        }
        Eif (affiliated["Code for All"]) {
          affiliated["Code for All"].push(organizations[organization.id - 2]);
          affiliated[organization.name] = [organization];
 
        }
 
      };
 
      const addToUnaffiliated = (organization) => {
 
        if (affiliated["unaffiliated"]) {
          affiliated["unaffiliated"].push(organization);
        }
        else {
          affiliated["unaffiliated"] = [organization];
        }
 
        getAffiliatedNames(organization);
 
      };
 
 
 
      for (const org of organizations)
      {
        names.push(org.name);
        const orgName = org.name.toLowerCase().replace(/\s/g, "");
 
 
 
        Eif ((!inputValue || orgName.includes(input)))
        {
          if (org.affiliated === false)
          {
 
            count1++;
            addToUnaffiliated(org);
 
          }
          else
          {
 
            count2++;
            addToAffiliated(org);
          }
        }
      }
 
      if (count1 !== 0 || count2 !== 0)
      {
 
        getunaffiliatedCount(count1);
        getaffiliatedCount(count2);
 
      }
 
      setAffiliatedOrganizationsObject(affiliated);
      setOrganizationNamesList(names.sort());
 
 
    };
    createAffiliatedOrganizations();
  }, [organizations, inputValue, count1,count2]);
 
 
 
  useEffect(() => {
    Iif (affiliation === "unaffiliated") {
      setUnaffiliatedOpen(true);
      setAffiliatedOpen(false);
      setAfflnSepOpen(false);
    } else Iif (affiliation === "affiliated") {
      setAffiliatedOpen(true);
      setUnaffiliatedOpen(false);
      setAfflnSepOpen(true);
    } else {
      setAffiliatedOpen(false);
      setUnaffiliatedOpen(true);
      setAfflnSepOpen(false);
    }
  }, [affiliation]);
 
  // Tab Code
 
  TabPanel.propTypes = {
    children: PropTypes.node,
    index: PropTypes.any.isRequired,
    value: PropTypes.any.isRequired,
  };
  // eslint-disable-next-line
  function a11yProps(index) {
    return {
      id: `full-width-tab-${index}`,
      "aria-controls": `full-width-tabpanel-${index}`,
    };
  }
 
  const theme = createMuiTheme({
 
    overrides: {
      MuiTab: {
        "root": {
          color: 'theme​.palette.​text.disabled',
          fontSize: '32px',
          fontWeight: 'bold',
          textTransform: 'none',
          display: "flex",
          '&$selected': {
            color: '#006B95',
          },
 
        },
        wrapper: {
          flexDirection: "row",
          width: "auto",
        },
 
      },
 
    },
  });
 
  const [value, setValue] = React.useState(0);
 
  const handleChange = (event, newValue) => {
    setValue(newValue);
 
  };
 
 
  // CheckBox Code
  const [state, setState] = React.useState({
    indexContributor: true,
 
  });
 
  const handleChangeCheckbox = (event) => {
    setState({ ...state, [event.target.name]: event.target.checked });
  };
 
 
 
  return (
 
    <Box className='pageContainer'>
      <Box className='containerDefault'>
        <Container className={classes.firstSectionWrapper}>
          <NavBreadcrumbs
            crumbs={[
              { name: "Home", href: "/" },
              { name: "Organizations", href: "/contributors" },
            ]}
          />
          <Grid container>
            <TitleSection>Organizations</TitleSection>
            <Grid item xs={12}>
              <Typography color='textSecondary' className={classes.textStyle}>Check out our partners who have contributed to the Civic Tech Index</Typography>
            </Grid>
            <Grid item xs={12}>
 
              <TopCallToAction
                options={organizationNamesList}
                inputValue={inputValue}
                setInputValue={setInputValue}
                inputPlaceholder="Search for an organization"
                InputProps={{
                  endAdornment: (
                    <InputAdornment position='end'>
                      <SearchRoundedIcon className={classes.icon} />
                    </InputAdornment>
                  ),
                }}
              />
            </Grid>
          </Grid>
        </Container>
      </Box>
      <Box className='containerGray'>
 
        <Container>
          <MuiThemeProvider theme={theme}>
            <AppBar position="static" color="default" elevation={0}>
              <Tabs
                value={value}
                onChange={handleChange}
                variant="fullWidth"
                className={classes.tabs}
                classes={{ indicator: classes.indicator }}
              >
 
                <Tab label={<><span  style={{ display:'flex',alignItems:'center', paddingLeft: '10px' }}>({unaffiliatedCount + affiliatedCount })</span></>} icon="All" {...a11yProps(0)} className={classes.tabVal} />
                <Tab  icon="Unaffiliated"  label={<><span  style={{ display:'flex',alignItems:'center', paddingLeft: '10px' }}>({affiliatedOrganizationsObject["unaffiliated"] ? affiliatedOrganizationsObject["unaffiliated"].length : 0})</span></>} className={classes.tabVal} {...a11yProps(1)} />
                <Tab  icon="Affiliated" label={<><span  style={{ display:'flex',alignItems:'center', paddingLeft: '10px' }}>({affiliatedCount})</span></>} className={classes.tabVal} {...a11yProps(2)} />
              </Tabs>
            </AppBar>
          </MuiThemeProvider>
 
 
          <Grid index={value}>
            <Grid>
              <FormGroup>
                <FormControlLabel
                  control={<Checkbox onChange={handleChangeCheckbox} name="indexcontributor" className={classes.chkBoxStyle}/>}
                  label={<Typography className={classes.formControlLabel}>Index Contributor</Typography>}
                />
              </FormGroup>
            </Grid>
            <TabPanel value={value} index={0}>
              <Grid className={classes.unaffiliatedWrapper}>
                <Grid className={classes.sectionContainer}>
                  <Box component="div" className={classes.affiliation}>
                    <Typography variant='h2' color='primary' component={'span'} style={{ paddingLeft: '82px', fontSize: '28px' }}>
                        Unaffiliated Organizations  ({affiliatedOrganizationsObject["unaffiliated"] ? affiliatedOrganizationsObject["unaffiliated"].length : 0} / {affiliatedOrganizationsObject["unaffiliated"] ? affiliatedOrganizationsObject["unaffiliated"].length : 0} )
                    </Typography>
                  </Box>
                  <Box>
                    {unaffiliatedOpen && (
                      <Affiliation
                        organizations={affiliatedOrganizationsObject["unaffiliated"]}
                        inputValue={inputValue}
                        unaffiliated={unaffiliated}
                        classes={classes}
                        affiliation="unaffiliated"
                      />
                    )}
                  </Box>
                </Grid>
              </Grid>
              <Grid className={classes.affiliatedWrapper}>
                <Grid className={classes.sectionContainer}>
                  <Box className={classes.affiliation}>
                    <Typography variant='h2' color='primary' component={'span'} style={{ paddingLeft: '166px', color: '#004364',fontSize: '28px' }}>
                        Affiliated Organizations ({affiliatedCount} / {affiliatedCount} )
                    </Typography>
                  </Box>
 
                  <Grid className={classes.affiliatedOrgsContainer}>
                    <Box className={affiliatedOpen ? `${classes.blueColor} ` : `${classes.codeForAllWrapper}`}>
                      <img
                        src="/images/Code_for_All.png"
                        alt="code for all logo"
                        style={{ marginRight: "10px" }}
                      />
                      <a style={{ textDecoration: "none" }}href={"https://codeforall.org"}  target="_blank"  rel="noreferrer noopener" >
                        <Typography variant='body2' className={classes.codeforAllText}>Code for All  ( {affiliatedCount} / {affiliatedCount} )</Typography>
                      </a>
                      <DropdownArrow  setOpenFunction={setAffiliatedOpen}  />
 
 
                    </Box>
                    <Box style={{ marginLeft: '-46px',width: '928px' }}>
 
                      {affiliatedOpen && (
                        <Affiliation
                          organizations={affiliatedOrganizationsObject}
                          inputValue={inputValue}
                          classes={classes}
                          affiliation="affiliated"
 
                        />
                      )}
                    </Box>
 
 
                  </Grid>
 
 
                </Grid>
              </Grid>
            </TabPanel>
            <TabPanel value={value} index={1}>
              <div className={classes.unaffiliatedWrapper}>
                <div className={classes.sectionContainer}>
                  <div className={classes.affiliation}>
                    <Typography variant='h2' color='primary'>
                          Unaffiliated Organizations  ({unaffiliatedCount} / {unaffiliatedCount} )
                    </Typography>
                  </div>
                  <div>
                    {unaffiliatedOpen && (
                      <Affiliation
                        organizations={affiliatedOrganizationsObject["unaffiliated"]}
                        inputValue={inputValue}
                        classes={classes}
                        affiliation="unaffiliated"
                      />
                    )}
                  </div>
                </div>
              </div>
            </TabPanel>
            <TabPanel value={value} index={2}>
 
 
              <Grid className={classes.affiliatedWrapper}>
                <Grid className={classes.sectionContainer}>
                  <Box className={classes.affiliation}>
                    <Typography variant='h2' color='primary'>
                        Affiliated Organizations ({affiliatedCount} / {affiliatedCount})
                    </Typography>
 
                  </Box>
                  <Grid>
                    <Box className={affiliatedSepOpen ? `${classes.blueColor} ` : `${classes.codeForAllWrapper}`}>
                      <img
                        src="/images/Code_for_All.png"
                        alt="code for all logo"
                      />
                      <Typography variant='body2'>Code for All ( {affiliatedCount} / {affiliatedCount} )</Typography>
                      <DropdownArrow setOpenFunction={setAfflnSepOpen}  />
                    </Box>
                    <Box style={{ marginLeft: '-46px',width: '928px' }}>
 
                      {affiliatedSepOpen && (
                        <Affiliation
                          organizations={affiliatedOrganizationsObject}
                          inputValue={inputValue}
                          classes={classes}
                          affiliation="affiliated"
                        />
                      )}
                    </Box>
 
                  </Grid>
 
 
                </Grid>
              </Grid>
 
            </TabPanel>
          </Grid>
        </Container>
 
      </Box>
 
      <Box className='containerWhite'>
        <Container>
          <GetStartedCard
            headerTitle='Want to add your organization?'
            buttonText='Tag your project'
            buttonHref='/taggenerator'
          />
        </Container>
      </Box>
    </Box>
 
 
  );
}
 
const Affiliation = ({ organizations, inputValue, classes, affiliation }) => {
 
  if (!organizations && !inputValue) {
    return <h3 className={classes.loaders}>Loading...</h3>;
  } else Iif (!organizations && inputValue) {
    return <h3 className={classes.loaders}>No Results</h3>;
  } else {
    if (affiliation === "unaffiliated") {
      return <UnaffiliatedOrganizations unAffiliatedOrgs={organizations} />;
    } else {
      return <AffiliatedOrganizations organizations={organizations} />;
    }
  }
};
const useStylesTopCallToAction = makeStyles(theme => ({
  root:
  {
 
    "& .MuiAutocomplete-inputRoot": {
      paddingRight: '14px',
 
    },
 
  },
  icon: {
    backgroundColor: theme.palette.secondary.main,
    borderBottomRightRadius: '4px',
    borderTopRightRadius: '4px',
    color: theme.palette.text.secondary,
    height: '56px',
    marginRight: '-14px',
    width: '51px',
  },
  input: {
    width: '945px',
    height: '64px',
    borderRadius: '7px',
    fontSize: '1.5rem',
    paddingBottom: '4em',
    paddingTop: '15px',
  },
  "& .MuiSvgIcon-root": {
    root: {
      width: 168,
      height: 168,
    },
  },
 
 
}));
 
const TopCallToAction = ({
  heading,
  tagline,
  input,
  options,
  inputPlaceholder,
  setInputValue,
}) => {
  const classes = useStylesTopCallToAction();
 
 
  return (
    <Autocomplete
      id="free-solo"
      freeSolo
      inputValue={input}
      onInputChange={(e, newValue) => setInputValue(() => newValue)}
      options={options}
      className={classes.root}
      disableClearable
      forcePopupIcon={false}
      renderInput={(params) => (
        <TextField
          {...params}
          placeholder={inputPlaceholder}
          className={classes.input}
          variant="outlined"
          InputProps={{
            ...params.InputProps,
            type: "search",
            endAdornment: (
              <InputAdornment position='end'>
                <SearchRoundedIcon className={classes.icon} />
 
              </InputAdornment>
            ),
          }}
        />
      )}
    />
 
  );
};