Skip to content

Commit

Permalink
fix: add org id to planter request (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp authored Jun 5, 2021
1 parent d0b759d commit e651010
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 37 deletions.
4 changes: 3 additions & 1 deletion src/api/planters.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export default {
},

getPlanterRegistrations(planterId) {
const registrationQuery = `${process.env.REACT_APP_API_ROOT}/api/planter-registration?filter[where][planterId]=${planterId}`;
const registrationQuery = `${
process.env.REACT_APP_API_ROOT
}/api/${getOrganization()}planter-registration?filter[where][planterId]=${planterId}`;
return fetch(registrationQuery, {
method: 'GET',
headers: {
Expand Down
24 changes: 18 additions & 6 deletions src/components/FilterTop.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,21 @@ function Filter(props) {
filter.dateStart || dateStartDefault,
);
const [dateEnd, setDateEnd] = useState(filter.dateEnd || dateEndDefault);
const [speciesId, setSpeciesId] = useState(ALL_SPECIES);
const [speciesId, setSpeciesId] = useState(filter.speciesId || ALL_SPECIES);
const [tag, setTag] = useState(null);
// TODO: how to save the tag state when the filter top opens/closes
// e.g. state --> {"id":5,"tagName":"another_tag","active":true,"public":true}
const [tagSearchString, setTagSearchString] = useState('');
const [organizationId, setOrganizationId] = useState(ALL_ORGANIZATIONS);
const [organizationId, setOrganizationId] = useState(
filter.organizationId || ALL_ORGANIZATIONS,
);
const [userHasOrg, setUserHasOrg] = useState(false);

useEffect(() => {
props.tagsDispatch.getTags(tagSearchString);
}, [tagSearchString, props.tagsDispatch]);

useEffect(() => {
// console.log('filter top checks user org id & loads orgs');
const hasOrg = getOrganization();
setUserHasOrg(hasOrg ? true : false);
// if not an org account && the org list isn't loaded --> load the orgs
Expand Down Expand Up @@ -256,7 +259,10 @@ function Filter(props) {
>
{[
{ id: ALL_SPECIES, name: 'All' },
{ id: SPECIES_NOT_SET, name: 'Not set' },
{
id: SPECIES_NOT_SET,
name: 'Not set',
},
...props.speciesState.speciesList,
].map((species) => (
<MenuItem key={species.id} value={species.id}>
Expand Down Expand Up @@ -298,8 +304,14 @@ function Filter(props) {
onChange={(e) => setOrganizationId(e.target.value)}
>
{[
{ id: ALL_ORGANIZATIONS, name: 'All' },
{ id: ORGANIZATION_NOT_SET, name: 'Not set' },
{
id: ALL_ORGANIZATIONS,
name: 'All',
},
{
id: ORGANIZATION_NOT_SET,
name: 'Not set',
},
...props.organizationState.organizationList,
].map((org) => (
<MenuItem key={org.id} value={org.id}>
Expand Down
38 changes: 8 additions & 30 deletions src/components/Verify.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState, useRef, forwardRef } from 'react';
import clsx from 'clsx';
import { connect } from 'react-redux';
import { makeStyles } from '@material-ui/core/styles';
Expand Down Expand Up @@ -41,7 +41,6 @@ import withData from './common/withData';
import OptimizedImage from './OptimizedImage';
import { LocationOn } from '@material-ui/icons';
import { countToLocaleString } from '../common/numbers';
import { getOrganization } from '../api/apiUtils';

const log = require('loglevel').getLogger('../components/Verify');

Expand Down Expand Up @@ -183,23 +182,24 @@ const ToVerifyCounter = withData(({ data }) => (
</>
));

const Transition = React.forwardRef(function Transition(props, ref) {
const Transition = forwardRef(function Transition(props, ref) {
return <Slide direction="up" ref={ref} {...props} />;
});

const Verify = (props) => {
// console.log('render: verify');
const classes = useStyles(props);
const [complete, setComplete] = React.useState(0);
const [isFilterShown, setFilterShown] = React.useState(false);
const [captureDetail, setCaptureDetail] = React.useState({
const [complete, setComplete] = useState(0);
const [isFilterShown, setFilterShown] = useState(false);
const [captureDetail, setCaptureDetail] = useState({
isOpen: false,
capture: {},
});
const [planterDetail, setPlanterDetail] = React.useState({
const [planterDetail, setPlanterDetail] = useState({
isOpen: false,
planter: {},
});
const refContainer = React.useRef();
const refContainer = useRef();

/*
* effect to load page when mounted
Expand All @@ -211,34 +211,16 @@ const Verify = (props) => {
props.verifyDispatch.updateFilter(props.verifyState.filter);
props.verifyDispatch.loadCaptureImages();
props.verifyDispatch.getCaptureCount();
if (
!getOrganization() &&
!props.organizationState.organizationList.length
) {
props.organizationDispatch.loadOrganizations();
}
}, []);

/* to display progress */
useEffect(() => {
// log.debug('set complete captures');
setComplete(props.verifyState.approveAllComplete);
}, [props.verifyState.approveAllComplete]);

/* To update capture count */
useEffect(() => {
if (
props.verifyState.captureCount !== props.verifyState.captureImages.length
) {
props.verifyDispatch.getCaptureCount();
}
}, [props.verifyState.captureImages]);

/* load more captures when the page or page size changes */
useEffect(() => {
// log.debug('get captures & capture count when page changes');
props.verifyDispatch.loadCaptureImages();
props.verifyDispatch.getCaptureCount();
}, [props.verifyState.pageSize, props.verifyState.currentPage]);

function handleCaptureClick(e, captureId) {
Expand Down Expand Up @@ -951,16 +933,12 @@ export default connect(
(state) => ({
verifyState: state.verify,
speciesState: state.species,
//plantersState: state.planters,
organizationState: state.organizations,
tagState: state.tags,
}),
//dispatch
(dispatch) => ({
verifyDispatch: dispatch.verify,
speciesDispatch: dispatch.species,
// plantersDispatch: dispatch.planters,
organizationDispatch: dispatch.organizations,
tagDispatch: dispatch.tags,
}),
)(Verify);

0 comments on commit e651010

Please sign in to comment.