redux#ActionCreator TypeScript Examples

The following examples show how to use redux#ActionCreator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: getVIP.ts    From client with MIT License 6 votes vote down vote up
getVIP: ActionCreator<ThunkAction<
  void,
  AppState,
  any,
  Action
>> = () => async dispatch => {
  dispatch({ type: SET_ACCOUNT_LOADER, payload: true });

  try {
    const { data } = await axios.get(
      process.env.REACT_APP_API_URI + '/user/account/vip'
    );

    dispatch({ type: SET_ACCOUNT_INFO, payload: data });
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_ACCOUNT_LOADER, payload: false });
}
Example #2
Source File: verification.ts    From client with MIT License 6 votes vote down vote up
userVerification: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = () => async dispatch => {
  try {
    if (localStorage.nyxToken) {
      const { data } = await axios.post(
        process.env.REACT_APP_API_URI + '/user/account/verify'
      );

      dispatch({
        type: LOGIN,
        payload: data
      });
    } else {
      dispatch({
        type: LOGIN_FAILED
      });
    }
  } catch (error) {
    dispatch({
      type: LOGOUT
    });

    dispatch({
      type: LOGIN_FAILED
    });
  }
}
Example #3
Source File: logout.ts    From client with MIT License 6 votes vote down vote up
userLogout: ActionCreator<ThunkAction<void, AppState, any, Action>> = (
  history: any
) => dispatch => {
  delete localStorage.nyxToken;

  dispatch({
    type: LOGOUT
  });

  history.push('/');
}
Example #4
Source File: login.ts    From client with MIT License 6 votes vote down vote up
userLogin: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = ({ username, password }, history) => async dispatch => {
  dispatch({ type: SET_LOGIN_LOADER, payload: true });

  try {
    const { data } = await axios.post(
      process.env.REACT_APP_API_URI + '/user/account/auth',
      { username, password }
    );

    localStorage.nyxToken = data.jwt_token;
    axios.defaults.headers.common.nyxAuthToken = data.jwt_token;

    dispatch({ type: LOGIN, payload: data });
    notice(data);

    if (!window.location.pathname.includes('/user/')) {
      history.push('/user/account/logs');
    }
  } catch (error) {
    dispatch({ type: LOGIN_FAILED });
    notice(error);
  }

  dispatch({ type: SET_LOGIN_LOADER, payload: false });
}
Example #5
Source File: withdraw.ts    From client with MIT License 6 votes vote down vote up
depositResources: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = (resources: Resource[]) => async dispatch => {
  dispatch({ type: SET_EXTRA_LOADER, payload: true });

  try {
    const { data } = await axios.patch(
      process.env.REACT_APP_API_URI + '/user/extra/resources/withdraw',
      { withdraws: resources }
    );

    const updated: any = {
      ...data.resources,
      list: data.resources.resources
    };
    delete updated.resources;

    dispatch({ type: WAREHOUSE_UPDATE, payload: data.items });
    dispatch({ type: RESOURCES_UPDATE, payload: updated });
    notice(data);
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_EXTRA_LOADER, payload: false });
}
Example #6
Source File: unlockWarehouse.ts    From client with MIT License 6 votes vote down vote up
unlockWarehouse: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = password => async dispatch => {
  try {
    dispatch({ type: WAREHOUSE_UNLOCK });
  } catch (error) {
    notice(error);
  }
}
Example #7
Source File: moveItem.ts    From client with MIT License 6 votes vote down vote up
moveItem: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = ({ itemSlot, newSlot, from, to }) => async dispatch => {
  dispatch({ type: SET_EXTRA_LOADER, payload: true });

  try {
    if (from !== to || (from === to && from !== 'storage')) {
      const { data } = await axios.patch(
        process.env.REACT_APP_API_URI + '/user/extra/storage/moveitem',
        {
          itemSlot,
          newSlot,
          from,
          to
        }
      );

      dispatch({ type: WAREHOUSE_UPDATE, payload: data.warehouse });
      dispatch({ type: STORAGE_UPDATE, payload: data.storage });
    }
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_EXTRA_LOADER, payload: false });
}
Example #8
Source File: getMarketItems.ts    From client with MIT License 6 votes vote down vote up
getMarketItems: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = (page = 1, perPage = 20) => async dispatch => {
  dispatch({ type: SET_EXTRA_LOADER, payload: true });

  try {
    const { data } = await axios.get(
      process.env.REACT_APP_API_URI +
        `/others/market?page=${page}&perPage=${perPage}`
    );

    dispatch({ type: SET_MARKET_ITEMS, payload: data });
    notice(data);
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_EXTRA_LOADER, payload: false });
}
Example #9
Source File: deposit.ts    From client with MIT License 6 votes vote down vote up
depositResources: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = (resources?: Resource[]) => async dispatch => {
  dispatch({ type: SET_EXTRA_LOADER, payload: true });

  try {
    const { data } = await axios.patch(
      process.env.REACT_APP_API_URI + '/user/extra/resources/deposit',
      { deposits: resources }
    );

    const updated: any = {
      ...data.resources,
      list: data.resources.resources
    };
    delete updated.resources;

    dispatch({ type: WAREHOUSE_UPDATE, payload: data.items });
    dispatch({ type: RESOURCES_UPDATE, payload: updated });
    notice(data);
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_EXTRA_LOADER, payload: false });
}
Example #10
Source File: buyItem.ts    From client with MIT License 6 votes vote down vote up
buyItem: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = (itemId, page, total) => async dispatch => {
  dispatch({ type: SET_MODAL_LOADER, payload: true });

  try {
    const { data } = await axios.patch(
      process.env.REACT_APP_API_URI + '/user/extra/market',
      { itemId }
    );

    dispatch({ type: RESOURCES_UPDATE, payload: data.resources });
    dispatch(getMarketItems(page, total));
    dispatch(getLatest(page, total));
    notice(data);
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_MODAL_LOADER, payload: false });
}
Example #11
Source File: saveStats.ts    From client with MIT License 6 votes vote down vote up
saveStats: ActionCreator<ThunkAction<
  void,
  AppState,
  any,
  Action
