12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import styled from '@emotion/styled';
- import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
- import {Button} from 'sentry/components/button';
- import Form, {FormProps} from 'sentry/components/forms/form';
- import JsonForm from 'sentry/components/forms/jsonForm';
- import PanelAlert from 'sentry/components/panels/panelAlert';
- import PanelItem from 'sentry/components/panels/panelItem';
- import accountPasswordFields from 'sentry/data/forms/accountPassword';
- import {t} from 'sentry/locale';
- import ConfigStore from 'sentry/stores/configStore';
- type OnSubmitSuccess = Parameters<NonNullable<FormProps['onSubmitSuccess']>>;
- function PasswordForm() {
- function handleSubmitSuccess(_change: OnSubmitSuccess[0], model: OnSubmitSuccess[1]) {
- // Reset form on success
- model.resetForm();
- addSuccessMessage('Password has been changed');
- }
- function handleSubmitError() {
- addErrorMessage('Error changing password');
- }
- const user = ConfigStore.get('user');
- return (
- <Form
- apiMethod="PUT"
- apiEndpoint="/users/me/password/"
- initialData={{}}
- onSubmitSuccess={handleSubmitSuccess}
- onSubmitError={handleSubmitError}
- hideFooter
- >
- <JsonForm
- forms={accountPasswordFields}
- additionalFieldProps={{user}}
- renderFooter={() => (
- <Actions>
- <Button type="submit" priority="primary">
- {t('Change password')}
- </Button>
- </Actions>
- )}
- renderHeader={() => (
- <PanelAlert type="info">
- {t('Changing your password will invalidate all logged in sessions.')}
- </PanelAlert>
- )}
- />
- </Form>
- );
- }
- const Actions = styled(PanelItem)`
- justify-content: flex-end;
- `;
- export default PasswordForm;
|