connected-react-router#LOCATION_CHANGE JavaScript Examples

The following examples show how to use connected-react-router#LOCATION_CHANGE. 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: reducer.js    From bank-client with MIT License 6 votes vote down vote up
forgetPasswordPageReducer = produce((draft, action) => {
  if (window.location.pathname === routes.forgetPassword.path) {
    switch (action.type) {
      case CHANGE_INPUT:
        draft[action.name] = action.value;
        break;
      case FORGOT_PASSWORD_SUCCESS:
        draft.isSuccess = true;
        break;
    }
  }
  switch (action.type) {
    case LOCATION_CHANGE:
      return initialState;
  }
}, initialState)
Example #2
Source File: reducer.js    From bank-client with MIT License 6 votes vote down vote up
historyPageReducer = produce((draft, action) => {
  switch (action.type) {
    case GET_TRANSACTION_HISTORY_SUCCESS:
      draft.transactions = action.transactions;
      break;
    case LOGOUT_SUCCESS:
    case LOGOUT_ERROR:
    case LOCATION_CHANGE:
      return initialState;
  }
}, initialState)
Example #3
Source File: reducer.js    From bank-client with MIT License 6 votes vote down vote up
loginPageReducer = produce((draft, action) => {
  if (window.location.pathname === routes.login.path) {
    switch (action.type) {
      case CHANGE_INPUT_NUMBER:
        draft[action.name] = parseInt(action.value, 10) || '';
        break;
      case CHANGE_INPUT:
        draft[action.name] = action.value;
        break;
      case NEXT_STEP:
        draft.currentStep += 1;
        break;
      case PREVIOUS_STEP:
        draft.currentStep -= 1;
        break;
    }
  }

  switch (action.type) {
    case LOCATION_CHANGE:
      return initialState;
  }
}, initialState)
Example #4
Source File: reducer.js    From bank-client with MIT License 6 votes vote down vote up
registerPageReducer = produce((draft, action) => {
  if (window.location.pathname === routes.register.path) {
    switch (action.type) {
      case CHANGE_INPUT:
        draft[action.name] = action.value.trim();
        break;
      case SELECT_CURRENCY:
        draft.currency = action.currency;
        break;
      case NEXT_STEP:
        draft.currentStep += 1;
        break;
      case PREVIOUS_STEP:
        draft.currentStep -= 1;
        break;
    }
  }

  switch (action.type) {
    case REGISTER_SUCCESS:
      draft.pinCode = action.pinCode;
      break;
    case LOCATION_CHANGE:
      return initialState;
  }
}, initialState)
Example #5
Source File: reducer.js    From bank-client with MIT License 6 votes vote down vote up
resetPasswordPageReducer = produce((draft, action) => {
  if (window.location.pathname.includes(routes.resetPassword.path)) {
    switch (action.type) {
      case CHANGE_INPUT:
        draft[action.name] = action.value;
        break;
      case RESET_PASSWORD_SUCCESS:
        draft.isSuccess = true;
        break;
    }
  }

  switch (action.type) {
    case LOCATION_CHANGE:
      return initialState;
  }
}, initialState)
Example #6
Source File: reducer.js    From bank-client with MIT License 6 votes vote down vote up
settingsPageReducer = produce((draft, action) => {
  if (window.location.pathname === routes.settings.path) {
    switch (action.type) {
      case SELECT_CURRENCY:
        if (draft.user?.userConfig?.currency?.uuid !== action?.currency) {
          draft.newData.currency = action.currency;
          draft.isOpenedModal = true;
        }
        break;
      case CHANGE_INPUT:
        if (draft.user[action.name] === action.value || !action.value.length) {
          delete draft.newData[action.name];
        } else {
          draft.newData[action.name] = action.value;
        }
        break;
      case TOGGLE_MODAL:
        draft.isOpenedModal = !draft.isOpenedModal;
        delete draft.newData.currency;
        break;
    }
  }

  switch (action.type) {
    case GET_USER_DATA_SUCCESS:
    case SET_USER_DATA_SUCCESS:
      draft.user = action.userData;
      draft.newData = initialState.newData;
      draft.isOpenedModal = false;
      break;
    case SET_USER_DATA_INCORRECT:
      draft.isOpenedModal = false;
      break;
    case LOCATION_CHANGE:
    case LOGOUT_SUCCESS:
    case LOGOUT_ERROR:
      return initialState;
  }
}, initialState)
Example #7
Source File: reducer.js    From bank-client with MIT License 5 votes vote down vote up
appReducer = produce((draft, action) => {
  if (/(.*)_ERROR/.test(action.type)) {
    return initialState;
  }

  switch (action.type) {
    case LOGIN_SUCCESS:
    case LOGIN_EXPRESS_SUCCESS:
      draft.isLogged = true;
      draft.token = action.token;
      draft.user = action.user;
      break;
    case COLLAPSED_SIDEBAR:
      draft.isCollapsedSidebar = !draft.isCollapsedSidebar;
      break;
    case COLLAPSED_DRAWER:
      draft.isCollapsedDrawer = !draft.isCollapsedDrawer;
      break;
    case CHANGE_LAYOUT:
      draft.layout = JSON.parse(JSON.stringify(action.layout));
      break;
    case SET_USER_DATA_SUCCESS:
      draft.user = action.userData;
      break;
    case TOGGLE_CONFIRM_MODAL:
      draft.isOpenedModal = !draft.isOpenedModal;
      break;
    case GET_CURRENCIES_SUCCESS:
      draft.currencies = action.data;
      break;
    case GET_MESSAGES_SUCCESS:
      draft.messages = action.data;
      break;
    case GET_NOTIFICATIONS_SUCCESS:
      draft.notifications = action.data;

      if (draft.user.userConfig.notificationCount) {
        draft.user.userConfig.notificationCount = 0;
      }
      break;
    case OPEN_MESSAGE_MODAL:
      draft.isOpenedMessage = true;
      draft.openedMessage = action.uuid;
      break;
    case READ_MESSAGE_SUCCESS:
      draft.messages.data.find(
        ({ uuid }) => uuid === draft.openedMessage,
      ).readed = true;

      if (draft.user.userConfig.messageCount) {
        draft.user.userConfig.messageCount -= 1;
      }
      break;
    case READ_ALL_MESSAGES_SUCCESS:
      draft.messages.data = draft.messages.data.map((message) => ({
        ...message,
        readed: true,
      }));

      if (draft.user.userConfig.messageCount) {
        draft.user.userConfig.messageCount = 0;
      }
      break;
    case CLOSE_MESSAGE_MODAL:
      draft.isOpenedMessage = initialState.isOpenedMessage;
      draft.openedMessage = initialState.openedMessage;
      break;
    case LOCATION_CHANGE:
      draft.isCollapsedDrawer = initialState.isCollapsedDrawer;
      draft.isOpenedMessage = initialState.isOpenedMessage;
      draft.openedMessage = initialState.openedMessage;
      break;
    case LOGOUT_ERROR:
    case LOGOUT_SUCCESS:
      return initialState;
  }
}, initialState)
Example #8
Source File: reducer.js    From bank-client with MIT License 5 votes vote down vote up
dashboardPageReducer = produce((draft, action) => {
  if (window.location.pathname === routes.dashboard.path) {
    switch (action.type) {
      case SELECT_CURRENCY:
        draft.currency = action.currency;
        break;
      case TOGGLE_MODAL:
        draft.isOpenedModal = !draft.isOpenedModal;
        break;
    }
  }

  switch (action.type) {
    case GET_BILLS_SUCCESS:
      draft.bills = action.bills.map(formatBill);
      break;
    case CREATE_NEW_BILL_SUCCESS:
      draft.bills = [...draft.bills, formatBill(action.bill)];
      draft.currency = initialState.currency;
      break;
    case GET_AVAILABLE_FUNDS_SUCCESS:
      draft.amountMoney = action.amountMoney;
      draft.currencyName = action.currencyName;
      draft.accountBalanceHistory =
        action.accountBalanceHistory.length === 1
          ? [...action.accountBalanceHistory, 0]
          : action.accountBalanceHistory;
      break;
    case GET_ACCOUNT_BALANCE_SUCCESS:
      draft.currencyName = action.currencyName;
      draft.savings = action.savings.toFixed(1).replace('.', ',');
      draft.savingsData = action.savingsData;
      draft.savingsColors = action.savingsColors;
      break;
    case GET_RECENT_TRANSACTIONS_SUCCESS:
      draft.recentTransactions = action.recentTransactions;
      break;

    case LOCATION_CHANGE:
    case LOGOUT_SUCCESS:
    case LOGOUT_ERROR:
      return initialState;
  }
}, initialState)
Example #9
Source File: reducer.js    From bank-client with MIT License 5 votes vote down vote up
paymentPageReducer = produce((draft, action) => {
  if (window.location.pathname === routes.payment.path) {
    switch (action.type) {
      case CHANGE_INPUT:
        if (action.name === 'recipientAccountBillNumber') {
          draft.recipientBill =
            draft.recipients?.find(
              (bill) =>
                bill.accountBillNumber.replace(/ /g, '') ===
                action.value.trim(),
            ) || '';
        } else {
          draft[action.name] = action.value.trim();
        }
        break;
      case CHANGE_INPUT_NUMBER:
        draft[action.name] = action.value || initialState.amountMoney;
        break;
      case CHECK_RECIPIENT_CORRECT:
      case NEXT_STEP:
        draft.currentStep += 1;
        break;
      case PREVIOUS_STEP:
        draft.currentStep -= 1;
        draft.hasCreatedTransaction = false;
        draft.authorizationKey = initialState.authorizationKey;
        break;
    }
  }

  switch (action.type) {
    case GET_AUTHORIZATION_KEY_SUCCESS:
      draft.authorizationKey = action.authorizationKey;
      break;
    case GET_BILLS_SUCCESS:
      draft.bills = action.bills.map(formatBill);
      break;
    case SEARCH_RECIPIENT_SUCCESS:
      draft.recipients = action.recipients.map(formatBill);
      break;
    case SELECT_SENDER_BILL:
      draft.senderBill =
        draft.bills?.find((bill) => bill.uuid === action.uuid) || '';
      break;
    case CREATE_TRANSACTION_SUCCESS:
      draft.hasCreatedTransaction = true;
      draft.transaction = action.uuid;
      break;
    case CONFIRM_TRANSACTION_SUCCESS:
      draft.hasConfirmedTransaction = true;
      break;
    case LOGOUT_SUCCESS:
    case LOGOUT_ERROR:
    case LOCATION_CHANGE:
      return initialState;
  }
}, initialState)