From e4e37aef92168b75c5724ade499c082e9de6cb4b Mon Sep 17 00:00:00 2001 From: indigane Date: Fri, 28 Feb 2025 14:02:18 +0200 Subject: [PATCH] Add legacy_release_date as an editable field for housing company --- .../tests/apis/test_api_housing_company.py | 1 + backend/hitas/views/housing_company.py | 1 + backend/openapi.yaml | 5 ++++ frontend/src/common/schemas/housingCompany.ts | 2 ++ .../HousingCompanyCreatePage.tsx | 29 +++++++++++++++++-- .../components/_HousingCompanyPage.sass | 5 ++++ 6 files changed, 41 insertions(+), 2 deletions(-) diff --git a/backend/hitas/tests/apis/test_api_housing_company.py b/backend/hitas/tests/apis/test_api_housing_company.py index a42e9ecbe..96790755e 100644 --- a/backend/hitas/tests/apis/test_api_housing_company.py +++ b/backend/hitas/tests/apis/test_api_housing_company.py @@ -371,6 +371,7 @@ def test__api__housing_company__retrieve(api_client: HitasAPIClient, apt_with_nu "notes": hc1.notes, "archive_id": hc1.id, "release_date": hc1.legacy_release_date, + "legacy_release_date": hc1.legacy_release_date, "last_modified": { "datetime": log.timestamp.isoformat().replace("+00:00", "Z"), "user": { diff --git a/backend/hitas/views/housing_company.py b/backend/hitas/views/housing_company.py index 01442ee5d..87b76ca39 100644 --- a/backend/hitas/views/housing_company.py +++ b/backend/hitas/views/housing_company.py @@ -356,6 +356,7 @@ class Meta: "notes", "archive_id", "release_date", + "legacy_release_date", "last_modified", "summary", "improvements", diff --git a/backend/openapi.yaml b/backend/openapi.yaml index d2d2011b3..0b5527297 100644 --- a/backend/openapi.yaml +++ b/backend/openapi.yaml @@ -5769,6 +5769,11 @@ components: format: date nullable: true readOnly: true + legacy_release_date: + description: Regulation release date for legacy housing companies. Overrides release_date. + type: string + format: date + nullable: true archive_id: description: Archive ID for this housing company type: integer diff --git a/frontend/src/common/schemas/housingCompany.ts b/frontend/src/common/schemas/housingCompany.ts index 4daf2e4a4..cfc712371 100644 --- a/frontend/src/common/schemas/housingCompany.ts +++ b/frontend/src/common/schemas/housingCompany.ts @@ -112,6 +112,7 @@ export const HousingCompanyDetailsSchema = object({ notes: string().nullable(), archive_id: number(), release_date: string().nullable(), + legacy_release_date: string().nullable(), last_modified: object({ user: object({ user: string().nullable(), @@ -140,6 +141,7 @@ export const HousingCompanyWritableSchema = HousingCompanyDetailsSchema.pick({ hitas_type: true, exclude_from_statistics: true, regulation_status: true, + legacy_release_date: true, address: true, acquisition_price: true, primary_loan: true, diff --git a/frontend/src/features/housingCompany/HousingCompanyCreatePage.tsx b/frontend/src/features/housingCompany/HousingCompanyCreatePage.tsx index bcb1d6a2e..d00345e4d 100644 --- a/frontend/src/features/housingCompany/HousingCompanyCreatePage.tsx +++ b/frontend/src/features/housingCompany/HousingCompanyCreatePage.tsx @@ -1,6 +1,6 @@ import React, {useContext, useRef, useState} from "react"; -import {Fieldset, IconQuestionCircle} from "hds-react"; +import {Fieldset, IconQuestionCircle, TextInput as HDSTextInput} from "hds-react"; import {useNavigate} from "react-router-dom"; import {zodResolver} from "@hookform/resolvers/zod"; @@ -35,7 +35,7 @@ import { useGetPropertyManagersQuery, useSaveHousingCompanyMutation, } from "../../common/services"; -import {hdsToast, setAPIErrorsForFormFields, validateBusinessId} from "../../common/utils"; +import {formatDate, hdsToast, setAPIErrorsForFormFields, validateBusinessId} from "../../common/utils"; import { HousingCompanyViewContext, HousingCompanyViewContextProvider, @@ -63,6 +63,7 @@ const getInitialFormData = (housingCompany): IHousingCompanyWritable => { hitas_type: "new_hitas_1", exclude_from_statistics: false, regulation_status: "regulated", + legacy_release_date: null, building_type: {id: ""}, business_id: "", developer: {id: ""}, @@ -137,6 +138,17 @@ const LoadedHousingCompanyCreatePage = (): React.JSX.Element => { }); }; + const getReleaseDateDisplay = (housingCompany?: IHousingCompanyDetails) => { + if (housingCompany) { + if (housingCompany.legacy_release_date) { + return "Vapautumispäivä korvattu"; + } else if (housingCompany.release_date) { + return formatDate(housingCompany.release_date); + } + } + return "Ei vapautumispäivää"; + }; + return ( <> { required /> +
+ + +