diff --git a/src/contacts/components/ContactReadonly.tsx b/src/contacts/components/ContactReadonly.tsx index 2dd54f88..d8dc908d 100644 --- a/src/contacts/components/ContactReadonly.tsx +++ b/src/contacts/components/ContactReadonly.tsx @@ -1,7 +1,7 @@ import React from "react"; import ContactTemplate from "@/contacts/components/templates/ContactTemplate"; import GreenBox from "@/components/content/GreenBox"; -import type { Contact } from "@/types"; +import type { Contact } from "@/contacts/types"; type Props = { contact: Contact; }; diff --git a/src/contacts/components/ContactsListPage.tsx b/src/contacts/components/ContactsListPage.tsx index d32853fa..9e30bf6c 100644 --- a/src/contacts/components/ContactsListPage.tsx +++ b/src/contacts/components/ContactsListPage.tsx @@ -27,7 +27,7 @@ import { getRouteById, Routes } from "@/root/routes"; import { getContactList, getIsFetching } from "@/contacts/selectors"; import { withContactAttributes } from "@/components/attributes/ContactAttributes"; import { getUserActiveServiceUnit } from "@/usersPermissions/selectors"; -import type { ContactList } from "@/contacts/types"; +import type { ContactList, ContactRow, ContactsActiveLease } from "@/contacts/types"; import type { Attributes, Methods as MethodsType } from "types"; import type { RootState } from "@/root/types"; import type { UserServiceUnit } from "@/usersPermissions/types"; @@ -346,6 +346,15 @@ class ContactListPage extends Component { }); } + if (isFieldAllowedToRead(contactAttributes, ContactFieldPaths.ACTIVE_LEASES)) { + columns.push({ + key: 'contacts_active_leases', + text: ContactFieldTitles.ACTIVE_LEASES, + renderer: (_val: ContactsActiveLease, row: ContactRow) => (row.contacts_active_leases || []).map((activeLease) => activeLease.lease_identifier).join(', ') || '', + sortable: false + }); + } + return columns; }; handleSortingChange = ({ diff --git a/src/contacts/components/forms/ContactForm.tsx b/src/contacts/components/forms/ContactForm.tsx index 451f6d9f..8a9c7a5f 100644 --- a/src/contacts/components/forms/ContactForm.tsx +++ b/src/contacts/components/forms/ContactForm.tsx @@ -24,6 +24,7 @@ import { getUserActiveServiceUnit } from "@/usersPermissions/selectors"; import type { Attributes } from "types"; import type { RootState } from "@/root/types"; import type { UserServiceUnit } from "@/usersPermissions/types"; +import { ContactsActiveLease } from "@/contacts/types"; type Props = { attributes: Attributes; change: (...args: Array) => any; @@ -302,6 +303,20 @@ class ContactForm extends Component { + + + + <> + + {ContactFieldTitles.ACTIVE_LEASES} + + + {(initialValues.contacts_active_leases || []).map((val: ContactsActiveLease) => val.lease_identifier).join(', ') || '-'} + + + + + ; diff --git a/src/contacts/components/templates/ContactTemplate.tsx b/src/contacts/components/templates/ContactTemplate.tsx index 54ec91d2..cdce2617 100644 --- a/src/contacts/components/templates/ContactTemplate.tsx +++ b/src/contacts/components/templates/ContactTemplate.tsx @@ -13,6 +13,7 @@ import { getFieldOptions, getLabelOfOption, isFieldAllowedToRead } from "@/util/ import { getAttributes } from "@/contacts/selectors"; import { ContactTypes } from "@/contacts/enums"; import type { Attributes } from "types"; +import { ContactsActiveLease } from "@/contacts/types"; type Props = { attributes: Attributes; contact: Record | null | undefined; @@ -264,6 +265,18 @@ const ContactTemplate = ({ + + + + <> + + {ContactFieldTitles.ACTIVE_LEASES} + + {(contact.contacts_active_leases || []).map((val: ContactsActiveLease) => val.lease_identifier).join(', ') || '-'} + + + + ; }; diff --git a/src/contacts/enums.ts b/src/contacts/enums.ts index f1ed26fd..0f1805d5 100644 --- a/src/contacts/enums.ts +++ b/src/contacts/enums.ts @@ -17,6 +17,7 @@ export const ContactTypes = { * @enum {string} */ export const ContactFieldPaths = { + ACTIVE_LEASES: 'contacts_active_leases', ADDRESS: 'address', ADDRESS_PROTECTION: 'address_protection', AUDIT_LOG: 'audit_log', @@ -51,6 +52,7 @@ export const ContactFieldPaths = { * @enum {string} */ export const ContactFieldTitles = { + ACTIVE_LEASES: 'Vuokraukset', ADDRESS: 'Katuosoite', ADDRESS_PROTECTION: 'Turvakielto', AUDIT_LOG: 'Muutoshistoria', diff --git a/src/contacts/types.ts b/src/contacts/types.ts index 05d23041..04f7f085 100644 --- a/src/contacts/types.ts +++ b/src/contacts/types.ts @@ -41,4 +41,11 @@ export type HideEditModeAction = Action; export type ShowEditModeAction = Action; export type HideContactModalAction = Action; export type ShowContactModalAction = Action; -export type ReceiveContactModalSettingsAction = Action; \ No newline at end of file +export type ReceiveContactModalSettingsAction = Action; +export type ContactsActiveLease = { + lease_id: number; + lease_identifier: string; +} +export type ContactRow = { + contacts_active_leases?: Array; +}