>> = form => async dispatch => {
  dispatch({ type: SET_CHARACTER_LOADER, payload: true });

  try {
    const { data } = await axios.patch(
      process.env.REACT_APP_API_URI + '/user/character/stats',
      form
    );

    dispatch(getChars());

    notice(data);
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_CHARACTER_LOADER, payload: false });
}
Example #12
Source File: reset.ts    From client with MIT License 6 votes vote down vote up
reset: ActionCreator<ThunkAction<void, AppState, any, Action>> = (
  name: string
) => async dispatch => {
  dispatch({ type: SET_CHARACTER_LOADER, payload: true });

  try {
    const { data } = await axios.patch(
      process.env.REACT_APP_API_URI + '/user/character/reset',
      { name }
    );

    notice(data);
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_CHARACTER_LOADER, payload: false });
}
Example #13
Source File: getChars.ts    From client with MIT License 6 votes vote down vote up
getChars: ActionCreator<ThunkAction<
  void,
  AppState,
  any,
  Action
>> = () => async dispatch => {
  dispatch({ type: SET_CHARACTER_LOADER, payload: true });

  try {
    const { data } = await axios.get(
      process.env.REACT_APP_API_URI + '/user/character'
    );

    dispatch({ type: SET_CHARACTERS, payload: data });
  } catch (error) {}

  dispatch({ type: SET_CHARACTER_LOADER, payload: false });
}
Example #14
Source File: changeName.ts    From client with MIT License 6 votes vote down vote up
changeName: ActionCreator<ThunkAction<void, AppState, any, Action>> = (
  name: string,
  newName: string
) => async dispatch => {
  dispatch({ type: SET_CHARACTER_LOADER, payload: true });

  try {
    const { data } = await axios.patch(
      process.env.REACT_APP_API_URI + '/user/character/name',
      { name, newName }
    );

    dispatch(getChars());

    notice(data);
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_CHARACTER_LOADER, payload: false });
}
Example #15
Source File: changeClass.ts    From client with MIT License 6 votes vote down vote up
changeClass: ActionCreator<ThunkAction<void, AppState, any, Action>> = (
  name: string,
  newClass: number
) => async dispatch => {
  dispatch({ type: SET_CHARACTER_LOADER, payload: true });

  try {
    const { data } = await axios.patch(
      process.env.REACT_APP_API_URI + '/user/character/class',
      { name, newClass }
    );

    dispatch(getChars());

    notice(data);
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_CHARACTER_LOADER, payload: false });
}
Example #16
Source File: updateConfig.ts    From client with MIT License 6 votes vote down vote up
updateConfig: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = (configName, updated) => async dispatch => {
  dispatch({ type: SET_ADMIN_LOADER, payload: true });

  try {
    const { data } = await axios.patch(
      process.env.REACT_APP_API_URI + '/admin/config',
      {
        configName,
        updated
      }
    );

    await dispatch(getConfig());

    notice(data);
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_ADMIN_LOADER, payload: false });
}
Example #17
Source File: getConfig.ts    From client with MIT License 6 votes vote down vote up
getConfig: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = () => async dispatch => {
  try {
    const { data } = await axios.get(process.env.REACT_APP_API_URI + '/config');

    dispatch({
      type: SET_CONFIG,
      payload: data
    });
  } catch (error) {
    dispatch({
      type: SET_CONFIG_FAILED
    });
  }
}
Example #18
Source File: getOnline.ts    From client with MIT License 6 votes vote down vote up
getLogs: ActionCreator<ThunkAction<
  void,
  AppState,
  any,
  Action
