Skip to content

Commit

Permalink
small change in networkReducer for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyubinhan committed Dec 7, 2018
1 parent edc4aef commit c26e921
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/actions/networkActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export const successPagenated = (reducer, data) => (
}
);

export const error = (reducer, errorMessage) => (
export const error = (reducer, errorResponse) => (
{
name: reducer,
type: actionTypes.ERROR,
errorMessage,
errorResponse,
}
);
4 changes: 2 additions & 2 deletions src/components/auth/LoginPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button, Icon } from 'semantic-ui-react';
import { IMAGE_SRC } from '../../constants/variables';
import { storeAuthData } from '../../actions';
import { fetchUser, signOut } from '../../actionCreators';
import { getIsFetchingUser, getUserErrorMessage } from '../../reducers/rootReducer';
import { getIsFetchingUser, getUserErrorOccured } from '../../reducers/rootReducer';
import { APP_NAME, LOGIN_TITLE } from '../../constants/strings';
import { detectIE } from '../../utils';
import SignInBox from './SignInBox';
Expand Down Expand Up @@ -179,7 +179,7 @@ export class LoginPage extends Component {
const mapStateToProps = state => (
{
isFetchingUser: getIsFetchingUser(state),
errorFetchingUser: getUserErrorMessage(state),
errorFetchingUser: getUserErrorOccured(state),
}
);

Expand Down
6 changes: 1 addition & 5 deletions src/components/auth/SignInBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ import { signOutFromSSO } from '../../utils';
class SignInBox extends Component {
static propTypes = {
isFetchingUser: PropTypes.bool.isRequired,
errorFetchingUser: PropTypes.shape({}),
errorFetchingUser: PropTypes.bool.isRequired,
signOut: PropTypes.func.isRequired,
};

static defaultProps = {
errorFetchingUser: null,
}

openNewTab = link => window.open(link, '_black')
onSigninBtnClick = () => this.openNewTab(SSO_LOGIN_ENDPOINT)
onIdirSigninBtnClick = () => this.openNewTab(SSO_IDIR_LOGIN_ENDPOINT)
Expand Down
7 changes: 3 additions & 4 deletions src/components/rangeUsePlan/PDFView.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ import { connect } from 'react-redux';
import { downloadPDFBlob } from '../../utils';
import { fetchRupPDF } from '../../actionCreators';
import { Loading, ErrorPage } from '../common';
import { getPlanPDF, getIsFetchingPlanPDF, getPlanPDFError } from '../../reducers/rootReducer';
import { getPlanPDF, getIsFetchingPlanPDF, getPlanPDFErrorOccured } from '../../reducers/rootReducer';

class PDFView extends Component {
static propTypes = {
match: PropTypes.shape({ params: PropTypes.object }).isRequired,
fetchRupPDF: PropTypes.func.isRequired,
isFetchingPDF: PropTypes.bool.isRequired,
errorFetchingPDF: PropTypes.shape({}),
errorFetchingPDF: PropTypes.bool.isRequired,
planPDFBlob: PropTypes.shape({}),
};

static defaultProps = {
planPDFBlob: null,
errorFetchingPDF: null,
}

state = {
Expand Down Expand Up @@ -141,7 +140,7 @@ const mapStateToProps = state => (
{
planPDFBlob: getPlanPDF(state),
isFetchingPDF: getIsFetchingPlanPDF(state),
errorFetchingPDF: getPlanPDFError(state),
errorFetchingPDF: getPlanPDFErrorOccured(state),
}
);

Expand Down
8 changes: 2 additions & 6 deletions src/components/rangeUsePlan/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ class Base extends Component {
location: PropTypes.shape({ pathname: PropTypes.string }).isRequired,
fetchRUP: PropTypes.func.isRequired,
isFetchingPlan: PropTypes.bool.isRequired,
errorFetchingPlan: PropTypes.shape({}),
errorFetchingPlan: PropTypes.bool.isRequired,
plansMap: PropTypes.shape({}).isRequired,
};

static defaultProps = {
errorFetchingPlan: null,
};

componentWillMount() {
document.title = DETAIL_RUP_TITLE;
}
Expand Down Expand Up @@ -124,7 +120,7 @@ const mapStateToProps = state => (
additionalRequirementsMap: selectors.getAdditionalRequirementsMap(state),
managementConsiderationsMap: selectors.getManagementConsiderationsMap(state),
isFetchingPlan: selectors.getIsFetchingPlan(state),
errorFetchingPlan: selectors.getPlanError(state),
errorFetchingPlan: selectors.getPlanErrorOccured(state),
references: selectors.getReferences(state),
isUpdatingStatus: selectors.getIsUpdatingPlanStatus(state),
isCreatingAmendment: selectors.getIsCreatingAmendment(state),
Expand Down
10 changes: 2 additions & 8 deletions src/components/selectRangeUsePlan/AgreementTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class AgreementTable extends Component {
currentPage: PropTypes.number,
totalPages: PropTypes.number,
}).isRequired,
errorGettingAgreements: PropTypes.shape({}),
errorGettingAgreements: PropTypes.bool.isRequired,
user: PropTypes.shape({}).isRequired,
handlePaginationChange: PropTypes.func.isRequired,
activeIndex: PropTypes.number.isRequired,
Expand All @@ -25,10 +25,6 @@ export class AgreementTable extends Component {
isFetchingAgreementWithAllPlan: PropTypes.bool.isRequired,
}

static defaultProps = {
errorGettingAgreements: null,
}

handlePaginationChange = (e, { activePage: currentPage }) => {
this.props.handlePaginationChange(currentPage);
}
Expand All @@ -42,8 +38,6 @@ export class AgreementTable extends Component {
<Button
onClick={() => window.location.reload(true)}
style={{ marginLeft: '10px' }}
basic
color="grey"
>
Retry
</Button>
Expand Down Expand Up @@ -142,7 +136,7 @@ const mapStateToProps = state => (
agreements: selectors.getAgreements(state),
isFetchingAgreements: selectors.getIsFetchingAgreements(state),
agreementPagination: selectors.getAgreementsPagination(state),
errorGettingAgreements: selectors.getAgreementsErrorMessage(state),
errorGettingAgreements: selectors.getAgreementsErrorOccured(state),
user: selectors.getUser(state),
references: selectors.getReferences(state),
agreementsMapWithAllPlan: selectors.getAgreementsMapWithAllPlan(state),
Expand Down
10 changes: 3 additions & 7 deletions src/components/selectRangeUsePlan/PlanTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button, Segment } from 'semantic-ui-react';
import { isStatusAmongApprovedStatuses } from '../../utils';
import { Loading } from '../common';
import { EFFECTIVE_DATE, SUBMITTED, TYPE, STATUS, VIEW, NO_RESULTS_FOUND, ERROR_OCCUR } from '../../constants/strings';
import { getIsFetchingAgreements, getUser, getReferences, getIsFetchingAgreementWithAllPlan, getAgreementsMapWithAllPlan, getAgreementsMapWithAllPlanErrorMessage } from '../../reducers/rootReducer';
import { getIsFetchingAgreements, getUser, getReferences, getIsFetchingAgreementWithAllPlan, getAgreementsMapWithAllPlan, getAgreementsMapWithAllPlanErrorOccured } from '../../reducers/rootReducer';
import PlanTableRow from './PlanTableRow';

class PlanTable extends Component {
Expand All @@ -15,14 +15,10 @@ class PlanTable extends Component {
references: PropTypes.shape({}).isRequired,
isFetchingAgreementWithAllPlan: PropTypes.bool.isRequired,
isFetchingAgreements: PropTypes.bool.isRequired,
errorGettingAgreementWithAllPlan: PropTypes.shape({}),
errorGettingAgreementWithAllPlan: PropTypes.bool.isRequired,
agreement: PropTypes.shape({}).isRequired,
}

static defaultProps = {
errorGettingAgreementWithAllPlan: null,
}

renderPlanTableItems = (plans = []) => {
const {
errorGettingAgreementWithAllPlan,
Expand Down Expand Up @@ -104,7 +100,7 @@ const mapStateToProps = state => (
references: getReferences(state),
isFetchingAgreementWithAllPlan: getIsFetchingAgreementWithAllPlan(state),
agreementsMapWithAllPlan: getAgreementsMapWithAllPlan(state),
errorGettingAgreementWithAllPlan: getAgreementsMapWithAllPlanErrorMessage(state),
errorGettingAgreementWithAllPlan: getAgreementsMapWithAllPlanErrorOccured(state),
}
);

Expand Down
4 changes: 2 additions & 2 deletions src/constants/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const GET_TOKEN_FROM_SSO = `/auth/realms/${SSO_REALM_NAME}/protocol/openi
export const REFRESH_TOKEN_FROM_SSO = `/auth/realms/${SSO_REALM_NAME}/protocol/openid-connect/token`;

// const DEV_API_BASE_URL = 'https://web-range-myra-prod.pathfinder.gov.bc.ca/api';
// const DEV_API_BASE_URL = 'https://web-range-myra-dev.pathfinder.gov.bc.ca/api';
const DEV_API_BASE_URL = 'https://web-range-myra-dev.pathfinder.gov.bc.ca/api';
// const DEV_API_BASE_URL = 'https://web-range-myra-test.pathfinder.gov.bc.ca/api';
const DEV_API_BASE_URL = 'http://localhost:8000/api';
// const DEV_API_BASE_URL = 'http://localhost:8000/api';
// const DEV_API_BASE_URL = 'http://10.10.10.190:8000/api';


Expand Down
20 changes: 9 additions & 11 deletions src/reducers/networkReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { REQUEST, SUCCESS, ERROR, SUCCESS_PAGINATED } from '../constants/actionT

const initialState = {
isFetching: false,
isSuccessful: false,
error: null,
errorOccured: false,
errorResponse: null,
success: null,
pagination: {
perPage: 10,
Expand All @@ -19,32 +19,29 @@ const networkReducer = (state = initialState, action) => {
return {
...state,
isFetching: true,
isSuccessful: false,
error: null,
errorOccured: false,
success: null,
};
case SUCCESS:
return {
...state,
isFetching: false,
isSuccessful: true,
error: null,
errorOccured: false,
success: action.data,
};
case ERROR:
return {
...state,
isFetching: false,
isSuccessful: false,
error: action.errorMessage,
errorOccured: true,
errorResponse: action.errorResponse,
success: null,
};
case SUCCESS_PAGINATED:
return {
...state,
isFetching: false,
isSuccessful: true,
error: null,
errorOccured: false,
success: action.data,
pagination: {
perPage: action.perPage,
Expand All @@ -63,5 +60,6 @@ export default networkReducer;
// private selectors
export const getIsFetching = state => state.isFetching;
export const getPagination = state => state.pagination;
export const getErrorMessage = state => state.error;
export const getErrorOccured = state => state.errorOccured;
export const getErrorResponse = state => state.errorResponse;
export const getData = state => state.success;
10 changes: 5 additions & 5 deletions src/reducers/rootReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ export const getAgreementIds = state => fromAgreement.getAgreementIds(state[redu
export const getAgreementsMap = state => fromAgreement.getAgreementsMap(state[reducerTypes.AGREEMENTS]);
export const getAgreementsPagination = state => fromNetwork.getPagination(state[reducerTypes.SEARCH_AGREEMENTS]);
export const getIsFetchingAgreements = state => fromNetwork.getIsFetching(state[reducerTypes.SEARCH_AGREEMENTS]);
export const getAgreementsErrorMessage = state => fromNetwork.getErrorMessage(state[reducerTypes.SEARCH_AGREEMENTS]);
export const getAgreementsErrorOccured = state => fromNetwork.getErrorOccured(state[reducerTypes.SEARCH_AGREEMENTS]);
export const getIsUpdatingAgreementZone = state => fromNetwork.getIsFetching(state[reducerTypes.UPDATE_AGREEMENT_ZONE]);

export const getAgreementsMapWithAllPlan = state => fromAgreementWithAllPlans.getAgreementsMap(state[reducerTypes.AGREEMENTS_WITH_ALL_PLANS]);
export const getIsFetchingAgreementWithAllPlan = state => fromNetwork.getIsFetching(state[reducerTypes.GET_AGREEMENT]);
export const getAgreementsMapWithAllPlanErrorMessage = state => fromNetwork.getErrorMessage(state[reducerTypes.GET_AGREEMENT]);
export const getAgreementsMapWithAllPlanErrorOccured = state => fromNetwork.getErrorOccured(state[reducerTypes.GET_AGREEMENT]);
export const getIsCreatingAmendment = state => fromNetwork.getIsFetching(state[reducerTypes.CREATE_AMENDMENT]);

export const getAuthData = state => fromAuth.getAuthData(state[reducerTypes.AUTH]);
export const getUser = state => fromAuth.getUser(state[reducerTypes.AUTH]);
export const getToken = state => fromAuth.getToken(state[reducerTypes.AUTH]);
export const getIsFetchingUser = state => fromNetwork.getIsFetching(state[reducerTypes.GET_USER]);
export const getUserErrorMessage = state => fromNetwork.getErrorMessage(state[reducerTypes.GET_USER]);
export const getUserErrorOccured = state => fromNetwork.getErrorOccured(state[reducerTypes.GET_USER]);

export const getZones = state => fromCommonStore.getZones(state[reducerTypes.COMMON]);
export const getZonesMap = state => fromCommonStore.getZonesMap(state[reducerTypes.COMMON]);
Expand All @@ -109,10 +109,10 @@ export const getIsUpdatingClientIdOfUser = state => fromNetwork.getIsFetching(st
export const getPlansMap = state => fromPlan.getPlansMap(state[reducerTypes.PLAN]);
export const getPlanIds = state => fromPlan.getPlanIds(state[reducerTypes.PLAN]);
export const getIsFetchingPlan = state => fromNetwork.getIsFetching(state[reducerTypes.GET_PLAN]);
export const getPlanError = state => fromNetwork.getErrorMessage(state[reducerTypes.GET_PLAN]);
export const getPlanErrorOccured = state => fromNetwork.getErrorOccured(state[reducerTypes.GET_PLAN]);

export const getIsFetchingPlanPDF = state => fromNetwork.getIsFetching(state[reducerTypes.GET_PLAN_PDF]);
export const getPlanPDFError = state => fromNetwork.getErrorMessage(state[reducerTypes.GET_PLAN_PDF]);
export const getPlanPDFErrorOccured = state => fromNetwork.getErrorOccured(state[reducerTypes.GET_PLAN_PDF]);
export const getPlanPDF = state => fromNetwork.getData(state[reducerTypes.GET_PLAN_PDF]);

export const getPasturesMap = state => fromPlan.getPasturesMap(state[reducerTypes.PLAN]);
Expand Down

0 comments on commit c26e921

Please sign in to comment.