Skip to content

Commit

Permalink
Merge pull request #327 from City-of-Helsinki/develop
Browse files Browse the repository at this point in the history
Release 20210108
  • Loading branch information
kovedev authored Jan 8, 2021
2 parents 9ed29b1 + 9378881 commit 01550df
Show file tree
Hide file tree
Showing 30 changed files with 1,464 additions and 415 deletions.
1 change: 1 addition & 0 deletions src/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ export const FormNames = {
PLOT_APPLICATIONS_CREATE: 'plot-application-create-form',
PLOT_APPLICATIONS_SEARCH: 'plot-application-search',
PLOT_APPLICATION: 'plot-application',
LAND_USE_CONTRACT_CONDITIONS: 'land-use-contract-conditions',
};

/**
Expand Down
12 changes: 10 additions & 2 deletions src/landUseContract/attributes-mock-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
"label": "Viite",
"max_length": 255
},
"litigantcontact_set": {
"landuseagreementlitigantcontact_set": {
"type": "field",
"required": false,
"read_only": false,
Expand Down Expand Up @@ -626,14 +626,22 @@
"contracts": {
"child": {
"children": {
"contract_type": {
"type": {
"type": "field",
"required": true,
"read_only": false,
"label": "Sopimuksen tyyppi",
"label_translations": {
"finnish": "Sopimukset tyyppi",
"swedish": "Jag talar inte svärge"
},
"choices": [
{
"display_name": "Kiinteistökaupan esisopimus",
"display_name_translations": {
"finnish": "Kiinteistökaupan esisopimus",
"swedish": "Jag talar inte svärge"
},
"value": 1
}
]
Expand Down
35 changes: 30 additions & 5 deletions src/landUseContract/components/LandUseContractPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {change, destroy, getFormValues, initialize, isDirty} from 'redux-form';
import flowRight from 'lodash/flowRight';
import isEmpty from 'lodash/isEmpty';

import {withUiDataList} from '$components/uiData/UiDataListHOC';
import BasicInformation from './sections/BasicInformation';
import BasicInformationEdit from './sections/BasicInformationEdit';
import Conditions from './sections/Conditions';
import ConditionsEdit from './sections/ConditionsEdit';
import Compensations from './sections/Compensations';
import CompensationsEdit from './sections/CompensationsEdit';
import ConfirmationModal from '$components/modal/ConfirmationModal';
Expand Down Expand Up @@ -63,6 +66,7 @@ import {
getContentDecisions,
getContentInvoices,
getContentLitigants,
getContentConditions,
} from '$src/landUseContract/helpers';
import {getSearchQuery, getUrlParams, isArchived, scrollToTopPage, setPageTitle} from '$util/helpers';
import {getRouteById, Routes} from '$src/root/routes';
Expand Down Expand Up @@ -107,6 +111,9 @@ type Props = {
isContractsFormValid: boolean,
isDecisionsFormDirty: boolean,
isDecisionsFormValid: boolean,
isConditionsFormDirty: boolean,
isConditionsFormValid: boolean,
conditionsFormValues: Object,
isEditMode: boolean,
isFetchingLandUseContractAttributes: boolean,
isFetchingUsersPermissions: boolean,
Expand Down Expand Up @@ -486,6 +493,7 @@ class LandUseContractPage extends Component<Props, State> {
initialize(FormNames.LAND_USE_CONTRACT_CONTRACTS, {contracts: getContentContracts(landUseContract)});
initialize(FormNames.LAND_USE_CONTRACT_COMPENSATIONS, {compensations: getContentCompensations(landUseContract)});
initialize(FormNames.LAND_USE_CONTRACT_INVOICES, {invoices: getContentInvoices(landUseContract)});
initialize(FormNames.LAND_USE_CONTRACT_CONDITIONS, {conditions: getContentConditions(landUseContract)});
}

cancelChanges = () => {
Expand Down Expand Up @@ -517,6 +525,8 @@ class LandUseContractPage extends Component<Props, State> {
isInvoicesFormDirty,
isLitigantsFormDirty,
litigantsFormValues,
isConditionsFormDirty,
conditionsFormValues,
} = this.props;

//TODO: Add helper functions to save land use contract to DB when API is ready
Expand All @@ -542,14 +552,16 @@ class LandUseContractPage extends Component<Props, State> {
if(isInvoicesFormDirty) {
payload = {...payload, ...invoicesFormValues};
}

if(isLitigantsFormDirty) {
payload = addLitigantsFormValuesToPayload(payload, litigantsFormValues);
}

payload.identifier = currentLandUseContract.identifier;
if(isConditionsFormDirty) {
payload = {...payload, ...conditionsFormValues};
}

payload.decisions = null;
payload.identifier = currentLandUseContract.identifier;

editLandUseContract(payload);
}
Expand All @@ -563,6 +575,7 @@ class LandUseContractPage extends Component<Props, State> {
isDecisionsFormValid,
isInvoicesFormValid,
isLitigantsFormValid,
isConditionsFormValid,
} = this.props;

return (
Expand All @@ -571,7 +584,8 @@ class LandUseContractPage extends Component<Props, State> {
isContractsFormValid &&
isDecisionsFormValid &&
isInvoicesFormValid &&
isLitigantsFormValid
isLitigantsFormValid &&
isConditionsFormValid
);
}

Expand Down Expand Up @@ -791,8 +805,14 @@ class LandUseContractPage extends Component<Props, State> {

<TabPane>
<ContentContainer>
{!isEditMode
? <Conditions />
: <ConditionsEdit />
}
{/*
<h2>Valvottavat ehdot</h2>
<Divider />
<Divider />
*/}
</ContentContainer>
</TabPane>
</TabContent>
Expand All @@ -805,6 +825,7 @@ class LandUseContractPage extends Component<Props, State> {
export default flowRight(
withRouter,
withLandUseContractAttributes,
withUiDataList,
connect(
(state, props: Props) => {
return {
Expand Down Expand Up @@ -836,6 +857,10 @@ export default flowRight(
invoices: getInvoicesByLandUseContractId(state, props.match.params.landUseContractId),
isFetchingLandUseInvoiceAttributes: getIsFetchingLandUseInvoiceAttributes(state),
landUseInvoiceAttributes: getLandUseInvoiceAttributes(state),

isConditionsFormDirty: isDirty(FormNames.LAND_USE_CONTRACT_CONDITIONS)(state),
isConditionsFormValid: getIsFormValidById(state, FormNames.LAND_USE_CONTRACT_CONDITIONS),
conditionsFormValues: getFormValues(FormNames.LAND_USE_CONTRACT_CONDITIONS)(state),
};
},
{
Expand Down
75 changes: 43 additions & 32 deletions src/landUseContract/components/sections/AddressItemEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import RemoveButton from '$components/form/RemoveButton';
import {getUsersPermissions} from '$src/usersPermissions/selectors';
import type {Attributes} from '$src/types';
import type {UsersPermissions as UsersPermissionsType} from '$src/usersPermissions/types';
import {
isFieldAllowedToRead,
} from '$util/helpers';

type Props = {
attributes: Attributes,
Expand All @@ -32,38 +35,46 @@ const AddressItemEdit = ({

return (
<Row>
<Column small={6} medium={4} large={2}>
<FormField
disableTouched={isSaveClicked}
fieldAttributes={get(attributes, 'addresses.child.children.address')}
name={`${field}.address`}
invisibleLabel
/>
</Column>
<Column small={6} medium={4} large={2}>
<FormField
disableTouched={isSaveClicked}
fieldAttributes={get(attributes, 'addresses.child.children.postal_code')}
name={`${field}.postal_code`}
invisibleLabel
/>
</Column>
<Column small={6} medium={4} large={2}>
<FormField
disableTouched={isSaveClicked}
fieldAttributes={get(attributes, 'addresses.child.children.city')}
name={`${field}.city`}
invisibleLabel
/>
</Column>
<Column small={6} medium={4} large={2}>
<FormField
disableTouched={isSaveClicked}
fieldAttributes={get(attributes, 'addresses.child.children.is_primary')}
name={`${field}.is_primary`}
invisibleLabel
/>
</Column>
<Authorization allow={isFieldAllowedToRead(attributes, 'addresses.child.children.address')}>
<Column small={6} medium={4} large={2}>
<FormField
disableTouched={isSaveClicked}
fieldAttributes={get(attributes, 'addresses.child.children.address')}
name={`${field}.address`}
invisibleLabel
/>
</Column>
</Authorization>
<Authorization allow={isFieldAllowedToRead(attributes, 'addresses.child.children.postal_code')}>
<Column small={6} medium={4} large={2}>
<FormField
disableTouched={isSaveClicked}
fieldAttributes={get(attributes, 'addresses.child.children.postal_code')}
name={`${field}.postal_code`}
invisibleLabel
/>
</Column>
</Authorization>
<Authorization allow={isFieldAllowedToRead(attributes, 'addresses.child.children.city')}>
<Column small={6} medium={4} large={2}>
<FormField
disableTouched={isSaveClicked}
fieldAttributes={get(attributes, 'addresses.child.children.city')}
name={`${field}.city`}
invisibleLabel
/>
</Column>
</Authorization>
<Authorization allow={isFieldAllowedToRead(attributes, 'addresses.child.children.is_primary')}>
<Column small={6} medium={4} large={2}>
<FormField
disableTouched={isSaveClicked}
fieldAttributes={get(attributes, 'addresses.child.children.is_primary')}
name={`${field}.is_primary`}
invisibleLabel
/>
</Column>
</Authorization>
<Column large={1}>
<Authorization allow={true}>
{!disabled &&
Expand Down
Loading

0 comments on commit 01550df

Please sign in to comment.