import { Trans } from "@lingui/macro" import { Box, Button, Checkbox, Group, PasswordInput, Stack, TextInput } from "@mantine/core" import { useForm } from "@mantine/form" import { client, errorToStrings } from "app/client" import type { AdminSaveUserRequest, UserModel } from "app/types" import { Alert } from "components/Alert" import { useAsyncCallback } from "react-async-hook" import { TbDeviceFloppy } from "react-icons/tb" interface UserEditProps { user?: UserModel onCancel: () => void onSave: () => void } export function UserEdit(props: UserEditProps) { const form = useForm({ initialValues: props.user ?? { name: "", enabled: true, admin: false, }, }) const saveUser = useAsyncCallback(client.admin.saveUser, { onSuccess: props.onSave }) return ( <> {saveUser.error && ( )}
Name} {...form.getInputProps("name")} required /> Password} {...form.getInputProps("password")} required={!props.user} /> E-mail} {...form.getInputProps("email")} /> Admin} {...form.getInputProps("admin", { type: "checkbox" })} /> Enabled} {...form.getInputProps("enabled", { type: "checkbox" })} />
) }