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

chore(superadmin): use org selector #1656

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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
Loading