Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the unsealing flow for plot search applications #447

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/form/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ const FormFieldInput = ({
case FieldTypeOptions.DATE:
return formatDate(value);
case FieldTypeOptions.TIME:
return formatDate(value) + ', ' + getHoursAndMinutes(value);
if (value) {
return formatDate(value) + ', ' + getHoursAndMinutes(value);
}
return '-';
case FieldTypeOptions.ADDRESS:
case FieldTypeOptions.INTEGER:
case FieldTypeOptions.STRING:
Expand Down
2 changes: 2 additions & 0 deletions src/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,12 @@ export const FormNames = {
PLOT_SEARCH_APPLICATION: 'plot-search-application-form',
PLOT_SEARCH_APPLICATION_SECTION_STAGING: 'plot-search-application-form-section-staging',
PLOT_SEARCH_APPLICATION_PREVIEW_MOCK_FORM: 'plot-search-application-preview-mock-form',
PLOT_SEARCH_APPLICATIONS_OPENING: 'plot-search-applications-opening',
PLOT_APPLICATIONS_CREATE: 'plot-application-create-form',
PLOT_APPLICATIONS_SEARCH: 'plot-application-search',
PLOT_APPLICATION: 'plot-application',
PLOT_APPLICATION_PREVIEW: 'plot-application-preview',
PLOT_APPLICATION_OPENING: 'plot-application-opening',
APPLICANT_INFO_CHECK: 'applicant-info-check',
PLOT_APPLICATION_TARGET_INFO_CHECK: 'plot-application-target-info-check',
LAND_USE_CONTRACT_CONDITIONS: 'land-use-contract-conditions',
Expand Down
10 changes: 7 additions & 3 deletions src/plotApplications/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import type {
ApplicationRelatedFormNotFoundAction,
ApplicationRelatedPlotSearchNotFoundAction,
ApplicationsNotFoundAction,
BatchEditPlotApplicationInfoChecksAction,
BatchEditPlotApplicationModelsAction,
ClearFormValidFlagsAction,
CreatePlotApplicationOpeningRecordAction,
CreatePlotApplicationAction,
DeleteTargetInfoCheckMeetingMemoAction,
EditPlotApplicationAction,
Expand Down Expand Up @@ -154,8 +155,8 @@ export const targetInfoCheckMeetingMemoUploadFailed = (): TargetInfoCheckMeeting
export const targetInfoCheckMeetingMemoDeleteFailed = (): TargetInfoCheckMeetingMemoDeleteFailedAction =>
createAction('mvj/plotApplications/MEETING_MEMO_DELETE_FAILED')();

export const batchEditApplicationInfoChecks = (payload: InfoCheckBatchEditData): BatchEditPlotApplicationInfoChecksAction =>
createAction('mvj/plotApplications/BATCH_EDIT_INFO_CHECKS')(payload);
export const batchEditApplicationModels = (payload: InfoCheckBatchEditData): BatchEditPlotApplicationModelsAction =>
createAction('mvj/plotApplications/BATCH_EDIT_RELATED_MODELS')(payload);

export const receiveBatchInfoCheckEditSuccess = (): ReceivePlotApplicationInfoCheckBatchEditSuccessAction =>
createAction('mvj/plotApplications/RECEIVE_INFO_CHECK_BATCH_EDIT_SUCCESS')();
Expand All @@ -171,3 +172,6 @@ export const receiveTargetInfoChecksForPlotSearch = (payload: Array<Object>): Re

export const targetInfoChecksForPlotSearchNotFound = (): TargetInfoChecksForPlotSearchNotFoundAction =>
createAction('mvj/plotApplications/TARGET_INFO_CHECKS_FOR_PLOT_SEARCH_NOT_FOUND')();

export const createPlotApplicationOpeningRecord = (id: number): CreatePlotApplicationOpeningRecordAction =>
createAction('mvj/plotApplications/CREATE_OPENING_RECORD')(id);
56 changes: 56 additions & 0 deletions src/plotApplications/components/PlotApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '$src/plotApplications/selectors';
import {receiveCollapseStates} from '$src/plotApplications/actions';
import {
formatDate,
isFieldAllowedToRead,
} from '$util/helpers';
import Loader from '$components/loader/Loader';
Expand Down Expand Up @@ -49,6 +50,9 @@ import type {Attributes} from '$src/types';
import type {PlotApplication as PlotApplicationType} from '$src/plotApplications/types';
import type {SectionExtraComponentProps} from '$src/application/types';
import type {UsersPermissions as UsersPermissionsType} from '$src/usersPermissions/types';
import {PlotApplicationOpeningRecordLabels, PlotApplicationOpeningRecordPaths} from '$src/plotApplications/enums';
import {getHoursAndMinutes} from '$util/date';
import {getContentUser} from '$src/users/helpers';

type OwnProps = {};

Expand Down Expand Up @@ -137,6 +141,58 @@ class PlotApplication extends PureComponent<Props> {
<Loader isLoading={isLoading} />
<Row className='summary__content-wrapper'>
<Column small={12}>
{plotApplication.opening_record && <Collapse
defaultOpen={true}
headerTitle='Hakemuksen avaaminen'
>
<Row>

<Authorization allow={isFieldAllowedToRead(attributes, PlotApplicationOpeningRecordPaths.PLOT_SEARCH_TIMESTAMP)}>
<Column small={12} medium={6} large={4}>
<FormTextTitle>
{PlotApplicationOpeningRecordLabels.PLOT_SEARCH_TIMESTAMP}
</FormTextTitle>
<FormText>{formatDate(plotApplication.plot_search_opening_time_stamp)}{', '}
{getHoursAndMinutes(plotApplication.plot_search_opening_time_stamp)}</FormText>
</Column>
</Authorization>
<Authorization allow={isFieldAllowedToRead(attributes, PlotApplicationOpeningRecordPaths.TIMESTAMP)}>
<Column small={6} medium={3} large={2}>
<FormTextTitle>
{PlotApplicationOpeningRecordLabels.TIMESTAMP}
</FormTextTitle>
<FormText>{formatDate(plotApplication.opening_record.time_stamp)}{', '}
{getHoursAndMinutes(plotApplication.opening_record.time_stamp)}</FormText>
</Column>
</Authorization>
<Authorization allow={isFieldAllowedToRead(attributes, PlotApplicationOpeningRecordPaths.CREATED_BY)}>
<Column small={6} medium={3} large={2}>
<FormTextTitle>
{PlotApplicationOpeningRecordLabels.CREATED_BY}
</FormTextTitle>
<FormText>{plotApplication.opening_record.created_by}</FormText>
</Column>
</Authorization>
<Authorization allow={isFieldAllowedToRead(attributes, PlotApplicationOpeningRecordPaths.OPENERS)}>
<Column small={12} medium={12} large={4}>
<FormTextTitle>
{PlotApplicationOpeningRecordLabels.OPENERS}
</FormTextTitle>
<FormText>{plotApplication.opening_record.openers.map((opener) => getContentUser(opener)?.label).join(', ')}</FormText>
</Column>
</Authorization>
</Row>
<Row>
<Authorization allow={isFieldAllowedToRead(attributes, PlotApplicationOpeningRecordPaths.NOTE)}>
<Column small={12}>
<FormTextTitle>
{PlotApplicationOpeningRecordLabels.NOTE}
</FormTextTitle>
<FormText>{plotApplication.opening_record.note}</FormText>
</Column>
</Authorization>
</Row>
</Collapse>}
<Collapse
defaultOpen={applicationCollapseState !== undefined ? applicationCollapseState : true}
headerTitle='Hakemuksen käsittelytiedot'
Expand Down
42 changes: 26 additions & 16 deletions src/plotApplications/components/PlotApplicationEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import {
import {reshapeSavedApplicationObject} from '$src/plotApplications/helpers';
import {getFieldAttributes} from '$util/helpers';
import {getIsFetchingForm} from '$src/plotSearch/selectors';
import type {Attributes} from '$src/types';
import ApplicationAnswersSection from '$src/application/components/ApplicationAnswersSection';
import Loader from '$components/loader/Loader';
import Title from '$components/content/Title';
import Divider from '$components/content/Divider';
import type {SectionExtraComponentProps} from '$src/application/types';
import PlotApplicationTargetInfoCheckEdit
from '$src/plotApplications/components/infoCheck/PlotApplicationTargetInfoCheckEdit';
import PlotApplicationApplicantInfoCheckEdit
Expand All @@ -29,9 +27,13 @@ import {
getIsFetchingFormAttributes,
} from '$src/application/selectors';
import {APPLICANT_SECTION_IDENTIFIER, TARGET_SECTION_IDENTIFIER} from '$src/application/constants';
import Collapse from '$components/collapse/Collapse';
import PlotApplicationOpeningRecordForm from '$src/plotApplications/components/PlotApplicationOpeningRecordForm';

import type {RootState} from '$src/root/types';
import type {PlotApplication} from '$src/plotApplications/types';
import type {SectionExtraComponentProps} from '$src/application/types';
import type {Attributes} from '$src/types';

type OwnProps = {};

Expand Down Expand Up @@ -100,20 +102,28 @@ class PlotApplicationEdit extends PureComponent<Props> {
</Title>
<Divider />
<Loader isLoading={isLoading} />
{!isLoading && fieldTypes && orderBy(form.sections, 'order').filter((section) => section.visible).map((section) =>
<ApplicationAnswersSection
section={section}
answer={answerData.sections[section.identifier]}
topLevel
fieldTypes={fieldTypes}
key={section.identifier}
plotSearch={plotSearch}
sectionExtraComponent={PlotApplicationEditSectionExtras}
sectionTitleTransformers={[
transformTargetSectionTitle(plotSearch),
transformApplicantSectionTitle,
]}
/>)}
{!isLoading && fieldTypes && <>
{currentPlotApplication.opening_record && <Collapse
defaultOpen={true}
headerTitle='Hakemuksen avaaminen'
>
<PlotApplicationOpeningRecordForm />
</Collapse>}
{orderBy(form.sections, 'order').filter((section) => section.visible).map((section) =>
<ApplicationAnswersSection
section={section}
answer={answerData.sections[section.identifier]}
topLevel
fieldTypes={fieldTypes}
key={section.identifier}
plotSearch={plotSearch}
sectionExtraComponent={PlotApplicationEditSectionExtras}
sectionTitleTransformers={[
transformTargetSectionTitle(plotSearch),
transformApplicantSectionTitle,
]}
/>)}
</>}
</div>
);
}
Expand Down
141 changes: 141 additions & 0 deletions src/plotApplications/components/PlotApplicationOpeningRecordForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// @flow
import React, {Component} from 'react';
import {getFormValues, reduxForm} from 'redux-form';
import {Column, Row} from 'react-foundation';
import {get} from 'lodash/object';
import {flowRight} from 'lodash/util';
import {connect} from 'react-redux';

import FormField from '$components/form/FormField';
import type {RootState} from '$src/root/types';
import {getAttributes} from '$src/application/selectors';
import type {Attributes} from '$src/types';
import {FieldTypes, FormNames} from '$src/enums';
import {getCurrentPlotApplication, getIsSaveClicked} from '$src/plotApplications/selectors';
import {getContentUser} from '$src/users/helpers';
import {PlotApplicationOpeningRecordLabels, PlotApplicationOpeningRecordPaths} from '$src/plotApplications/enums';
import {isFieldAllowedToRead} from '$util/helpers';
import Authorization from '$components/authorization/Authorization';

type Props = {

};

type InnerProps = {
...Props,
attributes: Attributes,
isSaveClicked: boolean,
initialize: Function,
change: Function,
currentPlotApplication: Object,
formValues: Object,
}

class PlotApplicationOpeningRecordForm extends Component<InnerProps> {
componentDidMount(): * {
const {initialize, change, currentPlotApplication, formValues} = this.props;

initialize({
opening_record: {
id: currentPlotApplication.opening_record.id,
note: currentPlotApplication.opening_record.note,
openers: currentPlotApplication.opening_record.openers.map(getContentUser),
time_stamp: currentPlotApplication.opening_record.time_stamp,
plot_search_time_stamp: currentPlotApplication.plot_search_opening_time_stamp,
},
});

if (formValues?.opening_record) {
change('opening_record.note', formValues.opening_record.note);
change('opening_record.openers', formValues.opening_record.openers);
}
}

render(): React$Node {
const {attributes, isSaveClicked} = this.props;

return (
<div>
<Row>
<Authorization allow={isFieldAllowedToRead(attributes, PlotApplicationOpeningRecordPaths.PLOT_SEARCH_TIMESTAMP)}>
<Column small={12} medium={6} large={4}>
<FormField
name='opening_record.plot_search_time_stamp'
fieldAttributes={{
type: FieldTypes.TIME,
read_only: true,
label: PlotApplicationOpeningRecordLabels.PLOT_SEARCH_TIMESTAMP,
}}
disableTouched={isSaveClicked}
/>
</Column>
</Authorization>
<Authorization allow={isFieldAllowedToRead(attributes, PlotApplicationOpeningRecordPaths.TIMESTAMP)}>
<Column small={6} medium={3} large={2}>
<FormField
name='opening_record.time_stamp'
fieldAttributes={{
type: FieldTypes.TIME,
read_only: true,
label: PlotApplicationOpeningRecordLabels.TIMESTAMP,
}}
disableTouched={isSaveClicked}
/>
</Column>
</Authorization>
<Authorization allow={isFieldAllowedToRead(attributes, PlotApplicationOpeningRecordPaths.CREATED_BY)}>
<Column small={6} medium={3} large={2}>
<FormField
name='opening_record.created_by'
fieldAttributes={get(attributes, PlotApplicationOpeningRecordPaths.CREATED_BY)}
overrideValues={{
label: PlotApplicationOpeningRecordLabels.CREATED_BY,
}}
disableTouched={isSaveClicked}
/>
</Column>
</Authorization>
<Authorization allow={isFieldAllowedToRead(attributes, PlotApplicationOpeningRecordPaths.OPENERS)}>
<Column small={12} medium={12} large={4}>
<FormField
name='opening_record.openers'
fieldAttributes={get(attributes, PlotApplicationOpeningRecordPaths.OPENERS)}
overrideValues={{
fieldType: FieldTypes.USER,
label: PlotApplicationOpeningRecordLabels.OPENERS,
required: true,
multiSelect: true,
}}
disableTouched={isSaveClicked}
/>
</Column>
</Authorization>
</Row>
<Row>
<Authorization allow={isFieldAllowedToRead(attributes, PlotApplicationOpeningRecordPaths.NOTE)}>
<Column small={12}>
<FormField
name='opening_record.note'
fieldAttributes={get(attributes, PlotApplicationOpeningRecordPaths.NOTE)}
overrideValues={{
fieldType: FieldTypes.TEXTAREA,
required: true,
label: PlotApplicationOpeningRecordLabels.NOTE,
}}
/>
</Column>
</Authorization>
</Row>
</div>
);
}
}

export default (flowRight(connect((state: RootState) => ({
attributes: getAttributes(state),
isSaveClicked: getIsSaveClicked(state),
currentPlotApplication: getCurrentPlotApplication(state),
formValues: getFormValues(FormNames.PLOT_APPLICATION_OPENING)(state),
})), reduxForm({
form: FormNames.PLOT_APPLICATION_OPENING,
}))(PlotApplicationOpeningRecordForm): React$ComponentType<Props>);
Loading
Loading