import { Select, ListItem, Form, FormField, FormButtons, TextField, FormSubmitButton, PasswordField, useToast, } from '@umami/react-zen'; import { useApi, useLoginQuery, useMessages, useModified } from '@/components/hooks'; import { ROLES } from '@/lib/constants'; import { useContext } from 'react'; import { UserContext } from './UserProvider'; export function UserEditForm({ userId, onSave }: { userId: string; onSave?: () => void }) { const { formatMessage, labels, messages, getMessage } = useMessages(); const { post, useMutation } = useApi(); const user = useContext(UserContext); const { user: login } = useLoginQuery(); const { toast } = useToast(); const { touch } = useModified(); const { mutate, error } = useMutation({ mutationFn: ({ username, password, role, }: { username: string; password: string; role: string; }) => post(`/users/${userId}`, { username, password, role }), }); const handleSubmit = async (data: any) => { mutate(data, { onSuccess: async () => { toast(formatMessage(messages.saved)); touch(`user:${user.id}`); onSave?.(); }, }); }; return (
); }