Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function* updateEvent(form, event) {
try {
// indicate start submitting form
yield put(startSubmit(form))
// update event into database
yield call(eventCrud.update, event)
// update event in store
yield put(eventsData.update(event))
// set form submitted
yield put(stopSubmit(form))
} catch (error) {
yield put(stopSubmit(form, { _error: error.message }))
throw error
}
}
function* submitTalkToEvent({ talkId, eventId, data }) {
const FORM = 'submit-talk'
const talk = yield select(talksData.get(talkId))
try {
// indicate start submitting form
yield put(startSubmit(FORM))
// check if it's already submitted
const alreadySubmitted = yield select(isSubmitted(talkId, eventId))
// submit talk
yield call(saveTalkSubmission, talk, eventId, data, alreadySubmitted)
// set form submitted
yield put(stopSubmit(FORM))
yield put({ type: 'SUBMISSION_NEXT_STEP' })
} catch (error) {
yield put(stopSubmit(FORM, { _error: error.message }))
throw error
}
}
function* createOrUpdateTalk(form, talk) {
try {
// indicate start submitting form
yield put(startSubmit(form))
if (form === 'talk-create') {
// get user id
const uid = yield select(getUserId)
// create talk into database
const ref = yield call(talkCrud.create, { ...talk, speakers: { [uid]: true } })
// go to talk page
yield put(push(`/speaker/talk/${ref.id}`))
// reset form
yield put(reset(form))
} else {
// update talk into database
yield call(talkCrud.update, talk)
// update talk into store
yield put(talkData.update(talk))
// go to talk page
yield put(push(`/speaker/talk/${talk.id}`))
const asyncSubmit = (name, dispatch, getState) => async (callback, ...args) => {
dispatch(startSubmit(name))
const response = await callback(...args)
if (isSubmitting(name)(getState())) dispatch(stopSubmit(name))
return response
}
export const updateClassify = classify => dispatch => {
dispatch(startSubmit(FORM_CLASSIFY));
const url = CLASSIFY_API_URL + `/${classify.id}`;
return _put(url,classify)
.then(result => {
dispatch(stopSubmit(FORM_CLASSIFY,result.errors));
if(result.code === 200){
dispatch(success("更新文章分类成功"));
dispatch(updateClassifyResponse(result));
dispatch(setClassifyLoading(false))
}
else {
dispatch(error(result.message));
}
})
};
export const insertComment = comment => (dispatch,getState) => {
dispatch(startSubmit(FORM_COMMENT));
const articleId = getState().content.article.id;
const url = ARTICLE_API_URL + `/${articleId}/comment/`;
return _post(url,comment)
.then(result => {
dispatch(setPreviousComment(initialPreviousComment));
dispatch(stopSubmit(FORM_COMMENT,result.errors));
if(result.code === 200){
dispatch(success("新增评论成功"));
dispatch(insertCommentResponse(result));
reloadComments(dispatch,getState);
}
else {
export const updateUserInfo = user => dispatch => {
const url = USER_API_URL + `/${user.id}`;
dispatch(startSubmit(FORM_USERINFO));
return _put(url,user)
.then(result => {
dispatch(stopSubmit(FORM_USERINFO,result.errors));
if(result.code === 200){
dispatch(setUserInfoModalShow(false));
dispatch(setLoginUser(result.entity));
dispatch(success("修改个人信息成功"));
dispatch(updateUserInfoResponse(result))
}
else{
dispatch(error(result.message));
}
});
};
export const saveZoneFeed = action => [
startSubmit( action.form ),
removeNotice( saveFeedNotice ),
resetLock( action.siteId, action.zoneId ),
http(
{
method: 'POST',
path: `/jetpack-blogs/${ action.siteId }/rest-api/`,
query: {
body: JSON.stringify( toApi( action.posts ) ),
json: true,
path: `/zoninator/v1/zones/${ action.zoneId }/posts&_method=PUT`,
},
},
action
),
];
return dispatch => {
dispatch(startSubmit('company'));
return dispatch(
callAPI({
types: Company.ADD,
endpoint: '/bdb/',
method: 'POST',
body: data,
schema: companySchema,
meta: {
errorMessage: 'Legg til bedrift feilet'
}
})
)
.then(action => {
if (!action || !action.payload) return;
const id = action.payload.result;
dispatch(stopSubmit('company'));
export const saveSettings = ( { dispatch }, action ) => {
const { data, form, siteId } = action;
dispatch( startSave( form ) );
dispatch( removeNotice( 'wpjm-settings-save' ) );
dispatch( http( {
method: 'POST',
path: `/jetpack-blogs/${ siteId }/rest-api/`,
query: {
body: JSON.stringify( toApi( data ) ),
json: true,
path: '/wpjm/v1/settings',
},
}, action ) );
};