import getEggs from '@/api/admin/nests/getEggs'; import importEgg from '@/api/admin/nests/importEgg'; import useFlash from '@/plugins/useFlash'; import { jsonLanguage } from '@codemirror/lang-json'; import Editor from '@/components/elements/Editor'; import React, { useState } from 'react'; import Button from '@/components/elements/Button'; import Modal from '@/components/elements/Modal'; import FlashMessageRender from '@/components/FlashMessageRender'; import { useRouteMatch } from 'react-router-dom'; import tw from 'twin.macro'; export default ({ className }: { className?: string }) => { const [ visible, setVisible ] = useState(false); const { clearFlashes } = useFlash(); const match = useRouteMatch<{ nestId: string }>(); const { mutate } = getEggs(Number(match.params.nestId)); let fetchFileContent: (() => Promise) | null = null; const submit = async () => { clearFlashes('egg:import'); if (fetchFileContent === null) { return; } const egg = await importEgg(Number(match.params.nestId), await fetchFileContent()); await mutate(data => ({ ...data!, items: [ ...data!.items!, egg ] })); setVisible(false); }; return ( <> { setVisible(false); }} >

Import Egg

{ fetchFileContent = value; }} />
); };