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 all 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 @@ 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
Loading