import { Dropdown, Item, Form, FormRow, FormButtons, FormInput, TextField, PasswordField, SubmitButton, Button, } from 'react-basics'; import { useIntl, defineMessages } from 'react-intl'; import useApi from 'hooks/useApi'; import { ROLES } from 'lib/constants'; import { labels } from 'components/messages'; const messages = defineMessages({ username: { id: 'label.username', defaultMessage: 'Username' }, password: { id: 'label.password', defaultMessage: 'Password' }, role: { id: 'label.role', defaultMessage: 'Role' }, user: { id: 'label.user', defaultMessage: 'User' }, admin: { id: 'label.admin', defaultMessage: 'Admin' }, }); export default function UserAddForm({ onSave, onClose }) { const { post, useMutation } = useApi(); const { mutate, error, isLoading } = useMutation(data => post(`/users`, data)); const { formatMessage } = useIntl(); const handleSubmit = async data => { mutate(data, { onSuccess: async () => { onSave(data); }, }); }; const renderValue = value => { if (value === ROLES.user) { return formatMessage(messages.user); } if (value === ROLES.admin) { return formatMessage(messages.admin); } }; return (
); }