Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add legacy_release_date as an editable field for housing company #530

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/hitas/tests/apis/test_api_housing_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions backend/hitas/views/housing_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ class Meta:
"notes",
"archive_id",
"release_date",
"legacy_release_date",
"last_modified",
"summary",
"improvements",
Expand Down
5 changes: 5 additions & 0 deletions backend/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/common/schemas/housingCompany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 27 additions & 2 deletions frontend/src/features/housingCompany/HousingCompanyCreatePage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: ""},
Expand Down Expand Up @@ -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 (
<>
<FormProviderForm
Expand Down Expand Up @@ -207,6 +219,19 @@ const LoadedHousingCompanyCreatePage = (): React.JSX.Element => {
required
/>
</div>
<div className="row">
<HDSTextInput
id="release_date"
label="Laskennallinen vapautumispäivä"
readOnly={true}
defaultValue={getReleaseDateDisplay(housingCompany)}
/>
<DateInput
label="Korvaava vapautumispäivä"
tooltipText="Tällä kentällä voi korvata automaattisesti lasketun vapautumispäivän. Oletuksena kentän voi jättää tyhjäksi."
name="legacy_release_date"
/>
</div>
<div className="row">
<CheckboxInput
label="Ei-tilastoihin"
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/styles/components/_HousingCompanyPage.sass
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,8 @@

[class^="StatusLabel"]
background-color: var(--color-engel-light)

#release_date[readonly]
padding: 0 var(--spacing-s)
background-color: var(--input-background-default)
cursor: default