Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
NC-jsAhonen committed Dec 10, 2024
1 parent e826b5f commit 7907f7f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,72 +18,83 @@ import {
LeaseFieldTitles,
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths,
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles,
LeaseRentsFieldPaths,
} from "@/leases/enums";
import { getUiDataLeaseKey } from "@/uiData/helpers";
import { formatDate } from "@/util/helpers";
import { formatDate, getFieldAttributes } from "@/util/helpers";
import FormField from "@/components/form/FormField";
import { Attributes } from "@/types";

type Props = {
oldDwellingsInHousingCompaniesPriceIndex: OldDwellingsInHousingCompaniesPriceIndexProps;
leaseAttributes: Attributes;
leaseStartDate: string;
isSaveClicked: boolean;
};

const getLastYearsIndexPointNumber = (
pointFigures: IndexPointFigureYearlyProps[]
pointFigures: IndexPointFigureYearlyProps[],
): string => {
const lastYear = new Date().getFullYear() - 1;
const lastYearIndex =
pointFigures?.find(
(x: IndexPointFigureYearlyProps) => x.year == lastYear
(x: IndexPointFigureYearlyProps) => x.year == lastYear,
) || null;
return lastYearIndex
? `${lastYearIndex.year} * ${lastYearIndex.value}`
: "Indeksipisteluvut puuttuvat";
};

const getReviewDaysSorted = (
pointFigures: IndexPointFigureYearlyProps[]
pointFigures: IndexPointFigureYearlyProps[],
): IndexPointFigureYearlyProps[] => {
// deep copy
const sortedNumbers = JSON.parse(JSON.stringify(pointFigures));

sortedNumbers.sort(
(a: IndexPointFigureYearlyProps, b: IndexPointFigureYearlyProps) =>
a.year - b.year
a.year - b.year,
);
return sortedNumbers;
};

class OldDwellingsInHousingCompaniesPriceIndexViewEdit extends PureComponent<Props> {
render() {
const { oldDwellingsInHousingCompaniesPriceIndex, leaseStartDate } =
this.props;

console.log("oldDwellingsInHousingCompaniesPriceIndex", oldDwellingsInHousingCompaniesPriceIndex);
const {
oldDwellingsInHousingCompaniesPriceIndex,
leaseAttributes,
leaseStartDate,
isSaveClicked,
} = this.props;

if (!oldDwellingsInHousingCompaniesPriceIndex) {
return <p>Lisää tasotarkistus</p>;
return <p>Lisää tasotarkistus</p>;
}

const {
name,
point_figures: pointFigures,
source_table_label: sourceTableLabel,
} = oldDwellingsInHousingCompaniesPriceIndex || {};
console.log("leaseAttributes", leaseAttributes);
return (
<Fragment>
<BoxItemContainer>
<Row>
<Column>
<FormTextTitle
uiDataKey={getUiDataLeaseKey(
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NAME
<FormField
disableTouched={isSaveClicked}
fieldAttributes={getFieldAttributes(
leaseAttributes,
LeaseRentsFieldPaths.OLD_DWELLINGS_IN_HOUSING_COMPANIES_PRICE_INDEX_TYPE,
)}
>
{
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.NAME
}
</FormTextTitle>
<FormText>{name}</FormText>
name="old_dwellings_in_housing_companies_price_index_type"
overrideValues={{
label: LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.TYPE,
type: "choice",
}}
// enableUiDataEdit
// uiDataKey={getUiDataLeaseKey(LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.OLD_DWELLINGS_IN_HOUSING_COMPANIES_PRICE_INDEX_TYPE)}
/>
</Column>
<Column>
<FormTextTitle>{LeaseFieldTitles.START_DATE}</FormTextTitle>
Expand All @@ -92,7 +103,7 @@ class OldDwellingsInHousingCompaniesPriceIndexViewEdit extends PureComponent<Pro
<Column>
<FormTextTitle
uiDataKey={getUiDataLeaseKey(
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS,
)}
>
{
Expand All @@ -105,7 +116,7 @@ class OldDwellingsInHousingCompaniesPriceIndexViewEdit extends PureComponent<Pro
<Column>
<FormTextTitle
uiDataKey={getUiDataLeaseKey(
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS
LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS,
)}
>
{
Expand All @@ -126,7 +137,7 @@ class OldDwellingsInHousingCompaniesPriceIndexViewEdit extends PureComponent<Pro
{`1.1.${number.year}`}
</FormText>
);
}
},
)
: ""}
</>
Expand All @@ -145,5 +156,5 @@ export default flowRight(
leaseAttributes: getLeaseAttributes(state),
leaseStartDate: getCurrentLeaseStartDate(state),
};
})
}),
)(OldDwellingsInHousingCompaniesPriceIndexViewEdit);
4 changes: 3 additions & 1 deletion src/leases/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ export const LeaseRentsFieldPaths = {
Y_VALUE_START: 'rents.child.children.y_value_start',
OVERRIDE_RECEIVABLE_TYPE: 'rents.child.children.override_receivable_type',
OLD_DWELLINGS_IN_HOUSING_COMPANIES_PRICE_INDEX: 'rents.child.children.old_dwellings_in_housing_companies_price_index',
OLD_DWELLINGS_IN_HOUSING_COMPANIES_PRICE_INDEX_TYPE: 'rents.child.children.old_dwellings_in_housing_companies_price_index_type',
};

/**
Expand Down Expand Up @@ -931,6 +932,7 @@ export const LeaseRentDueDatesFieldTitles = {
*/
export const LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths = {
OLD_DWELLINGS_IN_HOUSING_COMPANIES_PRICE_INDEX: 'rents.child.children.old_dwellings_in_housing_companies_price_index',
OLD_DWELLINGS_IN_HOUSING_COMPANIES_PRICE_INDEX_TYPE: 'rents.child.children.old_dwellings_in_housing_companies_price_index_type',
NAME: 'rents.child.children.old_dwellings_in_housing_companies_price_index.name',
NUMBERS: 'rents.child.children.old_dwellings_in_housing_companies_price_index.numbers',
};
Expand All @@ -942,7 +944,7 @@ export const LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths = {
*/
export const LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles = {
OLD_DWELLINGS_IN_HOUSING_COMPANIES_PRICE_INDEX: 'Tasotarkistus',
NAME: 'Tyyppi',
TYPE: 'Tyyppi',
NUMBERS: 'Indeksipisteluku',
REVIEW_DAYS: 'Tarkistuspäivät',
};
Expand Down

0 comments on commit 7907f7f

Please sign in to comment.