Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter Organizations for RegionalAdmin User Type #47

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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') {

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;

const orgCols: GridColDef[] = [
{ field: 'name', headerName: 'Organization', minWidth: 100, flex: 2 },
Expand Down Expand Up @@ -62,7 +72,7 @@

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 @@
} catch (e) {
console.error(e);
}
}, [apiGet, getOrgsURL]);
}, [apiGet, orgsUrl]);

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