Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// api call
const request = saga.next().value;
expect(request).toEqual(call(userApi.register, payload));
// api error
const error = 'error';
const response = saga.throw({ data: error }).value;
expect(response).toEqual(put({
type: REGISTER_ERROR,
payload: { error },
}));
// stop form submit
const stoppedSubmit = saga.next().value;
expect(stoppedSubmit).toEqual(put(stopSubmit(REGISTER)));
});
});
const FORM = 'event-create'
try {
// indicate start submitting form
yield put(startSubmit(FORM))
// get user id
const uid = yield select(getUserId)
// create event into database
const ref = yield call(eventCrud.create, { ...event, owner: uid })
// reset form
yield put(reset(FORM))
// set form submitted
yield put(stopSubmit(FORM))
// go to event page
yield put(push(`/organizer/event/${ref.id}`))
} catch (error) {
yield put(stopSubmit(FORM, { _error: error.message }))
throw error
}
}
export function* createCollectionF(): any {
while (true) {
const { collection } = yield take(CREATE_COLLECTION);
yield all([
put(jobStatus(true)),
put(startSubmit('add_or_edit_collection')),
]);
const { response, error } = yield call(createCollection, collection);
yield all([
put(jobStatus(false)),
put(stopSubmit('add_or_edit_collection')),
]);
if (response) {
// update the entity
// NOTE: the user collection locate in userCollections
yield put(setItem('userCollections', response));
// get current search path in url if startsWith ?add_to_collection&id=
const { search } = getHistory().location;
const searchParams = new URLSearchParams(search);
if (searchParams.has('step') && searchParams.has('id')) {
// get id from url
yield put(push(`?add_to_collection&id=${searchParams.get('id')}`));
} else {
yield put(push(`/collections/${response.id}`));
}
} else {
yield fork(handleCommonErr, error, CREATE_COLLECTION, { collection });
function* createEvent(event) {
const FORM = 'event-create'
try {
// indicate start submitting form
yield put(startSubmit(FORM))
// get user id
const uid = yield select(getUserId)
// create event into database
const ref = yield call(eventCrud.create, { ...event, owner: uid })
// reset form
yield put(reset(FORM))
// set form submitted
yield put(stopSubmit(FORM))
// go to event page
yield put(push(`/organizer/event/${ref.id}`))
} catch (error) {
yield put(stopSubmit(FORM, { _error: error.message }))
throw error
}
}
.then(result => {
dispatch(setPreviousComment(initialPreviousComment));
dispatch(stopSubmit(FORM_COMMENT,result.errors));
if(result.code === 200){
dispatch(success("新增评论成功"));
dispatch(insertCommentResponse(result));
reloadComments(dispatch,getState);
}
else {
dispatch(error(result.message));
}
});
};
export function *handleEmit(action) {
yield put(socketRequest(action))
yield take(action.type)
yield put(startSubmit('login'))
yield take([action.payload.successType, action.payload.failureType])
yield put(stopSubmit('login'))
}
export const announceFailure = action => [
stopSubmit( action.form ),
errorNotice( translate( 'There was a problem saving your changes. Please try again' ), {
id: saveFeedNotice,
} ),
];
.then(result => {
dispatch(stopSubmit(FORM_REGISTER,result.errors));
if(result.code === 200){
dispatch(setRegisterModalShow(false));
dispatch(success("注册成功,开始登录"));
dispatch(registerUserResponse(result));
afterLogin(result,dispatch,true);
}
else {
dispatch(error(result.message));
}
})
};
return async (dispatch) => {
dispatch(startSubmit(FORM_ARTICLE));
const result = await fetchFunc();
dispatch(stopSubmit(FORM_ARTICLE, result.errors));
if (result.code === ApiResultCode.OK) {
msg.success(successMsg);
dispatch(articleResponseActionCreator(result.entity));
dispatch(listArticles(1, ARTICLE_PAGE_SIZE));
dispatch(listClassify());
if (extraSuccessFunc) {
await extraSuccessFunc(result);
}
} else {
msg.error(result.message);
}
};
}
.catch(action => {
const errors = { ...action.payload.response.jsonData };
dispatch(stopSubmit('comment', errors));
});
};