UserProfileEditPage.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from 'react';
  2. import { connect, ConnectedProps } from 'react-redux';
  3. import { useMount } from 'react-use';
  4. import { NavModel } from '@grafana/data';
  5. import { VerticalGroup } from '@grafana/ui';
  6. import Page from 'app/core/components/Page/Page';
  7. import SharedPreferences from 'app/core/components/SharedPreferences/SharedPreferences';
  8. import { getNavModel } from 'app/core/selectors/navModel';
  9. import { StoreState } from 'app/types';
  10. import UserOrganizations from './UserOrganizations';
  11. import UserProfileEditForm from './UserProfileEditForm';
  12. import UserSessions from './UserSessions';
  13. import { UserTeams } from './UserTeams';
  14. import { changeUserOrg, initUserProfilePage, revokeUserSession, updateUserProfile } from './state/actions';
  15. export interface OwnProps {
  16. navModel: NavModel;
  17. }
  18. function mapStateToProps(state: StoreState) {
  19. const userState = state.user;
  20. const { user, teams, orgs, sessions, teamsAreLoading, orgsAreLoading, sessionsAreLoading, isUpdating } = userState;
  21. return {
  22. navModel: getNavModel(state.navIndex, 'profile-settings'),
  23. orgsAreLoading,
  24. sessionsAreLoading,
  25. teamsAreLoading,
  26. orgs,
  27. sessions,
  28. teams,
  29. isUpdating,
  30. user,
  31. };
  32. }
  33. const mapDispatchToProps = {
  34. initUserProfilePage,
  35. revokeUserSession,
  36. changeUserOrg,
  37. updateUserProfile,
  38. };
  39. const connector = connect(mapStateToProps, mapDispatchToProps);
  40. export type Props = OwnProps & ConnectedProps<typeof connector>;
  41. export function UserProfileEditPage({
  42. navModel,
  43. orgsAreLoading,
  44. sessionsAreLoading,
  45. teamsAreLoading,
  46. initUserProfilePage,
  47. orgs,
  48. sessions,
  49. teams,
  50. isUpdating,
  51. user,
  52. revokeUserSession,
  53. changeUserOrg,
  54. updateUserProfile,
  55. }: Props) {
  56. useMount(() => initUserProfilePage());
  57. return (
  58. <Page navModel={navModel}>
  59. <Page.Contents isLoading={!user}>
  60. <VerticalGroup spacing="md">
  61. <UserProfileEditForm updateProfile={updateUserProfile} isSavingUser={isUpdating} user={user} />
  62. <SharedPreferences resourceUri="user" />
  63. <UserTeams isLoading={teamsAreLoading} teams={teams} />
  64. <UserOrganizations isLoading={orgsAreLoading} setUserOrg={changeUserOrg} orgs={orgs} user={user} />
  65. <UserSessions isLoading={sessionsAreLoading} revokeUserSession={revokeUserSession} sessions={sessions} />
  66. </VerticalGroup>
  67. </Page.Contents>
  68. </Page>
  69. );
  70. }
  71. export default connector(UserProfileEditPage);