Skip to content

Commit

Permalink
Merge pull request #47 from cisagov/issue-23/region-admin-filtered-or…
Browse files Browse the repository at this point in the history
…ganizations

Filter Organizations for RegionalAdmin User Type
  • Loading branch information
nickviola authored Mar 15, 2024
2 parents fe796f8 + fd768ea commit a74ab95
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 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 @@ -16,7 +16,17 @@ export const OrganizationList: React.FC<{
const [organizations, setOrganizations] = useState<Organization[]>([]);
const [dialogOpen, setDialogOpen] = useState(false);
const history = useHistory();
const getOrgsURL = `/v2/organizations/`;
const regionId = user?.regionId;

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

const orgsUrl = getOrgsUrl() as string;

const orgCols: GridColDef[] = [
{ field: 'name', headerName: 'Organization', minWidth: 100, flex: 2 },
Expand Down Expand Up @@ -62,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 @@ -71,9 +81,9 @@ export const OrganizationList: React.FC<{
} catch (e) {
console.error(e);
}
}, [apiGet, getOrgsURL]);
}, [apiGet, orgsUrl]);

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

0 comments on commit a74ab95

Please sign in to comment.