/
editLead.js
37 lines (34 loc) · 1.13 KB
/
editLead.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { types } from "Actions"
import * as actions from "Actions"
import { select, take, put, call } from "redux-saga/effects"
import { push } from "react-router-redux"
import { prepareLeadDataForSend } from "../utils/prepare-data"
import API from "../api/index"
/**
* @param api {API} - this is this paramters
*/
export default function* editLead(api) {
while (true) {
const action = yield take(types.EDIT_LEAD_SUBMIT_FORM)
let { original_copy, values, agree_to_terms } = yield select(
state => state.editLead,
)
const prepData = prepareLeadDataForSend(values)
const lead = Object.assign(original_copy, prepData, {
agree_to_terms,
})
yield put(actions.editLead.editLeadLoadingStart())
let res = yield api.leads.editLeadsEditByForm({ lead })
yield put(actions.editLead.editLeadLoadingEnd())
if (res.error) {
const errors = res.error
for (let error in errors) {
yield put(actions.editLead.editLeadAddError(error, errors[error]))
}
} else {
yield put(actions.editLead.editLeadSubmitSuccess())
window.triggerFetch()
yield put(push("/my-leads"))
}
}
}