({ok, status, body: {error}}) => { env.swap(pipe( alter(putIn, xhrPath, null), alter(putIn, xhrMessagePath, ok ? okMessage : null), alter(putIn, xhrErrorPath, ok ? null : error || `Unexpected error (status ${status})`), )) }).start())
function request (read, env) { const okMessage = 'Thank you! We will contact you as soon as possible.' env.swap(pipe( alter(putIn, xhrMessagePath, null), alter(putIn, xhrErrorPath, null), alter(putIn, xhrPath, Xhr({ url: 'https://formspree.io/info@purelab.io', method: 'post', headers: { accept: 'application/json', 'content-type': 'application/json;charset=UTF-8', }, body: { email: read(...emailPath), name: read(...namePath), message: read(...messagePath) } }, ({ok, status, body: {error}}) => { env.swap(pipe( alter(putIn, xhrPath, null), alter(putIn, xhrMessagePath, ok ? okMessage : null), alter(putIn, xhrErrorPath, ok ? null : error || `Unexpected error (status ${status})`), )) }).start()) )) }