Skip to content

Commit

Permalink
Fix hiding the field from MaKe
Browse files Browse the repository at this point in the history
  • Loading branch information
juho-kettunen-nc committed Nov 13, 2024
1 parent 2d20f94 commit 4b9ea58
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/leases/components/leaseSections/rent/ContractRentEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Props = {
receivableTypes: Array<Record<string, any>>;
rentField: string;
rentType: string;
serviceUnitId: number;
showRemove: boolean;
usersPermissions: UsersPermissionsType;
change: (...args: Array<any>) => any;
Expand Down Expand Up @@ -73,6 +74,7 @@ class ContractRentEdit extends PureComponent<Props> {
onRemove,
receivableTypes,
rentType,
serviceUnitId: leaseServiceUnitId,
showRemove,
usersPermissions
} = this.props;
Expand Down Expand Up @@ -223,11 +225,9 @@ class ContractRentEdit extends PureComponent<Props> {
</Authorization>;

const endDateField = <Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentContractRentsFieldPaths.END_DATE)}>
{leaseAttributes.service_unit.id !== ServiceUnitIds.MAKE &&
<FormField disableTouched={isSaveClicked} fieldAttributes={getFieldAttributes(leaseAttributes, LeaseRentContractRentsFieldPaths.END_DATE)} name={`${field}.end_date`} overrideValues={{
label: LeaseRentContractRentsFieldTitles.END_DATE
}} enableUiDataEdit uiDataKey={getUiDataLeaseKey(LeaseRentContractRentsFieldPaths.END_DATE)} />
}
</Authorization>;

