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

Import Egg

{ fetchFileContent = value; }} language={LanguageDescription.of({ name: 'json', support: json() })} />
setVisible(false)} > Cancel
); };