Skip to content

Commit

Permalink
chore(superadmin): use org selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ajohn25 committed Aug 6, 2023
1 parent 57f6eaf commit 0523e72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 42 deletions.
12 changes: 4 additions & 8 deletions src/components/OrganizationSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { useGetOrganizationsQuery } from "@spoke/spoke-codegen";
import React, { useMemo, useState } from "react";

export interface OrganizationSelectorProps {
orgId: string;
orgId?: string;
onChange: (selectedOrgId: string) => Promise<void> | void;
style?: React.CSSProperties;
}

export const OrganizationSelector: React.FC<OrganizationSelectorProps> = (
Expand Down Expand Up @@ -43,14 +44,9 @@ export const OrganizationSelector: React.FC<OrganizationSelectorProps> = (
onInputChange={(_event, newValue) => {
setOrgInput(newValue);
}}
renderInput={(params) => (
<TextField
{...params}
label="Organization"
helperText="Which organization?"
/>
)}
renderInput={(params) => <TextField {...params} label="Organization" />}
onChange={handleOrgSelected}
style={props.style ?? {}}
/>
);
};
Expand Down
43 changes: 9 additions & 34 deletions src/containers/SuperAdminPeople.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,22 @@
import FormControl from "@material-ui/core/FormControl";
import InputLabel from "@material-ui/core/InputLabel";
import MenuItem from "@material-ui/core/MenuItem";
import Select from "@material-ui/core/Select";
import type { Organization } from "@spoke/spoke-codegen";
import { useGetOrganizationsQuery } from "@spoke/spoke-codegen";
import React, { useState } from "react";

import OrganizationSelector from "../components/OrganizationSelector";
import AdminPeople from "./AdminPeople";

const SuperAdminPeople: React.FC = (_props) => {
const [organizationId, setOrganizationId] = useState<string>();
const {
data: organizationsData,
loading: orgsLoading
} = useGetOrganizationsQuery();
if (orgsLoading) {
return <div>"Loading..."</div>;
}

const handleOrgChanged = (event: React.ChangeEvent<{ value: string }>) => {
setOrganizationId(event.target.value);
const handleOrgChanged = (selectedOrgId: string) => {
setOrganizationId(selectedOrgId);
};

const organizations = organizationsData?.organizations ?? [];
return (
<div>
<FormControl>
<InputLabel id="organization-label">Organization</InputLabel>
<Select
style={{ width: 300 }}
labelId="organization-label"
value={organizationId}
onChange={handleOrgChanged}
>
{organizations.map((org: Organization) => (
<MenuItem key={org.id} value={org.id}>
{org.name}
</MenuItem>
))}
</Select>
</FormControl>
<>
<OrganizationSelector
onChange={handleOrgChanged}
style={{ width: 300 }}
/>
{organizationId && <AdminPeople organizationId={organizationId} />}
</div>
</>
);
};

Expand Down

0 comments on commit 0523e72

Please sign in to comment.