>> = () => async dispatch => {
  dispatch({ type: SET_ACCOUNT_LOADER, payload: true });

  try {
    const { data } = await axios.get(
      process.env.REACT_APP_API_URI + '/user/account/online'
    );

    dispatch({ type: SET_ONLINE, payload: data });
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_ACCOUNT_LOADER, payload: false });
}
Example #19
Source File: getLogs.ts    From client with MIT License 6 votes vote down vote up
getLogs: ActionCreator<ThunkAction<void, AppState, any, Action>> = (
  page,
  perPage,
  category
) => async dispatch => {
  dispatch({ type: SET_ACCOUNT_LOADER, payload: true });

  try {
    const { data } = await axios.get(
      process.env.REACT_APP_API_URI +
        `/user/account/logs?page=${page}&perPage=${perPage}` +
        (category ? `&category=${category}` : '')
    );

    dispatch({ type: SET_LOGS, payload: data });
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_ACCOUNT_LOADER, payload: false });
}
Example #20
Source File: exchangeOnline.ts    From client with MIT License 6 votes vote down vote up
exchangeOnline: ActionCreator<ThunkAction<
  void,
  AppState,
  any,
  Action
>> = () => async dispatch => {
  dispatch({ type: SET_ACCOUNT_LOADER, payload: true });

  try {
    const { data } = await axios.patch(
      process.env.REACT_APP_API_URI + '/user/account/online'
    );

    dispatch({ type: SET_ONLINE, payload: data.status });
    dispatch({ type: SET_CREDITS, payload: data.credits });

    notice(data);
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_ACCOUNT_LOADER, payload: false });
}
Example #21
Source File: changePassword.ts    From client with MIT License 6 votes vote down vote up
changePassword: ActionCreator<ThunkAction<
  void,
  AppState,
  any,
  Action
