import React, { FC, useState } from 'react'; import { Button, Input, Modal } from 'antd'; import { STATUS_ERROR, STATUS_SUCCESS } from '../utils/input-statuses'; import { fetchData, FEDERATION_MESSAGE_SEND } from '../utils/apis'; const { TextArea } = Input; export type ComposeFederatedPostProps = { open: boolean; handleClose: () => void; }; export const ComposeFederatedPost: FC = ({ open, handleClose }) => { const [content, setContent] = useState(''); const [postPending, setPostPending] = useState(false); const [postSuccessState, setPostSuccessState] = useState(null); function handleEditorChange(e) { setContent(e.target.value); } function close() { setPostPending(false); setPostSuccessState(null); handleClose(); } async function sendButtonClicked() { setPostPending(true); const data = { value: content, }; try { await fetchData(FEDERATION_MESSAGE_SEND, { data, method: 'POST', auth: true, }); setPostSuccessState(STATUS_SUCCESS); setTimeout(close, 1000); } catch (e) { // eslint-disable-next-line no-console console.error(e); setPostSuccessState(STATUS_ERROR); } setPostPending(false); } return ( handleClose()}>Cancel, , ]} >