import { useState } from "react"; import type { SelectProps } from "@mantine/core"; import { Button, Group, Loader, Select, Stack } from "@mantine/core"; import { IconCheck } from "@tabler/icons-react"; import type { RouterOutputs } from "@homarr/api"; import { clientApi } from "@homarr/api/client"; import { useForm } from "@homarr/form"; import { createModal } from "@homarr/modals"; import { useI18n } from "@homarr/translation/client"; import { UserAvatar } from "@homarr/ui"; interface InnerProps { presentUserIds: string[]; onSelect: (props: { id: string; name: string; image: string }) => void | Promise; confirmLabel?: string; } interface UserSelectFormType { userId: string; } export const UserSelectModal = createModal(({ actions, innerProps }) => { const t = useI18n(); const { data: users, isPending } = clientApi.user.selectable.useQuery(); const [loading, setLoading] = useState(false); const form = useForm(); const handleSubmitAsync = async (values: UserSelectFormType) => { const currentUser = users?.find((user) => user.id === values.userId); if (!currentUser) return; setLoading(true); await innerProps.onSelect({ id: currentUser.id, name: currentUser.name ?? "", image: currentUser.image ?? "", }); setLoading(false); actions.closeModal(); }; const confirmLabel = innerProps.confirmLabel ?? t("common.action.add"); const currentUser = users?.find((user) => user.id === form.values.userId); return (
void handleSubmitAsync(values))}>