Skip to content

Commit

Permalink
fix: bugs, lint errors, remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp committed Jun 20, 2022
1 parent 688a9f2 commit 9f539ab
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 73 deletions.
17 changes: 4 additions & 13 deletions src/api/stakeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default {
getStakeholders(id, { offset, rowsPerPage, orderBy, order, filter }) {
const orgId = getOrganizationId();
const where = filter.getWhereObj();
console.log('where', where);
const lbFilter = {
where,
order: [`${orderBy} ${order}`],
Expand All @@ -37,8 +36,8 @@ export default {
let query = '';
if (!id && orgId && Number(orgId)) {
query = `${STAKEHOLDER_API}/${orgId}?filter=${JSON.stringify(lbFilter)}`;
// } else if (id) {
// query = `${STAKEHOLDER_API}/${id}?filter=${JSON.stringify(lbFilter)}`;
} else if (id) {
query = `${STAKEHOLDER_API}/${id}?filter=${JSON.stringify(lbFilter)}`;
} else {
query = `${STAKEHOLDER_API}?filter=${JSON.stringify(lbFilter)}`;
}
Expand All @@ -57,8 +56,6 @@ export default {
getUnlinkedStakeholders(id, abortController) {
const orgId = getOrganizationId();

console.log('id orgId', id, orgId);

let query = '';
if (!id && orgId && Number(orgId)) {
query = `${STAKEHOLDER_API}/links/${orgId}`;
Expand All @@ -68,8 +65,6 @@ export default {
query = `${STAKEHOLDER_API}/links`;
}

console.log('getUnlinkedStakeholders ---->', query);

return fetch(query, {
method: 'GET',
headers: {
Expand All @@ -85,8 +80,6 @@ export default {
updateLinks(id, stakeholdersData) {
const orgId = getOrganizationId();

console.log('id orgId', id, orgId);

let query = '';
if (orgId && Number(orgId)) {
query = `${STAKEHOLDER_API}/links/${orgId}`;
Expand All @@ -96,8 +89,6 @@ export default {
query = `${STAKEHOLDER_API}/links`;
}

console.log('updateLinks ---->', query);

return fetch(query, {
method: 'PATCH',
headers: {
Expand All @@ -111,8 +102,8 @@ export default {
},

updateStakeholder(stakeholderUpdate) {
console.log('org ---> ', getOrganizationId());
const query = `${STAKEHOLDER_API}/${getOrganizationId()}`;
const orgId = getOrganizationId();
const query = `${STAKEHOLDER_API}/${orgId}`;

return fetch(query, {
method: 'PATCH',
Expand Down
4 changes: 3 additions & 1 deletion src/components/Stakeholders/Add.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ function AddStakeholder() {
};

const submit = () => {
createStakeholder(data);
createStakeholder(data).then(() => {
closeModal();
});
};

return (
Expand Down
1 change: 0 additions & 1 deletion src/components/Stakeholders/Filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function Filter() {
};

const handleChanges = (e) => {
// console.log('handleChanges', e.target);
setFormData({ ...formData, [e.target.name]: e.target.value });
};

Expand Down
7 changes: 0 additions & 7 deletions src/components/Stakeholders/StakeholderDetail/Groups.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Grid, List, Typography } from '@material-ui/core';
// import { StakeholdersContext } from '../../../context/StakeholdersContext';
import AdminIcon from '@material-ui/icons/SupervisorAccount';
import GrowerIcon from '@material-ui/icons/NaturePeople';
import StakeholderList from './List';
Expand Down Expand Up @@ -33,9 +32,7 @@ const useStyles = makeStyles({
});

function StakeholderGroups({ data, render, tall }) {
// console.log('StakeholderGroups data, render tall', data, render, tall);
const classes = useStyles();
// const { linkStakeholder } = useContext(StakeholdersContext);

const stakeholders = {
children: { label: 'Children', icon: '' },
Expand All @@ -44,10 +41,6 @@ function StakeholderGroups({ data, render, tall }) {
growers: { label: 'Growers', icon: <GrowerIcon className={classes.pr} /> },
};

// const handleLink = (type, id) => {
// linkStakeholder({ type, id });
// };

return (
<>
{render.map((type) => (
Expand Down
36 changes: 9 additions & 27 deletions src/components/Stakeholders/StakeholderDetail/LinkStakeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
DialogContent,
DialogActions,
List,
// TextField,
// FormControl,
} from '@material-ui/core';
import { StakeholdersContext } from 'context/StakeholdersContext';
import StakeholderList from './List';
Expand Down Expand Up @@ -38,12 +36,6 @@ function LinkStakeholder({ id, type }) {
);
const [open, setOpen] = useState(false);
const [filteredStakeholders, setFilteredStakeholders] = useState(false);
// const [data, setData] = useState({
// id,
// relation,
// stakeholder_id: null,
// linked: false,
// });

useEffect(() => {
const abortController = new AbortController();
Expand All @@ -54,10 +46,16 @@ function LinkStakeholder({ id, type }) {
}, []);

useEffect(() => {
// console.log('unlinkedStakeholders', id, type, unlinkedStakeholders.length);
// filter unlinked by the stakeholder type: organization, person so only appropriate types can be linked by relation: parents, children, users, growers
// need to update db relations table first

// const filtered = unlinkedStakeholders.filter((s) => {
// return s.type === type;
// const relation =
// type === 'children' || type === 'parents' ? 'Organization' : 'Person';
// return s.type === relation;
// });

// setFilteredStakeholders(filtered);
setFilteredStakeholders(unlinkedStakeholders);
}, [unlinkedStakeholders]);

Expand All @@ -70,10 +68,6 @@ function LinkStakeholder({ id, type }) {
setOpen(false);
};

// const submit = () => {
// updateLinks(id, relation, data.id, linked);
// };

return (
<>
<Button
Expand All @@ -97,24 +91,12 @@ function LinkStakeholder({ id, type }) {
data={stakeholder}
type={type}
linked={false}
>
{/* <TextField
label="Link"
variant="outlined"
name="link"
type="checkbox"
onClick={(e) => handleChange(stakeholder.id, e)}
value={data.linked}
/> */}
</StakeholderList>
></StakeholderList>
);
})}
</List>
</DialogContent>
<DialogActions>
{/* <Button color="primary" onClick={submit}>
Link {relation}
</Button> */}
<Button onClick={closeModal}>Close</Button>
</DialogActions>
</Dialog>
Expand Down
13 changes: 4 additions & 9 deletions src/components/Stakeholders/StakeholderDetail/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ function StakeholderList({ id, data, type, linked }) {
const [isLinked, setIsLinked] = useState(linked);
const { updateLinks } = useContext(StakeholdersContext);

// const handleUnlink = (type, id) => {
// unlinkStakeholder({ type, id });
// };

const handleChange = (e, stakeholder) => {
const handleChange = (e, data) => {
setIsLinked(!isLinked);
updateLinks(id, {
id: stakeholder.id,
type,
linked: !linked,
data: stakeholder,
data: data,
});
};

Expand All @@ -45,9 +40,9 @@ function StakeholderList({ id, data, type, linked }) {
direction="row"
>
<Grid item container direction="row" alignItems="center" xs={11}>
{type === 'User' ? (
{type === 'users' ? (
<UserListItem data={data} />
) : type === 'Person' ? (
) : type === 'growers' ? (
<GrowerListItem data={data} />
) : (
<ParentChildListItem data={data} />
Expand Down
3 changes: 0 additions & 3 deletions src/components/Stakeholders/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { StakeholdersContext } from '../../context/StakeholdersContext';
function StakeholderTable() {
const {
stakeholders,
// stakeholder,
columns,
page,
rowsPerPage,
Expand All @@ -25,8 +24,6 @@ function StakeholderTable() {
setPage,
setRowsPerPage,
sort,
// getStakeholder,
// getStakeholders,
} = useContext(StakeholdersContext);

const handleRowsPerPageChange = (e) => {
Expand Down
16 changes: 5 additions & 11 deletions src/context/StakeholdersContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export function StakeholdersProvider(props) {
{ label: 'Phone', value: 'phone' },
{ label: 'Website', value: 'website' },
];
// const [totalGrowerCount, setTotalGrowerCount] = useState(null);

useEffect(() => {
getStakeholders();
Expand Down Expand Up @@ -107,7 +106,7 @@ export function StakeholdersProvider(props) {
setDisplay();
};

// call w/ or w/o an id, it will default to the organization id or null
// call w/ or w/o an id, it will default to the organization id or be null
const getStakeholders = async (id = null) => {
log.debug('load stakeholders', id);
let data;
Expand Down Expand Up @@ -137,7 +136,6 @@ export function StakeholdersProvider(props) {
};

const createStakeholder = async (payload) => {
console.log('create', payload);
await api.createStakeholder(payload);
getStakeholders();
};
Expand All @@ -147,13 +145,10 @@ export function StakeholdersProvider(props) {
setUnlinkedStakeholders(unlinked.stakeholders);
};

const updateLinks = async (stakeholder_id, payload) => {
const { id, type, linked, data } = payload;
console.log('update links', stakeholder_id, id, type, linked, data);
// update parent_id or child_id fields
await api.updateLinks(stakeholder_id, payload);
// get updated list of unlinked
getUnlinkedStakeholders();
const updateLinks = async (id, payload) => {
await api.updateLinks(id, payload);
// getUnlinkedStakeholders();
getStakeholders();
};

const value = {
Expand All @@ -175,7 +170,6 @@ export function StakeholdersProvider(props) {
setDisplay,
sort,
updateFilter,
// getStakeholder,
getStakeholders,
createStakeholder,
updateStakeholder,
Expand Down
1 change: 0 additions & 1 deletion src/models/FilterStakeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default class Filter {
}

getWhereObj() {
console.log('this', this);
let where = {};

if (this.type) {
Expand Down

0 comments on commit 9f539ab

Please sign in to comment.