import { find } from "lodash"; import { observer } from "mobx-react"; import { BuildingBlocksIcon } from "outline-icons"; import * as React from "react"; import { useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { IntegrationService, IntegrationType } from "@shared/types"; import Integration from "~/models/Integration"; import Button from "~/components/Button"; import Heading from "~/components/Heading"; import Input from "~/components/Input"; import Scene from "~/components/Scene"; import useStores from "~/hooks/useStores"; import useToasts from "~/hooks/useToasts"; import SettingRow from "./components/SettingRow"; type FormData = { drawIoUrl: string; }; function SelfHosted() { const { integrations } = useStores(); const { t } = useTranslation(); const { showToast } = useToasts(); const integration = find(integrations.orderedData, { type: IntegrationType.Embed, service: IntegrationService.Diagrams, }) as Integration | undefined; const { register, reset, handleSubmit: formHandleSubmit, formState, } = useForm({ mode: "all", defaultValues: { drawIoUrl: integration?.settings.url, }, }); React.useEffect(() => { integrations.fetchPage({ type: IntegrationType.Embed, }); }, [integrations]); React.useEffect(() => { reset({ drawIoUrl: integration?.settings.url }); }, [integration, reset]); const handleSubmit = React.useCallback( async (data: FormData) => { try { if (data.drawIoUrl) { await integrations.save({ id: integration?.id, type: IntegrationType.Embed, service: IntegrationService.Diagrams, settings: { url: data.drawIoUrl, }, }); } else { await integration?.delete(); } showToast(t("Settings saved"), { type: "success", }); } catch (err) { showToast(err.message, { type: "error", }); } }, [integrations, integration, t, showToast] ); return ( }> {t("Self Hosted")}
); } export default observer(SelfHosted);