Подскажите пожалуйста, как передать данные через action в redux toolkit так, чтобы redux saga их подхватила при нужном типе action?
const onSubmit: SubmitHandler<ILoginInputs> = async (data) => {
dispatch(fetchSignIn(data))
}
const usersSlice = createSlice({
name: 'users',
initialState: {
data: undefined,
isAuth: false,
},
reducers: {
fetchSignIn: (data: ILoginInputs) => {
return data
},
setUserData: (state, action) => {
state.data = action.payload
},
setAuth: (state, action) => {
state.isAuth = action.payload
},
},
})
export default usersSlice.reducer
export const { fetchSignIn, setUserData, setAuth } = usersSlice.actions
export function* fetchLoginWorker(payload: any): Generator<any> {
try {
const response: any = yield call(AuthApi.login, payload)
localStorage.setItem('token', response.data.accessToken)
yield put(setAuth(true))
yield put(setUserData(response.data.user))
} catch (e) {
console.log(e.response?.data?.message)
}
}
export function* usersSaga() {
yield takeEvery(fetchSignIn.type, fetchLoginWorker)
}