Skip to content

Commit

Permalink
Fix plot application page error states
Browse files Browse the repository at this point in the history
Previously the page just kept loading endlessly if the application
couldn't be loaded for any reason.
  • Loading branch information
EmiliaMakelaVincit committed Nov 20, 2023
1 parent dd973ee commit b7db2cf
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/plotApplications/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import type {
ReceiveSinglePlotApplicationAction,
ReceiveTargetInfoCheckMeetingMemoUploadedAction,
ReceiveTargetInfoChecksForPlotSearchAction,
SinglePlotApplicationNotAllowedAction,
SinglePlotApplicationNotFoundAction,
SetCurrentEditorTargetsAction,
ShowEditModeAction,
TargetInfoCheckMeetingMemoDeleteFailedAction,
Expand All @@ -62,6 +64,12 @@ export const fetchSinglePlotApplication = (id: number): FetchSinglePlotApplicati
export const receiveSinglePlotApplication = (plotApplication: PlotApplication): ReceiveSinglePlotApplicationAction =>
createAction('mvj/plotApplications/RECEIVE_SINGLE')(plotApplication);

export const singlePlotApplicationNotFound = (): SinglePlotApplicationNotFoundAction =>
createAction('mvj/plotApplications/SINGLE_NOT_FOUND')();

export const singlePlotApplicationNotAllowed = (): SinglePlotApplicationNotAllowedAction =>
createAction('mvj/plotApplications/SINGLE_NOT_ALLOWED')();

export const fetchPlotApplicationsByBBox = (params: Object): FetchPlotApplicationsByBBoxAction =>
createAction('mvj/plotApplications/FETCH_BY_BBOX')(params);

Expand Down
27 changes: 24 additions & 3 deletions src/plotApplications/components/PlotApplicationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
getIsFormValidFlags,
getIsPerformingFileOperation,
getIsSaving,
getIsSingleAllowed,
getApplicationRelatedPlotSearch,
getApplicationApplicantInfoCheckData,
getApplicationTargetInfoCheckData,
Expand All @@ -47,7 +48,8 @@ import {
receiveIsSaveClicked,
hideEditMode,
clearFormValidFlags,
receiveFormValidFlags, batchEditApplicationModels,
receiveFormValidFlags,
batchEditApplicationModels,
} from '$src/plotApplications/actions';
import type {
PlotApplication as PlotApplicationType,
Expand Down Expand Up @@ -118,6 +120,7 @@ type Props = {
isFormValid: (string) => boolean,
getValuesForForm: (string) => Object,
batchEditApplicationModels: Function,
isSingleAllowed: boolean,
}

type State = {
Expand Down Expand Up @@ -520,6 +523,7 @@ class PlotApplicationPage extends Component<Props, State> {
isSaveClicked,
isPerformingFileOperation,
isSaving,
isSingleAllowed,
} = this.props;

const areFormsValid = this.getAreFormsValid();
Expand All @@ -533,10 +537,26 @@ class PlotApplicationPage extends Component<Props, State> {
}

if (!isMethodAllowed(plotApplicationsMethods, Methods.GET)) {
return <PageContainer><AuthorizationError text={PermissionMissingTexts.PLOT_APPLICATIONS}/></PageContainer>;
return <PageContainer>
<AuthorizationError text={PermissionMissingTexts.PLOT_APPLICATIONS} />
</PageContainer>;
}

return(
if (!isFetching && !isSingleAllowed) {
return <PageContainer>
<AuthorizationError
text="Sinulla ei tällä hetkellä ole oikeutta nähdä tätä hakemusta. Mikäli hakemukseen liittyvä haku on päättynyt, valmistelija voi avata hakemuksen listanäkymän kautta." />
</PageContainer>;
}

if (!isFetching && !currentPlotApplication.id) {
return <PageContainer>
<AuthorizationError
text="Hakemusta ei löydy." />
</PageContainer>;
}

return (
<FullWidthContainer>
<PageNavigationWrapper>
<ControlButtonBar
Expand Down Expand Up @@ -630,6 +650,7 @@ export default (flowRight(
isSaveClicked: getIsSaveClicked(state),
isFormValidFlags: getIsFormValidFlags(state),
isPerformingFileOperation: getIsPerformingFileOperation(state),
isSingleAllowed: getIsSingleAllowed(state),
plotSearches: getPlotSearchList(state),
isSaving: getIsSaving(state),
currentPlotSearch: getApplicationRelatedPlotSearch(state),
Expand Down
13 changes: 12 additions & 1 deletion src/plotApplications/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@ import type {
const isFetchingReducer: Reducer<boolean> = handleActions({
['mvj/plotApplications/FETCH_ALL']: () => true,
['mvj/plotApplications/RECEIVE_ALL']: () => false,
['mvj/plotApplications/APPLICATIONS_NOT_FOUND']: () => false,
['mvj/plotApplications/FETCH_SINGLE']: () => true,
['mvj/plotApplications/RECEIVE_SINGLE']: () => false,
['mvj/plotApplications/SINGLE_NOT_FOUND']: () => false,
['mvj/plotApplications/SINGLE_NOT_ALLOWED']: () => false,
['mvj/plotApplications/EDIT']: () => true,
['mvj/plotApplications/RECEIVE_SAVED']: () => false,
['mvj/plotApplications/APPLICATIONS_NOT_FOUND']: () => false,
}, false);

const isSingleAllowedReducer: Reducer<boolean> = handleActions({
['mvj/plotApplications/RECEIVE_SINGLE']: () => true,
['mvj/plotApplications/SINGLE_NOT_ALLOWED']: () => false,
}, true);

const isEditModeReducer: Reducer<boolean> = handleActions({
'mvj/plotApplications/HIDE_EDIT': () => false,
'mvj/plotApplications/SHOW_EDIT': () => true,
Expand Down Expand Up @@ -164,15 +171,18 @@ const infoCheckBatchEditErrorsReducer: Reducer<InfoCheckBatchEditErrors> = handl
['mvj/plotApplications/BATCH_EDIT_RELATED_MODELS']: () => ({
target: [],
applicant: [],
openingRecord: null,
}),
['mvj/plotApplications/RECEIVE_INFO_CHECK_BATCH_EDIT_SUCCESS']: () => ({
target: [],
applicant: [],
openingRecord: null,
}),
['mvj/plotApplications/RECEIVE_INFO_CHECK_BATCH_EDIT_FAILURE']: (state, {payload}: ReceivePlotApplicationInfoCheckBatchEditFailureAction) => payload,
}, {
target: [],
applicant: [],
openingRecord: null,
});

const targetInfoChecksForCurrentPlotSearchReducer: Reducer<Array<Object>> = handleActions({
Expand All @@ -192,6 +202,7 @@ const isFetchingTargetInfoChecksForCurrentPlotSearchReducer: Reducer<boolean> =
export default (combineReducers<Object, Action<any>>({
isFetching: isFetchingReducer,
isFetchingByBBox: isFetchingByBBoxReducer,
isSingleAllowed: isSingleAllowedReducer,
listByBBox: listByBBoxReducer,
list: plotApplicationsListReducer,
current: currentPlotApplicationReducer,
Expand Down
12 changes: 11 additions & 1 deletion src/plotApplications/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import {
receivePlotSearchSubtypes,
receiveSinglePlotApplication,
receiveTargetInfoCheckMeetingMemoUploaded,
receiveTargetInfoChecksForPlotSearch, showEditMode,
receiveTargetInfoChecksForPlotSearch,
showEditMode,
singlePlotApplicationNotAllowed,
singlePlotApplicationNotFound,
targetInfoCheckMeetingMemoDeleteFailed,
targetInfoCheckMeetingMemoUploadFailed,
targetInfoChecksForPlotSearchNotFound,
Expand Down Expand Up @@ -114,9 +117,16 @@ function* fetchSinglePlotApplicationSaga({payload: id}): Generator<any, any, any
yield put(fetchFormAttributes(bodyAsJson.form));
yield put(fetchApplicantInfoCheckAttributes());
break;
case 401:
case 403:
yield put(singlePlotApplicationNotAllowed());
break;
default:
yield put(singlePlotApplicationNotFound());
}
} catch (e) {
console.error(e);
yield put(singlePlotApplicationNotFound());
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/plotApplications/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const getIsFetching: Selector<boolean, void> = (state: RootState): boolea
export const getIsFetchingByBBox: Selector<boolean, void> = (state: RootState): boolean =>
state.plotApplications.isFetchingByBBox;

export const getIsSingleAllowed: Selector<boolean, void> = (state: RootState): boolean =>
state.plotApplications.isSingleAllowed;

export const getPlotApplicationsList: Selector<PlotApplicationsList, void> = (state: RootState): PlotApplicationsList =>
state.plotApplications.list;

Expand Down
2 changes: 2 additions & 0 deletions src/plotApplications/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ const baseState: PlotApplicationsState = {
infoCheckBatchEditErrors: {
applicant: [],
target: [],
openingRecord: null,
},
targetInfoChecksForCurrentPlotSearch: [],
isFetchingTargetInfoChecksForCurrentPlotSearch: false,
isSingleAllowed: true,
};

// $FlowFixMe
Expand Down
3 changes: 3 additions & 0 deletions src/plotApplications/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type PlotApplicationsState = {
infoCheckBatchEditErrors: InfoCheckBatchEditErrors,
targetInfoChecksForCurrentPlotSearch: Array<Object>,
isFetchingTargetInfoChecksForCurrentPlotSearch: boolean,
isSingleAllowed: boolean,
};

export type PlotApplicationsList = Object;
Expand All @@ -45,6 +46,8 @@ export type NotFoundByBBoxAction = Action<'mvj/plotApplications/NOT_FOUND_BY_BBO

export type FetchSinglePlotApplicationAction = Action<'mvj/plotApplications/FETCH_SINGLE', number>;
export type ReceiveSinglePlotApplicationAction = Action<'mvj/plotApplications/RECEIVE_SINGLE', PlotApplication>;
export type SinglePlotApplicationNotFoundAction = Action<'mvj/plotApplications/SINGLE_NOT_FOUND', void>;
export type SinglePlotApplicationNotAllowedAction = Action<'mvj/plotApplications/SINGLE_NOT_ALLOWED', void>;

export type HideEditModeAction = Action<'mvj/plotApplications/HIDE_EDIT', void>;
export type ShowEditModeAction = Action<'mvj/plotApplications/SHOW_EDIT', void>;
Expand Down

0 comments on commit b7db2cf

Please sign in to comment.