thecodingmachine / redux-toolkit-wrapper

Redux-toolkit wrapper used to write less code regarding classic CRUD operations.
MIT License
19 stars 5 forks source link

How do you make extraReducer with this? #15

Open bsor-dev opened 2 years ago

bsor-dev commented 2 years ago

This is not working for me

export const LoginT= createAsyncThunk('login/loginT', async () => {
  return new Promise(async (resolve, reject) => {
    const params = qs.stringify({
      ...
    })

    await api({
     ...
    })
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
})
export default {
  initialState: buildAsyncState('login'),
  action: buildAsyncActions('user/login', LoginApiService),
  reducers: {
    ...buildAsyncReducers({
      itemKey: 'token',
      loadingKey: 'login.loading',
      errorKey: 'login.error',
    }),
    rejected: (state, action) => {
      state.login.loading = false
      state.login.error = action.payload
    },
    pending: (state, action) => {
      state.login.loading = true
    },
    fulfilled: (state, { payload, type }) => {
      if (payload && payload.token) {
        state.token = payload
        state.isAuth = true
      }
      state.login.error = null
      state.login.loading = false
    },
  },
  extraReducers: (builder) => {
    builder
      .addCase(loginT.pending, (state) => {
        console.log('pendign')

      })
      .addCase(loginT.fulfilled, (state, action) => {
        console.log(action.payload)
        console.log('fulfilled')
      })
      .addCase(loginT.rejected, (state, action) => {
        console.log('what')
        state.login.loading = false
        state.login.error = action.payload
      })
  },
}

It doesn't reached the extrareducers, not working