ChangePasswordPage.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 Page from 'app/core/components/Page/Page';
  6. import { getNavModel } from 'app/core/selectors/navModel';
  7. import { StoreState } from 'app/types';
  8. import { ChangePasswordForm } from './ChangePasswordForm';
  9. import { changePassword, loadUser } from './state/actions';
  10. export interface OwnProps {
  11. navModel: NavModel;
  12. }
  13. function mapStateToProps(state: StoreState) {
  14. const userState = state.user;
  15. const { isUpdating, user } = userState;
  16. return {
  17. navModel: getNavModel(state.navIndex, `change-password`),
  18. isUpdating,
  19. user,
  20. };
  21. }
  22. const mapDispatchToProps = {
  23. loadUser,
  24. changePassword,
  25. };
  26. const connector = connect(mapStateToProps, mapDispatchToProps);
  27. export type Props = OwnProps & ConnectedProps<typeof connector>;
  28. export function ChangePasswordPage({ navModel, loadUser, isUpdating, user, changePassword }: Props) {
  29. useMount(() => loadUser());
  30. return (
  31. <Page navModel={navModel}>
  32. <Page.Contents isLoading={!Boolean(user)}>
  33. {user ? (
  34. <>
  35. <h3 className="page-heading">Change Your Password</h3>
  36. <ChangePasswordForm user={user} onChangePassword={changePassword} isSaving={isUpdating} />
  37. </>
  38. ) : null}
  39. </Page.Contents>
  40. </Page>
  41. );
  42. }
  43. export default connector(ChangePasswordPage);