Skip to content

Commit

Permalink
Merge pull request #448 from City-of-Helsinki/fix-plot-application-er…
Browse files Browse the repository at this point in the history
…ror-states

Fix plot application page error states
  • Loading branch information
EmiliaMakelaVincit authored Nov 20, 2023
2 parents dd973ee + 5384121 commit c43ec31
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 7 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
14 changes: 13 additions & 1 deletion src/plotApplications/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ 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_FOUND']: () => 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 +172,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 +203,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
2 changes: 1 addition & 1 deletion src/plotSearch/components/PlotSearchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ class PlotSearchPage extends Component<Props, State> {
isEditMode={isEditMode}
isSaveDisabled={isSaveClicked && !areFormsValid}
onCancel={this.cancelChanges}
onEdit={this.handleShowEditMode}
onEdit={() => this.handleShowEditMode(false)}
onSave={this.saveChanges}
showCommentButton={false}
showCopyButton={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default (flowRight(
connect((state: RootState) => ({
applicationAttributes: getAttributes(state),
plotSearch: getCurrentPlotSearch(state),
enabled: formValueSelector(FormNames.PLOT_SEARCH_APPLICATIONS_OPENING)(state, 'openingRecord') !== null,
enabled: formValueSelector(FormNames.PLOT_SEARCH_APPLICATIONS_OPENING)(state, 'opening_record') !== null,
})),
reduxForm({
form: FormNames.PLOT_SEARCH_APPLICATIONS_OPENING,
Expand Down

0 comments on commit c43ec31

Please sign in to comment.