diff --git a/src/leases/components/leaseSections/rent/OldDwellingsInHousingCompaniesPriceIndex.tsx b/src/leases/components/leaseSections/rent/OldDwellingsInHousingCompaniesPriceIndex.tsx index 8c065b15..a8b8b03a 100644 --- a/src/leases/components/leaseSections/rent/OldDwellingsInHousingCompaniesPriceIndex.tsx +++ b/src/leases/components/leaseSections/rent/OldDwellingsInHousingCompaniesPriceIndex.tsx @@ -5,7 +5,7 @@ import { flowRight } from 'lodash'; import { connect } from 'react-redux'; import type { OldDwellingsInHousingCompaniesPriceIndex as OldDwellingsInHousingCompaniesPriceIndexProps, - IndexNumberYearly as IndexNumberYearlyProps, + IndexPointFigureYearly as IndexPointFigureYearlyProps, } from '@/leases/types'; import BoxItemContainer from '@/components/content/BoxItemContainer'; import { withWindowResize } from '@/components/resize/WindowResizeHandler'; @@ -15,36 +15,38 @@ import { LeaseFieldTitles, LeaseRentOldDwellingsInHousingCompaniesPriceIndexFiel import Authorization from '@/components/authorization/Authorization'; import { getUiDataLeaseKey } from '@/uiData/helpers'; import { formatDate } from '../../../../util/helpers'; +import { OldDwellingsInHousingCompaniesPriceIndex } from '../../../types'; type Props = { oldDwellingsInHousingCompaniesPriceIndex: OldDwellingsInHousingCompaniesPriceIndexProps; leaseStartDate: string; }; -const getLastYearsIndexPointNumber = (annualIndexNumbers: IndexNumberYearlyProps[]): string => { +const getLastYearsIndexPointNumber = (pointFigures: IndexPointFigureYearlyProps[]): string => { const lastYear = new Date().getFullYear() - 1; - const lastYearIndex = annualIndexNumbers.find((x: IndexNumberYearlyProps) => x.year == lastYear); - return lastYearIndex ? `${lastYearIndex.year} * ${lastYearIndex.number}` : ''; + const lastYearIndex = pointFigures?.find((x: IndexPointFigureYearlyProps) => x.year == lastYear) || null; + return lastYearIndex ? `${lastYearIndex.year} * ${lastYearIndex.value}` : 'Indeksipisteluvut puuttuvat'; } -const getReviewDaysSorted = (annualIndexNumbers: IndexNumberYearlyProps[]): IndexNumberYearlyProps[] => { +const getReviewDaysSorted = (pointFigures: IndexPointFigureYearlyProps[]): IndexPointFigureYearlyProps[] => { // deep copy - const sortedNumbers = JSON.parse(JSON.stringify(annualIndexNumbers)); + const sortedNumbers = JSON.parse(JSON.stringify(pointFigures)); - sortedNumbers.sort((a: IndexNumberYearlyProps, b: IndexNumberYearlyProps) => a.year - b.year); + sortedNumbers.sort((a: IndexPointFigureYearlyProps, b: IndexPointFigureYearlyProps) => a.year - b.year); return sortedNumbers; } -class OldDwellingsInHousingCompaniesPriceIndex extends PureComponent { +class OldDwellingsInHousingCompaniesPriceIndexView extends PureComponent { render() { const { - oldDwellingsInHousingCompaniesPriceIndex: { - name, - numbers, - source_table_label: sourceTableLabel, - }, + oldDwellingsInHousingCompaniesPriceIndex, leaseStartDate } = this.props; + const { + name, + point_figures: pointFigures, + source_table_label: sourceTableLabel + } = oldDwellingsInHousingCompaniesPriceIndex || {}; return @@ -74,7 +76,7 @@ class OldDwellingsInHousingCompaniesPriceIndex extends PureComponent { {LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.NUMBERS} - {getLastYearsIndexPointNumber(numbers)} + {getLastYearsIndexPointNumber(pointFigures)} {sourceTableLabel} @@ -87,9 +89,9 @@ class OldDwellingsInHousingCompaniesPriceIndex extends PureComponent { {LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.REVIEW_DAYS} <> - {numbers && !!numbers.length ? - getReviewDaysSorted(numbers).map( - (number: IndexNumberYearlyProps, index: number) => { + {pointFigures && !!pointFigures.length ? + getReviewDaysSorted(pointFigures).map( + (number: IndexPointFigureYearlyProps, index: number) => { return {`1.1.${number.year}`} @@ -111,4 +113,4 @@ export default flowRight(withWindowResize, connect(state => { leaseAttributes: getLeaseAttributes(state), leaseStartDate: getCurrentLeaseStartDate(state) }; -}))(OldDwellingsInHousingCompaniesPriceIndex); \ No newline at end of file +}))(OldDwellingsInHousingCompaniesPriceIndexView); \ No newline at end of file diff --git a/src/leases/components/leaseSections/rent/RentItem.tsx b/src/leases/components/leaseSections/rent/RentItem.tsx index ab4ffb4f..035820b7 100644 --- a/src/leases/components/leaseSections/rent/RentItem.tsx +++ b/src/leases/components/leaseSections/rent/RentItem.tsx @@ -20,7 +20,7 @@ import { formatDateRange, getFieldOptions, getLabelOfOption, isActive, isArchive import { getAttributes as getLeaseAttributes, getCollapseStateByKey } from "@/leases/selectors"; import type { Attributes } from "types"; import type { ServiceUnit } from "@/serviceUnits/types"; -import OldDwellingsInHousingCompaniesPriceIndex from "./OldDwellingsInHousingCompaniesPriceIndex"; +import OldDwellingsInHousingCompaniesPriceIndexView from "./OldDwellingsInHousingCompaniesPriceIndex"; const formName = FormNames.LEASE_RENTS; type Props = { @@ -117,9 +117,10 @@ const RentItem = ({ } onToggle={handleRentCollapseToggle}> {/* TODO: Add authorization for OldDwellingsInHousingCompaniesPriceIndex */} - {/* */} + { oldDwellingsInHousingCompaniesPriceIndex && + /* */ - + {/* */} diff --git a/src/leases/types.ts b/src/leases/types.ts index c14e8bc9..761bb4bd 100644 --- a/src/leases/types.ts +++ b/src/leases/types.ts @@ -1,7 +1,6 @@ import type { Action, ApiResponse, Attributes, Methods } from "@/types"; import type { ServiceUnit } from "@/serviceUnits/types"; -import { year } from '../components/form/validations'; -import commentSaga from '@/comments/saga'; + export type LeaseState = { attributes: Attributes; byId: Record; @@ -13,7 +12,7 @@ export type LeaseState = { isEditMode: boolean; isFetching: boolean; isFetchingByBBox: boolean; - isFetchingById: {}; + isFetchingById: Record; isFetchingAttributes: boolean; isSaveClicked: boolean; isSaving: boolean; @@ -51,8 +50,8 @@ export type IntendedUse = { name: string; service_unit: ServiceUnit["id"]; }; -export type IndexNumberYearly = { - number: number; +export type IndexPointFigureYearly = { + value: number; year: number; region: string; comment: string; @@ -65,7 +64,7 @@ export type OldDwellingsInHousingCompaniesPriceIndex = { source_table_updated?: string; source_table_label: string; url: string; - numbers: IndexNumberYearly[]; + point_figures: IndexPointFigureYearly[]; } export type FetchAttributesAction = Action; export type ReceiveAttributesAction = Action;