>> = (form: Form) => async dispatch => {
  dispatch({ type: SET_ACCOUNT_LOADER, payload: true });

  try {
    const { data } = await axios.patch(
      process.env.REACT_APP_API_URI + '/user/account/password',
      form
    );

    notice(data);
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_ACCOUNT_LOADER, payload: false });
}
Example #22
Source File: buyVIP.ts    From client with MIT License 6 votes vote down vote up
buyVIP: ActionCreator<ThunkAction<void, AppState, any, Action>> = (
  vipDays: number
) => async dispatch => {
  dispatch({ type: SET_ACCOUNT_LOADER, payload: true });

  try {
    const { data } = await axios.patch(
      process.env.REACT_APP_API_URI + '/user/account/vip',
      {
        vipDays
      }
    );

    dispatch({ type: SET_ACCOUNT_INFO, payload: data.info });

    dispatch({ type: SET_CREDITS, payload: data.credits });

    notice(data);
  } catch (error) {
    notice(error);
  }

  dispatch({ type: SET_ACCOUNT_LOADER, payload: false });
}
Example #23
Source File: getTop5Guilds.ts    From client with MIT License 6 votes vote down vote up
getCharacters: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = () => async dispatch => {
  try {
    const { data } = await axios.get(
      process.env.REACT_APP_API_URI + '/guilds?limit=5'
    );

    dispatch({
      type: data ? GET_RANK_5GUILDS : GET_RANK_5GUILDS_FAILED,
      payload: data
    });
  } catch (error) {
    dispatch({
      type: GET_RANK_5GUILDS_FAILED
    });
  }
}
Example #24
Source File: getHof.ts    From client with MIT License 6 votes vote down vote up
getHof: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = () => async dispatch => {
  try {
    const { data } = await axios.get(
      process.env.REACT_APP_API_URI + '/characters/hof'
    );

    dispatch({
      type: !data.error ? GET_HOF : GET_HOF_FAILED,
      payload: data
    });
  } catch (error) {
    dispatch({
      type: GET_HOF_FAILED
    });
  }
}
Example #25
Source File: getGuild.ts    From client with MIT License 6 votes vote down vote up
getGuild: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = (name: string) => async dispatch => {
  dispatch({ type: SET_GUILD_LOADING, payload: true });

  try {
    const { data } = await axios.get(
      process.env.REACT_APP_API_URI + `/guilds/${name}`
    );

    dispatch({ type: GET_GUILD, payload: data });
  } catch (error) {
    dispatch({ type: GET_GUILD, payload: false });
  }

  dispatch({ type: SET_GUILD_LOADING, payload: false });
}
Example #26
Source File: getCharacters.ts    From client with MIT License 6 votes vote down vote up
getCharacters: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = (page, perPage) => async dispatch => {
  dispatch({
    type: RANKINGS_LOADING,
    payload: true
  });

  try {
    const { data } = await axios.get(
      process.env.REACT_APP_API_URI +
        `/characters?page=${page}&perPage=${perPage}`
    );

    dispatch({
      type: data ? GET_RANK_CHARACTERS : GET_RANK_CHARACTERS_FAILED,
      payload: data
    });
  } catch (error) {
    dispatch({
      type: GET_RANK_CHARACTERS_FAILED
    });
  }
  dispatch({
    type: RANKINGS_LOADING,
    payload: false
  });
}
Example #27
Source File: getCharacter.ts    From client with MIT License 6 votes vote down vote up
getCharacters: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = (name: string) => async dispatch => {
  dispatch({ type: SET_CHARACTER_LOADING, payload: true });

  try {
    const { data } = await axios.get(
      process.env.REACT_APP_API_URI + `/characters/${name}`
    );

    dispatch({ type: GET_CHARACTER, payload: data });
  } catch (error) {
    dispatch({ type: GET_CHARACTER, payload: false });
  }

  dispatch({ type: SET_CHARACTER_LOADING, payload: false });
}
Example #28
Source File: postNews.ts    From client with MIT License 6 votes vote down vote up
postNews: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = news => async () => {
  try {
    const { data } = await axios.post(
      process.env.REACT_APP_API_URI + `/admin/news`,
      news
    );

    notice(data);
  } catch (error) {
    notice(error);
  }
}
Example #29
Source File: latest.ts    From client with MIT License 6 votes vote down vote up
getCharacters: ActionCreator<ThunkAction<
  Promise<any>,
  AppState,
  any,
  Action
>> = (page = 1, perPage) => async dispatch => {
  try {
    const { data } = await axios.get(
      process.env.REACT_APP_API_URI +
        `/others/market?page=${page}&perPage=${perPage || 3}`
    );

    dispatch({
      type: MARKET_LATEST,
      payload: data
    });
  } catch (error) {
    dispatch({
      type: MARKET_LATEST_FAILED
    });
  }
}