1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-12 13:00:04 +02:00
copilot/spikes/form/redux-form/client/form/submit.js

19 lines
678 B
JavaScript

const SubmissionError = require('redux-form').SubmissionError;
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
function submit(values) {
return sleep(1000) // simulate server latency
.then(() => {
if (![ 'john', 'paul', 'george', 'ringo' ].includes(values.username)) {
throw new SubmissionError({ username: 'User does not exist', _error: 'Login failed!' })
} else if (values.password !== 'redux-form') {
throw new SubmissionError({ password: 'Wrong password', _error: 'Login failed!' })
} else {
window.alert(`You submitted:\n\n${JSON.stringify(values, null, 2)}`)
}
})
}
module.exports = submit;