import React, { ChangeEvent, EventHandler, SyntheticEvent, useState } from "react"; import { Button } from "../common/Button"; import { InfoBox } from "../common/InfoBox"; const exampleInput = `{ "title": "Random example", "description": "Just a random description of a random example", "ids": [ "metaculus-372", "goodjudgmentopen-2244", "metaculus-7550", "kalshi-09d060ee-b184-4167-b86b-d773e56b4162", "wildeford-5d1a04e1a8", "metaculus-2817" ], "creator": "Peter Parker" }`; interface Props { handleSubmit: (data: any) => Promise; } export const DashboardCreator: React.FC = ({ handleSubmit }) => { const [value, setValue] = useState(exampleInput); const [acting, setActing] = useState(false); const handleChange = (event: ChangeEvent) => { setValue(event.target.value); }; const handleSubmitInner: EventHandler = async (event) => { event.preventDefault(); try { const newData = JSON.parse(value); if (!newData || !newData.ids || newData.ids.length == 0) { throw Error("Not enough objects"); } else { setActing(true); await handleSubmit(newData); setActing(false); } } catch (error) { setActing(false); const substituteText = `Error: ${error.message} Try something like: ${exampleInput} Your old input was: ${value}`; setValue(substituteText); } }; return (