import { useMutation, useQuery, useQueryClient } from "react-query"; import { fetchGuildChannels, postGuildTodo } from "../../api"; import { useGuild } from "../App/useGuild"; import { useState } from "preact/hooks"; import { useFlash } from "../App/FlashContext"; import { ICON_FLASH_TIME } from "../../consts"; export const CreateTodo = ({ showSelector = false, channel }) => { const guild = useGuild(); const [recentlyCreated, setRecentlyCreated] = useState(false); const [newTodo, setNewTodo] = useState({ value: "", channel_id: channel }); const flash = useFlash(); const { isSuccess, data: channels } = useQuery(fetchGuildChannels(guild)); const queryClient = useQueryClient(); const mutation = useMutation({ ...postGuildTodo(guild), onSuccess: (data) => { if (data.error) { flash({ message: data.error, type: "error", }); } else { flash({ message: "Todo created", type: "success", }); queryClient.invalidateQueries({ queryKey: ["GUILD_TODOS", guild], }); setRecentlyCreated(true); setTimeout(() => { setRecentlyCreated(false); }, ICON_FLASH_TIME); } }, }); return (