actionRegister.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { call, put, select } from "redux-saga/effects";
  2. import { gql } from "../helpers";
  3. import { actionPromise } from "../reducers";
  4. import { promiseWorker } from "../reducers/promiseReducer";
  5. import { actionLogin } from "./actionLogin";
  6. export const actionRegister = (username, password) => ({ type: "REGISTER", payload: { username, password } });
  7. export function* registerWorker(action) {
  8. const { username, password } = action.payload || {};
  9. yield call(
  10. promiseWorker,
  11. actionPromise(
  12. "register",
  13. gql(
  14. `mutation register($username:String,$password:String){
  15. UserUpsert(user:{username:$username,password:$password}){
  16. _id username
  17. }
  18. }`,
  19. {
  20. username,
  21. password,
  22. }
  23. )
  24. )
  25. );
  26. const {
  27. promise: { register },
  28. } = yield select();
  29. if (register.status === "FULFILLED") {
  30. yield put(actionLogin(username, password));
  31. }
  32. }