The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/org/SelectOrgPage.tsx

59 lines
1.5 KiB

import React, { FC, useState } from 'react';
import Page from 'app/core/components/Page/Page';
import { getBackendSrv, config } from '@grafana/runtime';
import { UserOrg } from 'app/types';
import { useAsync } from 'react-use';
import { Button, HorizontalGroup } from '@grafana/ui';
const navModel = {
main: {
icon: 'grafana',
subTitle: 'Preferences',
text: 'Select active organization',
},
node: {
text: 'Select active organization',
},
};
const getUserOrgs = async () => {
return await getBackendSrv().get('/api/user/orgs');
};
const setUserOrg = async (org: UserOrg) => {
return await getBackendSrv()
.post('/api/user/using/' + org.orgId)
.then(() => {
window.location.href = config.appSubUrl + '/';
});
};
export const SelectOrgPage: FC = () => {
const [orgs, setOrgs] = useState<UserOrg[]>();
useAsync(async () => {
setOrgs(await getUserOrgs());
}, []);
return (
<Page navModel={navModel}>
<Page.Contents>
<div>
<p>
You have been invited to another organization! Please select which organization that you want to use right
now. You can change this later at any time.
</p>
<HorizontalGroup wrap>
{orgs &&
orgs.map((org) => (
<Button key={org.orgId} icon="signin" onClick={() => setUserOrg(org)}>
{org.name}
</Button>
))}
</HorizontalGroup>
</div>
</Page.Contents>
</Page>
);
};
export default SelectOrgPage;