import { Dropdown, Item, Form, FormRow, FormButtons, FormInput, TextField, SubmitButton, PasswordField, useToasts, } from 'react-basics'; import { useApi, useMessages } from 'components/hooks'; import { ROLES } from 'lib/constants'; import { useRef } from 'react'; export function UserEditForm({ userId, data }: { userId: string; data: object }) { const { formatMessage, labels, messages } = useMessages(); const { post, useMutation } = useApi(); const { mutate, error } = useMutation({ mutationFn: ({ username, password, role, }: { username: string; password: string; role: string; }) => post(`/users/${userId}`, { username, password, role }), }); const ref = useRef(null); const { showToast } = useToasts(); const handleSubmit = async (data: any) => { mutate(data, { onSuccess: async () => { showToast({ message: formatMessage(messages.saved), variant: 'success' }); ref.current.reset(data); }, }); }; const renderValue = (value: string) => { if (value === ROLES.user) { return formatMessage(labels.user); } if (value === ROLES.admin) { return formatMessage(labels.administrator); } if (value === ROLES.viewOnly) { return formatMessage(labels.viewOnly); } }; return (
{formatMessage(labels.viewOnly)} {formatMessage(labels.user)} {formatMessage(labels.administrator)} {formatMessage(labels.save)}
); } export default UserEditForm;