2021-12-16 02:57:18 -06:00
|
|
|
import React, { FC } from 'react';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { connect, ConnectedProps } from 'react-redux';
|
2021-12-16 02:57:18 -06:00
|
|
|
import { useEffectOnce } from 'react-use';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
|
|
|
import { config } from '@grafana/runtime';
|
2020-05-19 02:55:04 -05:00
|
|
|
import { Button, HorizontalGroup } from '@grafana/ui';
|
2022-04-22 08:33:13 -05:00
|
|
|
import Page from 'app/core/components/Page/Page';
|
|
|
|
import { StoreState, UserOrg } from 'app/types';
|
|
|
|
|
2021-12-16 02:57:18 -06:00
|
|
|
import { getUserOrganizations, setUserOrganization } from './state/actions';
|
2020-05-19 02:55:04 -05:00
|
|
|
|
|
|
|
const navModel = {
|
|
|
|
main: {
|
|
|
|
icon: 'grafana',
|
|
|
|
subTitle: 'Preferences',
|
|
|
|
text: 'Select active organization',
|
|
|
|
},
|
|
|
|
node: {
|
|
|
|
text: 'Select active organization',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-12-16 02:57:18 -06:00
|
|
|
const mapStateToProps = (state: StoreState) => {
|
|
|
|
return {
|
|
|
|
userOrgs: state.organization.userOrgs,
|
|
|
|
};
|
2020-05-19 02:55:04 -05:00
|
|
|
};
|
2021-12-15 02:42:52 -06:00
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
setUserOrganization,
|
2021-12-16 02:57:18 -06:00
|
|
|
getUserOrganizations,
|
2020-05-19 02:55:04 -05:00
|
|
|
};
|
|
|
|
|
2021-12-16 02:57:18 -06:00
|
|
|
const connector = connect(mapStateToProps, mapDispatchToProps);
|
2021-12-15 02:42:52 -06:00
|
|
|
|
|
|
|
type Props = ConnectedProps<typeof connector>;
|
|
|
|
|
2021-12-16 02:57:18 -06:00
|
|
|
export const SelectOrgPage: FC<Props> = ({ setUserOrganization, getUserOrganizations, userOrgs }) => {
|
2021-12-15 02:42:52 -06:00
|
|
|
const setUserOrg = async (org: UserOrg) => {
|
2021-12-15 10:15:16 -06:00
|
|
|
await setUserOrganization(org.orgId);
|
2021-12-15 02:42:52 -06:00
|
|
|
window.location.href = config.appSubUrl + '/';
|
|
|
|
};
|
|
|
|
|
2021-12-16 02:57:18 -06:00
|
|
|
useEffectOnce(() => {
|
|
|
|
getUserOrganizations();
|
|
|
|
});
|
|
|
|
|
2020-05-19 02:55:04 -05:00
|
|
|
return (
|
|
|
|
<Page navModel={navModel}>
|
|
|
|
<Page.Contents>
|
|
|
|
<div>
|
|
|
|
<p>
|
2021-03-30 13:54:31 -05:00
|
|
|
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.
|
2020-05-19 02:55:04 -05:00
|
|
|
</p>
|
|
|
|
<HorizontalGroup wrap>
|
2021-12-16 02:57:18 -06:00
|
|
|
{userOrgs &&
|
|
|
|
userOrgs.map((org) => (
|
2020-05-19 02:55:04 -05:00
|
|
|
<Button key={org.orgId} icon="signin" onClick={() => setUserOrg(org)}>
|
|
|
|
{org.name}
|
|
|
|
</Button>
|
|
|
|
))}
|
|
|
|
</HorizontalGroup>
|
|
|
|
</div>
|
|
|
|
</Page.Contents>
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-12-15 02:42:52 -06:00
|
|
|
export default connector(SelectOrgPage);
|