2020-06-08 10:19:00 -05:00
|
|
|
import React, { FC } from 'react';
|
2021-05-25 07:48:16 -05:00
|
|
|
import { Button, Field, FieldSet, Form, Icon, Input, Tooltip } from '@grafana/ui';
|
2021-02-16 03:20:41 -06:00
|
|
|
import { UserDTO } from 'app/types';
|
2019-08-19 12:40:14 -05:00
|
|
|
import config from 'app/core/config';
|
2021-05-25 07:48:16 -05:00
|
|
|
import { ProfileUpdateFields } from './types';
|
2019-08-19 12:40:14 -05:00
|
|
|
|
|
|
|
export interface Props {
|
2021-05-25 07:48:16 -05:00
|
|
|
user: UserDTO | null;
|
2019-08-19 12:40:14 -05:00
|
|
|
isSavingUser: boolean;
|
|
|
|
updateProfile: (payload: ProfileUpdateFields) => void;
|
|
|
|
}
|
|
|
|
|
2020-06-08 10:19:00 -05:00
|
|
|
const { disableLoginForm } = config;
|
2019-08-19 12:40:14 -05:00
|
|
|
|
2020-06-08 10:19:00 -05:00
|
|
|
export const UserProfileEditForm: FC<Props> = ({ user, isSavingUser, updateProfile }) => {
|
|
|
|
const onSubmitProfileUpdate = (data: ProfileUpdateFields) => {
|
|
|
|
updateProfile(data);
|
2019-08-19 12:40:14 -05:00
|
|
|
};
|
|
|
|
|
2020-06-08 10:19:00 -05:00
|
|
|
return (
|
|
|
|
<Form onSubmit={onSubmitProfileUpdate} validateOn="onBlur">
|
|
|
|
{({ register, errors }) => {
|
|
|
|
return (
|
2021-03-31 18:07:37 -05:00
|
|
|
<FieldSet label="Edit profile">
|
2021-02-16 03:20:41 -06:00
|
|
|
<Field label="Name" invalid={!!errors.name} error="Name is required" disabled={disableLoginForm}>
|
|
|
|
<Input
|
2021-04-29 08:54:38 -05:00
|
|
|
{...register('name', { required: true })}
|
2021-05-25 07:48:16 -05:00
|
|
|
id="edit-user-profile-name"
|
2021-02-16 03:20:41 -06:00
|
|
|
placeholder="Name"
|
2021-05-25 07:48:16 -05:00
|
|
|
defaultValue={user?.name ?? ''}
|
2021-02-16 03:20:41 -06:00
|
|
|
suffix={<InputSuffix />}
|
|
|
|
/>
|
2020-06-08 10:19:00 -05:00
|
|
|
</Field>
|
|
|
|
<Field label="Email" invalid={!!errors.email} error="Email is required" disabled={disableLoginForm}>
|
|
|
|
<Input
|
2021-04-29 08:54:38 -05:00
|
|
|
{...register('email', { required: true })}
|
2021-05-25 07:48:16 -05:00
|
|
|
id="edit-user-profile-email"
|
2020-06-08 10:19:00 -05:00
|
|
|
placeholder="Email"
|
2021-05-25 07:48:16 -05:00
|
|
|
defaultValue={user?.email ?? ''}
|
2020-06-08 10:19:00 -05:00
|
|
|
suffix={<InputSuffix />}
|
|
|
|
/>
|
|
|
|
</Field>
|
|
|
|
<Field label="Username" disabled={disableLoginForm}>
|
2021-05-25 07:48:16 -05:00
|
|
|
<Input
|
|
|
|
{...register('login')}
|
|
|
|
id="edit-user-profile-username"
|
|
|
|
defaultValue={user?.login ?? ''}
|
|
|
|
placeholder="Username"
|
|
|
|
suffix={<InputSuffix />}
|
|
|
|
/>
|
2020-06-08 10:19:00 -05:00
|
|
|
</Field>
|
|
|
|
<div className="gf-form-button-row">
|
2021-05-25 07:48:16 -05:00
|
|
|
<Button variant="primary" disabled={isSavingUser} aria-label="Edit user profile save button">
|
2020-06-08 10:19:00 -05:00
|
|
|
Save
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</FieldSet>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
2019-08-19 12:40:14 -05:00
|
|
|
|
|
|
|
export default UserProfileEditForm;
|
2020-06-08 10:19:00 -05:00
|
|
|
|
|
|
|
const InputSuffix: FC = () => {
|
|
|
|
return disableLoginForm ? (
|
2021-03-31 18:07:37 -05:00
|
|
|
<Tooltip content="Login details locked because they are managed in another system.">
|
2020-06-08 10:19:00 -05:00
|
|
|
<Icon name="lock" />
|
|
|
|
</Tooltip>
|
|
|
|
) : null;
|
|
|
|
};
|