Skip to content

Commit

Permalink
Modify getOrgsURL based on user type to filter in frontend/src/compon…
Browse files Browse the repository at this point in the history
…ents/OrganizationList/OrganizationList.tsx
  • Loading branch information
nickviola committed Mar 13, 2024
1 parent 8863f4a commit 51c8b87
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions frontend/src/components/OrganizationList/OrganizationList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import EditNoteOutlinedIcon from '@mui/icons-material/EditNoteOutlined';
import { Organization } from 'types';
import { Alert, Box, Button, IconButton, Grid } from '@mui/material';
Expand All @@ -17,13 +17,16 @@ export const OrganizationList: React.FC<{
const [dialogOpen, setDialogOpen] = useState(false);
const history = useHistory();
const regionId = user?.regionId;
let getOrgsURL: any;

if (user?.userType == 'regionalAdmin') {
getOrgsURL = `/organizations/regionId/${regionId}`;
} else {
getOrgsURL = `/v2/organizations/`;
}
const getOrgsUrl = () => {
if (user?.userType == 'regionalAdmin') {

Check warning on line 22 in frontend/src/components/OrganizationList/OrganizationList.tsx

View workflow job for this annotation

GitHub Actions / lint

Expected '===' and instead saw '=='
return `/organizations/regionId/${regionId}`;
} else {
return `/v2/organizations/`;
}
};

const orgsUrl = getOrgsUrl() as String;

Check warning on line 29 in frontend/src/components/OrganizationList/OrganizationList.tsx

View workflow job for this annotation

GitHub Actions / lint

'orgsUrl' is assigned a value but never used

const orgCols: GridColDef[] = [
{ field: 'name', headerName: 'Organization', minWidth: 100, flex: 2 },
Expand Down Expand Up @@ -69,7 +72,7 @@ export const OrganizationList: React.FC<{

const fetchOrganizations = useCallback(async () => {
try {
const rows = await apiGet<Organization[]>(getOrgsURL);
const rows = await apiGet<Organization[]>(orgsURL);
// rows.forEach((obj) => {
// // obj.userCount = obj.userRoles.length;
// obj.tagNames = obj.tags.map((tag) => tag.name);
Expand All @@ -78,9 +81,9 @@ export const OrganizationList: React.FC<{
} catch (e) {
console.error(e);
}
}, [apiGet, getOrgsURL]);
}, [apiGet, orgsURL]);

Check warning on line 84 in frontend/src/components/OrganizationList/OrganizationList.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has an unnecessary dependency: 'orgsURL'. Either exclude it or remove the dependency array. Outer scope values like 'orgsURL' aren't valid dependencies because mutating them doesn't re-render the component

React.useEffect(() => {
useEffect(() => {
if (!parent) fetchOrganizations();
else {
setOrganizations(parent.children);
Expand Down

0 comments on commit 51c8b87

Please sign in to comment.