mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 09:18:59 +00:00
69 lines
1.9 KiB
JavaScript
69 lines
1.9 KiB
JavaScript
import React, { Component } from "react";
|
|
import PropTypes from "prop-types";
|
|
|
|
import ReactTooltip from "react-tooltip";
|
|
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";
|
|
import validate from "components/forms/UserSettingsForm/validate";
|
|
|
|
const formFields = ["email", "name", "position", "username"];
|
|
|
|
const baseClass = "manage-user";
|
|
|
|
class UserSettingsForm extends Component {
|
|
static propTypes = {
|
|
fields: PropTypes.shape({
|
|
email: formFieldInterface.isRequired,
|
|
name: formFieldInterface.isRequired,
|
|
position: formFieldInterface.isRequired,
|
|
}).isRequired,
|
|
handleSubmit: PropTypes.func.isRequired,
|
|
pendingEmail: PropTypes.string,
|
|
onCancel: PropTypes.func.isRequired,
|
|
};
|
|
|
|
renderEmailHint = () => {
|
|
const { pendingEmail } = this.props;
|
|
|
|
if (!pendingEmail) {
|
|
return undefined;
|
|
}
|
|
|
|
return (
|
|
<i className={`${baseClass}__email-hint`}>
|
|
Pending change to <b>{pendingEmail}</b>
|
|
</i>
|
|
);
|
|
};
|
|
|
|
render() {
|
|
const { fields, handleSubmit, onCancel } = this.props;
|
|
const { renderEmailHint } = this;
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit} className={baseClass}>
|
|
<InputField
|
|
{...fields.email}
|
|
autofocus
|
|
label="Email (required)"
|
|
hint={renderEmailHint()}
|
|
/>
|
|
<InputField {...fields.name} label="Full name (required)" />
|
|
<InputField {...fields.position} label="Position" />
|
|
<div className={`${baseClass}__button-wrap`}>
|
|
<Button onClick={onCancel} variant="inverse">
|
|
Cancel
|
|
</Button>
|
|
<Button type="submit" variant="brand">
|
|
Update
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default Form(UserSettingsForm, { fields: formFields, validate });
|