const indexField = <Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentContractRentsFieldPaths.INDEX)}>
Expand All @@ -245,9 +245,9 @@ class ContractRentEdit extends PureComponent<Props> {
<Column small={6} medium={4} large={2}>
{intendedUseField}
</Column>
<Column small={6} medium={4} large={2}>
{ leaseServiceUnitId !== ServiceUnitIds.MAKE && <Column small={6} medium={4} large={2}>
{overrideReceivableTypeField}
</Column>
</Column>}
{rentType === RentTypes.INDEX2022 && <Column small={6} medium={4} large={2}>
{indexField}
</Column>}
Expand Down
4 changes: 3 additions & 1 deletion src/leases/components/leaseSections/rent/ContractRents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Props = {
largeScreen: boolean;
leaseAttributes: Attributes;
rentType: string;
serviceUnitId: number;
};
type State = {
amountPeriodOptions: Array<Record<string, any>>;
Expand Down Expand Up @@ -61,6 +62,7 @@ class ContractRents extends PureComponent<Props, State> {
largeScreen,
leaseAttributes,
rentType,
serviceUnitId,
} = this.props;
const {
amountPeriodOptions,
Expand Down Expand Up @@ -125,7 +127,7 @@ class ContractRents extends PureComponent<Props, State> {
</>
</Authorization>
</Column>
{(leaseAttributes.service_unit.id !== ServiceUnitIds.MAKE) && <Column small={6} medium={4} large={3}>
{(serviceUnitId !== ServiceUnitIds.MAKE) && <Column small={6} medium={4} large={3}>
<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentContractRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
<>
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentContractRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@ import { ConfirmationModalTexts } from "@/enums";
import { ButtonColors } from "@/components/enums";
import { UsersPermissions } from "@/usersPermissions/enums";
import { hasPermissions } from "@/util/helpers";
import { getAttributes as getLeaseAttributes } from "@/leases/selectors";
import { getUsersPermissions } from "@/usersPermissions/selectors";
import type { Attributes } from "types";
import type { UsersPermissions as UsersPermissionsType } from "@/usersPermissions/types";
type Props = {
fields: any;
leaseAttributes: Attributes;
rentField: string;
rentType: string;
serviceUnitId: number;
usersPermissions: UsersPermissionsType;
};

const ContractRentsEdit = ({
fields,
leaseAttributes,
rentField,
rentType,
serviceUnitId,
usersPermissions
}: Props) => {
const handleAdd = () => {
Expand Down Expand Up @@ -60,7 +58,7 @@ const ContractRentsEdit = ({
});
};

return <ContractRentEdit key={index} field={rent} onRemove={handleRemove} rentField={rentField} rentType={rentType} showRemove={!!fields && fields.length > 1} />;
return <ContractRentEdit key={index} field={rent} onRemove={handleRemove} rentField={rentField} rentType={rentType} showRemove={!!fields && fields.length > 1} serviceUnitId={serviceUnitId} />;
})}
</BoxItemContainer>}

Expand All @@ -78,7 +76,6 @@ const ContractRentsEdit = ({

export default connect(state => {
return {
leaseAttributes: getLeaseAttributes(state),
usersPermissions: getUsersPermissions(state)
};
})(ContractRentsEdit);
4 changes: 3 additions & 1 deletion src/leases/components/leaseSections/rent/RentItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Props = {
rents: Array<Record<string, any>>;
rentAdjustmentsCollapseState: boolean;
rentCollapseState: boolean;
serviceUnitId: number;
};

const RentItem = ({
Expand All @@ -46,6 +47,7 @@ const RentItem = ({
rents,
rentAdjustmentsCollapseState,
rentCollapseState,
serviceUnitId,
}: Props) => {
const handleCollapseToggle = (key: string, val: boolean) => {
receiveCollapseStates({
Expand Down Expand Up @@ -118,7 +120,7 @@ const RentItem = ({

<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentContractRentsFieldPaths.CONTRACT_RENTS)}>
{(rentTypeIsIndex || rentTypeIsIndex2022 || rentTypeIsFixed || rentTypeIsManual) && <Collapse className='collapse__secondary' defaultOpen={contractRentsCollapseState !== undefined ? contractRentsCollapseState : true} headerTitle={`${LeaseRentContractRentsFieldTitles.CONTRACT_RENTS} (${contractRents.length})`} onToggle={handleContractRentsCollapseToggle} uiDataKey={getUiDataLeaseKey(LeaseRentContractRentsFieldPaths.CONTRACT_RENTS)}>
<ContractRents contractRents={contractRents} rentType={rentType} />
<ContractRents contractRents={contractRents} rentType={rentType} serviceUnitId={serviceUnitId}/>
</Collapse>}
</Authorization>

Expand Down
6 changes: 4 additions & 2 deletions src/leases/components/leaseSections/rent/RentItemEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Props = {
rentId: number;
rents: Array<Record<string, any>>;
rentType: string | null | undefined;
serviceUnitId: number;
usersPermissions: UsersPermissionsType;
};
type State = {
Expand Down Expand Up @@ -237,6 +238,7 @@ class RentItemEdit extends PureComponent<Props, State> {
rentCollapseState,
rentType,
rents,
serviceUnitId,
usersPermissions
} = this.props;
const {
Expand Down Expand Up @@ -277,7 +279,7 @@ class RentItemEdit extends PureComponent<Props, State> {

<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentContractRentsFieldPaths.CONTRACT_RENTS)}>
{(rentTypeIsIndex || rentTypeIsIndex2022 || rentTypeIsFixed || rentTypeIsManual) && <Collapse className='collapse__secondary' defaultOpen={contractRentsCollapseState !== undefined ? contractRentsCollapseState : true} hasErrors={isSaveClicked && !isEmpty(contractRentErrors)} headerTitle={`${LeaseRentContractRentsFieldTitles.CONTRACT_RENTS} (${contractRents ? contractRents.length : 0})`} onToggle={this.handleContractRentsCollapseToggle} enableUiDataEdit uiDataKey={getUiDataLeaseKey(LeaseRentContractRentsFieldPaths.CONTRACT_RENTS)}>
<FieldArray component={ContractRentsEdit} isSaveClicked={isSaveClicked} name={`${field}.contract_rents`} rentField={field} rentType={rentType} />
<FieldArray component={ContractRentsEdit} isSaveClicked={isSaveClicked} name={`${field}.contract_rents`} rentField={field} rentType={rentType} serviceUnitId={serviceUnitId}/>
</Collapse>}
</Authorization>

Expand Down Expand Up @@ -340,4 +342,4 @@ export default connect((state, props) => {
}, {
change,
receiveCollapseStates
})(RentItemEdit);
})(RentItemEdit);
2 changes: 1 addition & 1 deletion src/leases/components/leaseSections/rent/Rents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const Rents = ({
<>
{!rents || !rents.length && <FormText className='no-margin'>Ei vuokria</FormText>}
{rents && !!rents.length && rents.map(rent => {
return <RentItem key={rent.id} rent={rent} rents={rents} />;
return <RentItem key={rent.id} rent={rent} rents={rents} serviceUnitId={currentLease.service_unit.id} />;
})}

{!!rentsArchived.length && <h3 style={{
Expand Down
9 changes: 6 additions & 3 deletions src/leases/components/leaseSections/rent/RentsEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ type RentsProps = {
archived: boolean;
fields: any;
rents: Array<Record<string, any>>;
serviceUnitId: number;
usersPermissions: UsersPermissionsType;
};

const renderRents = ({
archived,
fields,
rents,
serviceUnitId,
usersPermissions
}: RentsProps): ReactElement => {
const handleAdd = () => {
Expand Down Expand Up @@ -99,7 +101,7 @@ const renderRents = ({
});
};

return <RentItemEdit key={index} field={item} index={index} onRemove={handleRemove} rents={rents} />;
return <RentItemEdit key={index} field={item} index={index} onRemove={handleRemove} rents={rents} serviceUnitId={serviceUnitId}/>;
})}
{!archived && <Authorization allow={hasPermissions(usersPermissions, UsersPermissions.ADD_RENT)}>
<Row>
Expand Down Expand Up @@ -219,6 +221,7 @@ class RentsEdit extends PureComponent<Props, State> {

render() {
const {
currentLease,
editedActiveBasisOfRents,
editedArchivedBasisOfRents,
isRentInfoComplete,
Expand Down Expand Up @@ -282,7 +285,7 @@ class RentsEdit extends PureComponent<Props, State> {
<Field name='rentWarnings' component={RentWarnings} leaseAttributes={leaseAttributes} showWarning={true} />
<Divider />

<FieldArray component={renderRents} archive={false} name='rents' rents={rents} usersPermissions={usersPermissions} />
<FieldArray component={renderRents} archived={false} name='rents' rents={rents} usersPermissions={usersPermissions} serviceUnitId={currentLease.service_unit.id} />

{
/* Archived rents */
Expand Down Expand Up @@ -344,4 +347,4 @@ export default flowRight(withRouter, connect(state => {
destroyOnUnmount: false,
validate: validateRentForm,
warn: warnRentForm
}))(RentsEdit) as React.ComponentType<any>;
}))(RentsEdit) as React.ComponentType<any>;

0 comments on commit 4b9ea58

Please sign in to comment.