NewOrgPage.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React, { FC } from 'react';
  2. import { connect, ConnectedProps } from 'react-redux';
  3. import { Button, Input, Field, Form } from '@grafana/ui';
  4. import Page from 'app/core/components/Page/Page';
  5. import { getConfig } from 'app/core/config';
  6. import { StoreState } from 'app/types';
  7. import { getNavModel } from '../../core/selectors/navModel';
  8. import { createOrganization } from './state/actions';
  9. const mapStateToProps = (state: StoreState) => {
  10. return { navModel: getNavModel(state.navIndex, 'global-orgs') };
  11. };
  12. const mapDispatchToProps = {
  13. createOrganization,
  14. };
  15. const connector = connect(mapStateToProps, mapDispatchToProps);
  16. type Props = ConnectedProps<typeof connector>;
  17. interface CreateOrgFormDTO {
  18. name: string;
  19. }
  20. export const NewOrgPage: FC<Props> = ({ navModel, createOrganization }) => {
  21. const createOrg = async (newOrg: { name: string }) => {
  22. await createOrganization(newOrg);
  23. window.location.href = getConfig().appSubUrl + '/org';
  24. };
  25. return (
  26. <Page navModel={navModel}>
  27. <Page.Contents>
  28. <h3 className="page-sub-heading">New organization</h3>
  29. <p className="playlist-description">
  30. Each organization contains their own dashboards, data sources, and configuration, which cannot be shared
  31. shared between organizations. While users might belong to more than one organization, multiple organizations
  32. are most frequently used in multi-tenant deployments.{' '}
  33. </p>
  34. <Form<CreateOrgFormDTO> onSubmit={createOrg}>
  35. {({ register, errors }) => {
  36. return (
  37. <>
  38. <Field label="Organization name" invalid={!!errors.name} error={errors.name && errors.name.message}>
  39. <Input
  40. placeholder="Org name"
  41. {...register('name', {
  42. required: 'Organization name is required',
  43. })}
  44. />
  45. </Field>
  46. <Button type="submit">Create</Button>
  47. </>
  48. );
  49. }}
  50. </Form>
  51. </Page.Contents>
  52. </Page>
  53. );
  54. };
  55. export default connector(NewOrgPage);