2020-08-09 08:48:43 +02:00
|
|
|
import React, { useState } from 'react';
|
2020-09-06 02:27:01 +02:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2020-09-19 19:35:05 +02:00
|
|
|
import { useSelector } from 'react-redux';
|
2020-08-12 07:24:41 +02:00
|
|
|
import PageHeader from 'components/layout/PageHeader';
|
|
|
|
import Button from 'components/common/Button';
|
|
|
|
import Modal from 'components/common/Modal';
|
2020-09-06 02:27:01 +02:00
|
|
|
import Toast from 'components/common/Toast';
|
|
|
|
import ChangePasswordForm from 'components/forms/ChangePasswordForm';
|
2020-09-19 19:35:05 +02:00
|
|
|
import TimezoneSetting from 'components/settings/TimezoneSetting';
|
2020-08-15 10:17:15 +02:00
|
|
|
import Dots from 'assets/ellipsis-h.svg';
|
2020-09-17 09:17:11 +02:00
|
|
|
import styles from './ProfileSettings.module.css';
|
2020-09-19 19:35:05 +02:00
|
|
|
import DateRangeSetting from './DateRangeSetting';
|
2020-09-30 01:25:21 +02:00
|
|
|
import useEscapeKey from 'hooks/useEscapeKey';
|
2020-08-09 08:48:43 +02:00
|
|
|
|
|
|
|
export default function ProfileSettings() {
|
|
|
|
const user = useSelector(state => state.user);
|
|
|
|
const [changePassword, setChangePassword] = useState(false);
|
2020-09-01 00:57:59 +02:00
|
|
|
const [message, setMessage] = useState();
|
2020-08-09 11:03:37 +02:00
|
|
|
const { user_id } = user;
|
2020-08-09 08:48:43 +02:00
|
|
|
|
2020-09-01 00:57:59 +02:00
|
|
|
function handleSave() {
|
|
|
|
setChangePassword(false);
|
2020-09-06 02:27:01 +02:00
|
|
|
setMessage(<FormattedMessage id="message.save-success" defaultMessage="Saved successfully." />);
|
2020-09-01 00:57:59 +02:00
|
|
|
}
|
|
|
|
|
2020-09-30 01:25:21 +02:00
|
|
|
useEscapeKey(() => {
|
|
|
|
setChangePassword(false);
|
|
|
|
});
|
|
|
|
|
2020-08-09 08:48:43 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<PageHeader>
|
2020-09-06 02:27:01 +02:00
|
|
|
<div>
|
2020-09-17 07:29:40 +02:00
|
|
|
<FormattedMessage id="label.profile" defaultMessage="Profile" />
|
2020-09-06 02:27:01 +02:00
|
|
|
</div>
|
2020-08-15 10:17:15 +02:00
|
|
|
<Button icon={<Dots />} size="small" onClick={() => setChangePassword(true)}>
|
2020-10-13 07:53:59 +02:00
|
|
|
<FormattedMessage id="label.change-password" defaultMessage="Change password" />
|
2020-08-09 08:48:43 +02:00
|
|
|
</Button>
|
|
|
|
</PageHeader>
|
2020-09-19 19:35:05 +02:00
|
|
|
<dl className={styles.list}>
|
2020-09-06 02:27:01 +02:00
|
|
|
<dt>
|
|
|
|
<FormattedMessage id="label.username" defaultMessage="Username" />
|
|
|
|
</dt>
|
2020-08-09 11:03:37 +02:00
|
|
|
<dd>{user.username}</dd>
|
2020-09-17 09:17:11 +02:00
|
|
|
<dt>
|
|
|
|
<FormattedMessage id="label.timezone" defaultMessage="Timezone" />
|
|
|
|
</dt>
|
2020-09-19 19:35:05 +02:00
|
|
|
<dd>
|
|
|
|
<TimezoneSetting />
|
|
|
|
</dd>
|
2020-09-17 09:17:11 +02:00
|
|
|
<dt>
|
|
|
|
<FormattedMessage id="label.default-date-range" defaultMessage="Default date range" />
|
|
|
|
</dt>
|
2020-09-19 19:35:05 +02:00
|
|
|
<dd>
|
|
|
|
<DateRangeSetting />
|
2020-09-17 09:17:11 +02:00
|
|
|
</dd>
|
2020-08-09 11:03:37 +02:00
|
|
|
</dl>
|
2020-08-09 08:48:43 +02:00
|
|
|
{changePassword && (
|
2020-09-12 12:22:14 +02:00
|
|
|
<Modal
|
2020-10-13 07:53:59 +02:00
|
|
|
title={<FormattedMessage id="label.change-password" defaultMessage="Change password" />}
|
2020-09-12 12:22:14 +02:00
|
|
|
>
|
2020-08-09 11:03:37 +02:00
|
|
|
<ChangePasswordForm
|
|
|
|
values={{ user_id }}
|
2020-09-01 00:57:59 +02:00
|
|
|
onSave={handleSave}
|
2020-08-09 11:03:37 +02:00
|
|
|
onClose={() => setChangePassword(false)}
|
|
|
|
/>
|
2020-08-09 08:48:43 +02:00
|
|
|
</Modal>
|
|
|
|
)}
|
2020-09-01 00:57:59 +02:00
|
|
|
{message && <Toast message={message} onClose={() => setMessage(null)} />}
|
2020-08-09 08:48:43 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|