mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Refactored user components.
This commit is contained in:
parent
91af593ff5
commit
cdd54df8f6
16 changed files with 180 additions and 231 deletions
46
components/pages/settings/profile/PasswordChangeButton.js
Normal file
46
components/pages/settings/profile/PasswordChangeButton.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { useState } from 'react';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
import { Button, Icon, Text, Modal, useToast } from 'react-basics';
|
||||
import PasswordEditForm from 'components/pages/settings/profile/PasswordEditForm';
|
||||
import { Lock } from 'components/icons';
|
||||
|
||||
const messages = defineMessages({
|
||||
changePassword: { id: 'label.change-password', defaultMessage: 'Change password' },
|
||||
saved: { id: 'message.saved-successfully', defaultMessage: 'Saved successfully.' },
|
||||
});
|
||||
|
||||
export default function PasswordChangeButton() {
|
||||
const { formatMessage } = useIntl();
|
||||
const [edit, setEdit] = useState(false);
|
||||
const { toast, showToast } = useToast();
|
||||
|
||||
const handleSave = () => {
|
||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||
setEdit(false);
|
||||
};
|
||||
|
||||
const handleEdit = () => {
|
||||
setEdit(true);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setEdit(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{toast}
|
||||
<Button onClick={handleEdit}>
|
||||
<Icon>
|
||||
<Lock />
|
||||
</Icon>
|
||||
<Text>{formatMessage(messages.changePassword)}</Text>
|
||||
</Button>
|
||||
{edit && (
|
||||
<Modal title={formatMessage(messages.changePassword)} onClose={handleClose}>
|
||||
{() => <PasswordEditForm onSave={handleSave} onClose={handleClose} />}
|
||||
</Modal>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue