2021-04-12 13:32:25 +00:00
|
|
|
import React, { Component } from "react";
|
|
|
|
|
import PropTypes from "prop-types";
|
2016-12-13 15:24:58 +00:00
|
|
|
|
2021-06-24 20:42:29 +00:00
|
|
|
import ReactTooltip from "react-tooltip";
|
2021-04-12 13:32:25 +00:00
|
|
|
import Button from "components/buttons/Button";
|
|
|
|
|
import Form from "components/forms/Form";
|
|
|
|
|
import formFieldInterface from "interfaces/form_field";
|
|
|
|
|
import InputField from "components/forms/fields/InputField";
|
2016-12-13 15:24:58 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
const formFields = ["email", "name", "position", "username"];
|
2016-12-13 15:24:58 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
const baseClass = "manage-user";
|
2016-12-21 18:22:18 +00:00
|
|
|
|
2016-12-13 15:24:58 +00:00
|
|
|
class UserSettingsForm extends Component {
|
|
|
|
|
static propTypes = {
|
|
|
|
|
fields: PropTypes.shape({
|
|
|
|
|
email: formFieldInterface.isRequired,
|
|
|
|
|
name: formFieldInterface.isRequired,
|
|
|
|
|
position: formFieldInterface.isRequired,
|
|
|
|
|
}).isRequired,
|
|
|
|
|
handleSubmit: PropTypes.func.isRequired,
|
2017-02-24 15:08:59 +00:00
|
|
|
pendingEmail: PropTypes.string,
|
2016-12-13 15:24:58 +00:00
|
|
|
onCancel: PropTypes.func.isRequired,
|
|
|
|
|
};
|
|
|
|
|
|
2017-02-24 15:08:59 +00:00
|
|
|
renderEmailHint = () => {
|
|
|
|
|
const { pendingEmail } = this.props;
|
|
|
|
|
|
|
|
|
|
if (!pendingEmail) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<i className={`${baseClass}__email-hint`}>
|
|
|
|
|
Pending change to <b>{pendingEmail}</b>
|
|
|
|
|
</i>
|
|
|
|
|
);
|
2021-04-12 13:32:25 +00:00
|
|
|
};
|
2017-02-24 15:08:59 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
render() {
|
2016-12-13 15:24:58 +00:00
|
|
|
const { fields, handleSubmit, onCancel } = this.props;
|
2017-02-24 15:08:59 +00:00
|
|
|
const { renderEmailHint } = this;
|
2016-12-13 15:24:58 +00:00
|
|
|
|
|
|
|
|
return (
|
2016-12-21 18:22:18 +00:00
|
|
|
<form onSubmit={handleSubmit} className={baseClass}>
|
2016-12-13 15:24:58 +00:00
|
|
|
<InputField
|
|
|
|
|
{...fields.email}
|
2021-06-24 20:42:29 +00:00
|
|
|
autofocus
|
2016-12-13 15:24:58 +00:00
|
|
|
label="Email (required)"
|
2017-02-24 15:08:59 +00:00
|
|
|
hint={renderEmailHint()}
|
2016-12-13 15:24:58 +00:00
|
|
|
/>
|
2021-06-25 21:46:11 +00:00
|
|
|
<InputField {...fields.name} label="Full name (required)" />
|
2021-04-12 13:32:25 +00:00
|
|
|
<InputField {...fields.position} label="Position" />
|
2016-12-21 18:22:18 +00:00
|
|
|
<div className={`${baseClass}__button-wrap`}>
|
2021-04-12 13:32:25 +00:00
|
|
|
<Button onClick={onCancel} variant="inverse">
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
<Button type="submit" variant="brand">
|
|
|
|
|
Update
|
|
|
|
|
</Button>
|
2016-12-21 18:22:18 +00:00
|
|
|
</div>
|
2016-12-13 15:24:58 +00:00
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Form(UserSettingsForm, { fields: formFields });
|