import { URLS } from "../api/apiConfig";
import { TAxios } from "../api/TAxios";
import { types } from "./actionTypes";

export const getAuthenticationCode = () => (dispatch, getState) => {
  const onSuccess = (response) => {
    console.log("getAuthenticationCode onSuccess: ", response.data);

    dispatch({
      type: types.GET_AUTHENTICATION_CODE,
      payload: response.data.data.accessToken,
    });
  };

  const onFail = (error) => {
    console.error("getAuthenticationCode onFail: ", error);
  };

  TAxios(
    dispatch,
    getState,
    "get",
    URLS.GET_AUTHENTICATION_CODE,
    {},
    {},
    onSuccess,
    onFail
  );
};
