-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MVJ-421 tasotarkistus to rents tab (#549)
* tasotarkistus to rents tab: static view
- Loading branch information
1 parent
2c27a16
commit 242c63c
Showing
8 changed files
with
325 additions
and
6 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
src/leases/components/leaseSections/rent/OldDwellingsInHousingCompaniesPriceIndex.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React, { Fragment, PureComponent } from 'react'; | ||
import { Row, Column } from "react-foundation"; | ||
import { getCurrentLeaseStartDate, getAttributes as getLeaseAttributes } from '@/leases/selectors'; | ||
import { flowRight } from 'lodash'; | ||
import { connect } from 'react-redux'; | ||
import type { | ||
OldDwellingsInHousingCompaniesPriceIndex as OldDwellingsInHousingCompaniesPriceIndexProps, | ||
IndexPointFigureYearly as IndexPointFigureYearlyProps, | ||
} from '@/leases/types'; | ||
import BoxItemContainer from '@/components/content/BoxItemContainer'; | ||
import { withWindowResize } from '@/components/resize/WindowResizeHandler'; | ||
import FormText from "@/components/form/FormText"; | ||
import FormTextTitle from '@/components/form/FormTextTitle'; | ||
import { LeaseFieldTitles, LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths, LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles } from '@/leases/enums'; | ||
import { getUiDataLeaseKey } from '@/uiData/helpers'; | ||
import { formatDate } from '@/util/helpers'; | ||
|
||
type Props = { | ||
oldDwellingsInHousingCompaniesPriceIndex: OldDwellingsInHousingCompaniesPriceIndexProps; | ||
leaseStartDate: string; | ||
}; | ||
|
||
const getLastYearsIndexPointNumber = (pointFigures: IndexPointFigureYearlyProps[]): string => { | ||
const lastYear = new Date().getFullYear() - 1; | ||
const lastYearIndex = pointFigures?.find((x: IndexPointFigureYearlyProps) => x.year == lastYear) || null; | ||
return lastYearIndex ? `${lastYearIndex.year} * ${lastYearIndex.value}` : 'Indeksipisteluvut puuttuvat'; | ||
} | ||
|
||
const getReviewDaysSorted = (pointFigures: IndexPointFigureYearlyProps[]): IndexPointFigureYearlyProps[] => { | ||
// deep copy | ||
const sortedNumbers = JSON.parse(JSON.stringify(pointFigures)); | ||
|
||
sortedNumbers.sort((a: IndexPointFigureYearlyProps, b: IndexPointFigureYearlyProps) => a.year - b.year); | ||
return sortedNumbers; | ||
} | ||
|
||
class OldDwellingsInHousingCompaniesPriceIndexView extends PureComponent<Props> { | ||
render() { | ||
const { | ||
oldDwellingsInHousingCompaniesPriceIndex, | ||
leaseStartDate | ||
} = this.props; | ||
const { | ||
name, | ||
point_figures: pointFigures, | ||
source_table_label: sourceTableLabel | ||
} = oldDwellingsInHousingCompaniesPriceIndex || {}; | ||
return <Fragment> | ||
<BoxItemContainer> | ||
<Row> | ||
<Column> | ||
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NAME)}> | ||
{LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.NAME} | ||
</FormTextTitle> | ||
<FormText>{name}</FormText> | ||
</Column> | ||
<Column> | ||
<FormTextTitle> | ||
{LeaseFieldTitles.START_DATE} | ||
</FormTextTitle> | ||
<FormText>{formatDate(leaseStartDate)}</FormText> | ||
</Column> | ||
<Column> | ||
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS)}> | ||
{LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.NUMBERS} | ||
</FormTextTitle> | ||
<FormText>{getLastYearsIndexPointNumber(pointFigures)}</FormText> | ||
<FormText>{sourceTableLabel}</FormText> | ||
</Column> | ||
<Column> | ||
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS)}> | ||
{LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.REVIEW_DAYS} | ||
</FormTextTitle> | ||
<> | ||
{pointFigures && !!pointFigures.length ? | ||
getReviewDaysSorted(pointFigures).map( | ||
(number: IndexPointFigureYearlyProps, index: number) => { | ||
return <FormText key={LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS + `[${index}]`}> | ||
{`1.1.${number.year}`} | ||
</FormText> | ||
} | ||
) | ||
: ""} | ||
</> | ||
</Column> | ||
</Row> | ||
</BoxItemContainer> | ||
</Fragment> | ||
} | ||
} | ||
|
||
export default flowRight(withWindowResize, connect(state => { | ||
return { | ||
leaseAttributes: getLeaseAttributes(state), | ||
leaseStartDate: getCurrentLeaseStartDate(state) | ||
}; | ||
}))(OldDwellingsInHousingCompaniesPriceIndexView); |
149 changes: 149 additions & 0 deletions
149
src/leases/components/leaseSections/rent/OldDwellingsInHousingCompaniesPriceIndexEdit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import React, { Fragment, PureComponent } from "react"; | ||
import { Row, Column } from "react-foundation"; | ||
import { | ||
getCurrentLeaseStartDate, | ||
getAttributes as getLeaseAttributes, | ||
} from "@/leases/selectors"; | ||
import { flowRight } from "lodash"; | ||
import { connect } from "react-redux"; | ||
import type { | ||
OldDwellingsInHousingCompaniesPriceIndex as OldDwellingsInHousingCompaniesPriceIndexProps, | ||
IndexPointFigureYearly as IndexPointFigureYearlyProps, | ||
} from "@/leases/types"; | ||
import BoxItemContainer from "@/components/content/BoxItemContainer"; | ||
import { withWindowResize } from "@/components/resize/WindowResizeHandler"; | ||
import FormText from "@/components/form/FormText"; | ||
import FormTextTitle from "@/components/form/FormTextTitle"; | ||
import { | ||
LeaseFieldTitles, | ||
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths, | ||
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles, | ||
} from "@/leases/enums"; | ||
import { getUiDataLeaseKey } from "@/uiData/helpers"; | ||
import { formatDate } from "@/util/helpers"; | ||
|
||
type Props = { | ||
oldDwellingsInHousingCompaniesPriceIndex: OldDwellingsInHousingCompaniesPriceIndexProps; | ||
leaseStartDate: string; | ||
}; | ||
|
||
const getLastYearsIndexPointNumber = ( | ||
pointFigures: IndexPointFigureYearlyProps[] | ||
): string => { | ||
const lastYear = new Date().getFullYear() - 1; | ||
const lastYearIndex = | ||
pointFigures?.find( | ||
(x: IndexPointFigureYearlyProps) => x.year == lastYear | ||
) || null; | ||
return lastYearIndex | ||
? `${lastYearIndex.year} * ${lastYearIndex.value}` | ||
: "Indeksipisteluvut puuttuvat"; | ||
}; | ||
|
||
const getReviewDaysSorted = ( | ||
pointFigures: IndexPointFigureYearlyProps[] | ||
): IndexPointFigureYearlyProps[] => { | ||
// deep copy | ||
const sortedNumbers = JSON.parse(JSON.stringify(pointFigures)); | ||
|
||
sortedNumbers.sort( | ||
(a: IndexPointFigureYearlyProps, b: IndexPointFigureYearlyProps) => | ||
a.year - b.year | ||
); | ||
return sortedNumbers; | ||
}; | ||
|
||
class OldDwellingsInHousingCompaniesPriceIndexViewEdit extends PureComponent<Props> { | ||
render() { | ||
const { oldDwellingsInHousingCompaniesPriceIndex, leaseStartDate } = | ||
this.props; | ||
|
||
console.log("oldDwellingsInHousingCompaniesPriceIndex", oldDwellingsInHousingCompaniesPriceIndex); | ||
|
||
if (!oldDwellingsInHousingCompaniesPriceIndex) { | ||
return <p>Lisää tasotarkistus</p>; | ||
} | ||
|
||
const { | ||
name, | ||
point_figures: pointFigures, | ||
source_table_label: sourceTableLabel, | ||
} = oldDwellingsInHousingCompaniesPriceIndex || {}; | ||
return ( | ||
<Fragment> | ||
<BoxItemContainer> | ||
<Row> | ||
<Column> | ||
<FormTextTitle | ||
uiDataKey={getUiDataLeaseKey( | ||
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NAME | ||
)} | ||
> | ||
{ | ||
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.NAME | ||
} | ||
</FormTextTitle> | ||
<FormText>{name}</FormText> | ||
</Column> | ||
<Column> | ||
<FormTextTitle>{LeaseFieldTitles.START_DATE}</FormTextTitle> | ||
<FormText>{formatDate(leaseStartDate)}</FormText> | ||
</Column> | ||
<Column> | ||
<FormTextTitle | ||
uiDataKey={getUiDataLeaseKey( | ||
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS | ||
)} | ||
> | ||
{ | ||
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.NUMBERS | ||
} | ||
</FormTextTitle> | ||
<FormText>{getLastYearsIndexPointNumber(pointFigures)}</FormText> | ||
<FormText>{sourceTableLabel}</FormText> | ||
</Column> | ||
<Column> | ||
<FormTextTitle | ||
uiDataKey={getUiDataLeaseKey( | ||
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS | ||
)} | ||
> | ||
{ | ||
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.REVIEW_DAYS | ||
} | ||
</FormTextTitle> | ||
<> | ||
{pointFigures && !!pointFigures.length | ||
? getReviewDaysSorted(pointFigures).map( | ||
(number: IndexPointFigureYearlyProps, index: number) => { | ||
return ( | ||
<FormText | ||
key={ | ||
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS + | ||
`[${index}]` | ||
} | ||
> | ||
{`1.1.${number.year}`} | ||
</FormText> | ||
); | ||
} | ||
) | ||
: ""} | ||
</> | ||
</Column> | ||
</Row> | ||
</BoxItemContainer> | ||
</Fragment> | ||
); | ||
} | ||
} | ||
|
||
export default flowRight( | ||
withWindowResize, | ||
connect((state) => { | ||
return { | ||
leaseAttributes: getLeaseAttributes(state), | ||
leaseStartDate: getCurrentLeaseStartDate(state), | ||
}; | ||
}) | ||
)(OldDwellingsInHousingCompaniesPriceIndexViewEdit); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.