"use client"; import { memo, 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"; interface InnerProps { presentAppIds: string[]; onSelect: (props: RouterOutputs["app"]["selectable"][number]) => void | Promise; confirmLabel?: string; } interface AppSelectFormType { id: string; } export const AppSelectModal = createModal(({ actions, innerProps }) => { const t = useI18n(); const { data: apps, isPending } = clientApi.app.selectable.useQuery(); const [loading, setLoading] = useState(false); const form = useForm(); const handleSubmitAsync = async (values: AppSelectFormType) => { const currentApp = apps?.find((app) => app.id === values.id); if (!currentApp) return; setLoading(true); await innerProps.onSelect(currentApp); setLoading(false); actions.closeModal(); }; const confirmLabel = innerProps.confirmLabel ?? t("common.action.add"); const currentApp = apps?.find((app) => app.id === form.values.id); return (
void handleSubmitAsync(values))}>