import React, {useState} from 'react'; import {csrfToken, postJson} from '../api'; import Modal from './Modal'; // The to-do row asking for an email, on the home page. The address is entered // in a dialog over the page, and saying no thanks, or changing your mind about // it, happen in place. Saving is an ordinary form post, because the list // changes when it's saved (there is a link to confirm it). // // It renders the contents of the row: the server's own markup for the same row // is inside the island's element, for anyone without JavaScript. export default function EmailStep({number, declined: initiallyDeclined, urls, labels}) { const [declined, setDeclined] = useState(initiallyDeclined); const [open, setOpen] = useState(false); const [busy, setBusy] = useState(false); const [error, setError] = useState(''); async function decline() { setBusy(true); setError(''); try { const {ok} = await postJson(urls.decline, {}); if (ok) { setDeclined(true); setOpen(false); } else { setError(labels.error); } } catch (failure) { setError(labels.error); } setBusy(false); } return ( <> {declined ? : number}