Closed stefensuhat closed 7 years ago
Hey. I dont rly understand ur first problem. Your actions seems to be plain objects and you have not specified anything more about the problem.
As to the second one - is that all of your code? Sagas are not scoped per component but rather acting like a global listeners + handlers. Your doSignIn should be called whenever authRequest action happens. I have a little problem with reading the code on my mobile but I think u pass to the takeLatest a function (action creator) and not an action type which might lead to unwanted calls in your scenario
@Andarist yeah I still stuck and can't solve it. If I change to fork
the method never get call even the button is pressed.
Any code you want to look at? I will post it if you need more
Looking at the originally posted code, you need to change this takeLatest(actions.authRequest, doSignIn)
to takeLatest(AUTH_REQUEST, doSignIn)
.
And also this part:
yield put(actions.sendingRequest);
const { email, password } = yield put(actions.authRequest);
Looks really weird. Doing like so you are dispatching functions and not actions.
Probably what you were looking for is something along theese lines:
// action parameter is available here thanks to takeLatest running your 'doSignIn' with it
export function* doSignIn(action) {
const { email, password } = action;
try {
yield put(actions.sendingRequest()); // changed here actions.sendingRequest to actions.sendingRequest()
const signin = yield call(axios.post, url, { email, password });
yield put(actions.loginUser(signin));
} catch (err) {
yield put(actions.authError(err));
}
}
If you still need a help, please reopen this. Closing for now, as there was no activity here for over a month
Thanks @Andarist because now I know "export function* doSignIn(action) // action parameter is available here thanks to takeLatest running your 'doSignIn' with it".
*
* DeleteConfirmationModal
*
*/
import React from 'react';
import saga from './saga';
import { compose} from 'redux';
import reducer from './reducer';
import { connect } from 'react-redux';
import injectSaga from "../../utils/injectSaga";
import { createStructuredSelector } from 'reselect';
import injectReducer from "../../utils/injectReducer";
import {submitDeleteConfirmationModalForm, toggleDeleteConfirmationModal} from "./actions";
import {
deleteConfirmationRecordId,
deleteConfirmationRecordIndex,
makeSelectDeleteConfirmationModalShow
} from './selectors';
import DeleteConfirmationForm from "./form";
/* eslint-disable react/prefer-stateless-function */
class DeleteConfirmationModal extends React.PureComponent {
constructor(props) {
super(props);
this.toggleModal = this.toggleModal.bind(this);
}
toggleModal() {
const {toggleModal} = this.props;
toggleModal();
}
render() {
const {show, itemName, onModalFormSubmit, id, index} = this.props;
return (
<div id="modal_default" className="modal fade">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h5 className="modal-title">Delete {itemName}</h5>
</div>
<div className="modal-body">
<p>You have selected to delete this {itemName}</p>
<p>If this was the action that you wanted to do, please confirm your choice, or cancel and return to the
page</p>
<br/>
<DeleteConfirmationForm
id={id}
index={index}
onModalFormSubmit={onModalFormSubmit}
/>
</div>
<div className="modal-footer">
</div>
</div>
</div>
</div>
);
}
}
const mapStateToProps = createStructuredSelector({
id: deleteConfirmationRecordId(),
index: deleteConfirmationRecordIndex(),
show: makeSelectDeleteConfirmationModalShow(),
});
function mapDispatchToProps(dispatch) {
return {
toggleModal: () => dispatch(toggleDeleteConfirmationModal()),
onModalFormSubmit:(data) => dispatch(submitDeleteConfirmationModalForm(data)),
};
}
const withConnect = connect(
mapStateToProps,
mapDispatchToProps
);
const withReducer = injectReducer({ key: 'deleteConfirmationModal', reducer });
const withSaga = injectSaga({ key: 'deleteConfirmationModal', saga });
export default compose(
withReducer,
withSaga,
withConnect,
)(DeleteConfirmationModal);
/*
*
* DeleteConfirmationModal actions
*
*/
import {
SETUP_DELETE_CONFIRMATION_MODAL,
TOGGLE_DELETE_CONFIRMATION_MODAL,
SUBMIT_DELETE_CONFIRMATION_MODAL_FORM,
} from './constants';
export function toggleDeleteConfirmationModal(forceAction = null) {
return {
type: TOGGLE_DELETE_CONFIRMATION_MODAL,
forceAction,
}
}
export function setupDeleteConfirmationModal(payload) {
return {
type: SETUP_DELETE_CONFIRMATION_MODAL,
payload,
}
}
export function submitDeleteConfirmationModalForm(params) {
return {
type: SUBMIT_DELETE_CONFIRMATION_MODAL_FORM,
params,
}
}
import {
SUBMIT_DELETE_CONFIRMATION_MODAL_FORM,
} from "./constants";
import LocationsApi from "../../api/LocationsApi";
import {put, all, takeLatest,} from 'redux-saga/effects';
import {submitDeleteConfirmationModalFormSuccess} from "../Location/actions";
function* submitDeleteConfirmationModalForm(action) {
try {
const id = action.params.id;
const index = action.params.index;
const response = yield LocationsApi.delete(id);
if (response.status && response.status === 'ok') {
localStorage.removeItem('location' + index);
localStorage.setItem('locations_length', parseInt(localStorage.getItem('locations_length')) - 1);
yield put($('#modal_default').modal('hide'));
yield put(submitDeleteConfirmationModalFormSuccess(id));
}
}catch (error) {
}
}
function* watchAll() {
yield all([takeLatest(SUBMIT_DELETE_CONFIRMATION_MODAL_FORM, submitDeleteConfirmationModalForm)]);
}
export default watchAll;
I am getting this error since yesterday, trying to resolve it but still failed.
utils.js?56bd:225 uncaught at submitDeleteConfirmationModalForm Error: Actions must be plain objects. Use custom middleware for async actions.
at Object.performAction (<anonymous>:1:42634)
at liftAction (<anonymous>:1:36073)
at dispatch (<anonymous>:1:40184)
at eval (webpack-internal:///823:22:18)
at eval (webpack-internal:///1041:70:22)
at dispatch (webpack-internal:///41:619:28)
at eval (webpack-internal:///42:282:12)
at eval (webpack-internal:///491:498:52)
at exec (webpack-internal:///420:22:5)
at flush (webpack-internal:///420:63:5)
I'm still learning about
redux-saga
but stuck at 2 problem.Here is my code:
The problem is:
Actions must be plain objects. Use custom middleware for async actions
Any solution?