TeamSettings.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React, { FC } from 'react';
  2. import { connect, ConnectedProps } from 'react-redux';
  3. import { Input, Field, Form, Button, FieldSet, VerticalGroup } from '@grafana/ui';
  4. import { SharedPreferences } from 'app/core/components/SharedPreferences/SharedPreferences';
  5. import { contextSrv } from 'app/core/core';
  6. import { AccessControlAction, Team } from 'app/types';
  7. import { updateTeam } from './state/actions';
  8. const mapDispatchToProps = {
  9. updateTeam,
  10. };
  11. const connector = connect(null, mapDispatchToProps);
  12. interface OwnProps {
  13. team: Team;
  14. }
  15. export type Props = ConnectedProps<typeof connector> & OwnProps;
  16. export const TeamSettings: FC<Props> = ({ team, updateTeam }) => {
  17. const canWriteTeamSettings = contextSrv.hasPermissionInMetadata(AccessControlAction.ActionTeamsWrite, team);
  18. return (
  19. <VerticalGroup>
  20. <FieldSet label="Team settings">
  21. <Form
  22. defaultValues={{ ...team }}
  23. onSubmit={(formTeam: Team) => {
  24. updateTeam(formTeam.name, formTeam.email);
  25. }}
  26. disabled={!canWriteTeamSettings}
  27. >
  28. {({ register }) => (
  29. <>
  30. <Field label="Name" disabled={!canWriteTeamSettings}>
  31. <Input {...register('name', { required: true })} id="name-input" />
  32. </Field>
  33. <Field
  34. label="Email"
  35. description="This is optional and is primarily used to set the team profile avatar (via gravatar service)."
  36. disabled={!canWriteTeamSettings}
  37. >
  38. <Input {...register('email')} placeholder="team@email.com" type="email" id="email-input" />
  39. </Field>
  40. <Button type="submit" disabled={!canWriteTeamSettings}>
  41. Update
  42. </Button>
  43. </>
  44. )}
  45. </Form>
  46. </FieldSet>
  47. <SharedPreferences resourceUri={`teams/${team.id}`} disabled={!canWriteTeamSettings} />
  48. </VerticalGroup>
  49. );
  50. };
  51. export default connector(TeamSettings);