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

psp-8852 | Fixed tenants without primary contact on save #4198

Merged
merged 3 commits into from
Jul 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const OrganizationView: React.FunctionComponent<OrganizationViewProps> = ({ orga
<Col>
<SectionField
label="Connected to this organization"
labelWidth="3"
labelWidth="auto"
valueTestId="contact-organization-person-list"
tooltip="To unlink a contact from this organization, or edit a contact's information, click on the name and unlink from the individual contact page."
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ exports[`Contact OrganizationView component > renders as expected 1`] = `
class="pb-2 row"
>
<div
class="pr-0 text-left col-3"
class="pr-0 text-left col-auto"
>
<label
class="c3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const UpdateOrganization: React.FC<FormikProps<IEditableOrganizationForm>> = ({
<Section header="Individual Contacts">
<SectionField
label="Connected to this organization"
labelWidth="3"
labelWidth="auto"
tooltip="To unlink a contact from this organization, or edit a contact's information, click on the name and unlink from the individual contact page."
>
{persons &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ exports[`UpdateOrganizationForm > renders as expected 1`] = `
class="pb-2 row"
>
<div
class="pr-0 text-left col-3"
class="pr-0 text-left col-auto"
>
<label
class="c4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const TenantOrganizationContactInfo: React.FunctionComponent<
const { values } = useFormikContext<LeaseFormModel>();
const tenant: FormTenant = getIn(values, nameSpace);
let primaryContact = tenant?.initialPrimaryContact;
if (primaryContact?.id !== tenant?.primaryContactId) {
if (primaryContact?.id !== Number(tenant?.primaryContactId)) {
primaryContact = tenant?.primaryContactId
? getPrimaryContact(tenant?.primaryContactId, tenant) ?? undefined
? getPrimaryContact(Number(tenant?.primaryContactId), tenant) ?? undefined
: undefined;
}
const primaryContactName = formatApiPersonNames(primaryContact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ const getColumns = (tenantTypes: SelectOption[]): ColumnWithProps<FormTenant>[]
minWidth: 150,
width: 120,
Cell: (props: CellProps<FormTenant>) => {
const original = props.row.original;
const tenant = props.row.original;
const persons =
original.original !== undefined && isValidId(props?.row?.original?.organizationId)
? original?.original.organization.organizationPersons?.map(op => op.person)
: original?.organizationPersons?.map(op => op.person);
let primaryContact = original.initialPrimaryContact;
if (original.primaryContactId !== original.initialPrimaryContact?.id) {
primaryContact = original.primaryContactId
? getPrimaryContact(original.primaryContactId, original) ?? undefined
tenant.original !== undefined && isValidId(tenant.organizationId)
? tenant?.original.organization.organizationPersons?.map(op => op.person)
: tenant?.organizationPersons?.map(op => op.person);
let initialPrimaryContact = tenant.initialPrimaryContact;
if (Number(tenant.primaryContactId) !== initialPrimaryContact?.id) {
initialPrimaryContact = tenant.primaryContactId
? getPrimaryContact(Number(tenant.primaryContactId), tenant) ?? undefined
: undefined;
}
const primaryContactOptions: SelectOption[] =
persons?.map(person => ({
label: formatApiPersonNames(person),
value: person?.id ?? 0,
})) ?? [];
if (isValidId(props?.row?.original?.personId)) {
if (isValidId(tenant?.personId)) {
return <p>Not applicable</p>;
} else if (persons?.length && persons?.length > 1) {
return (
Expand All @@ -100,7 +100,7 @@ const getColumns = (tenantTypes: SelectOption[]): ColumnWithProps<FormTenant>[]
} else if (persons?.length === 1) {
return (
<p key={`tenants.primaryContact.${persons[0]?.id ?? props?.row?.index}`}>
{formatApiPersonNames(primaryContact ?? persons[0])}
{formatApiPersonNames(initialPrimaryContact ?? persons[0])}
</p>
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class FormTenant {
public readonly mobile?: string;
public readonly isDisabled?: boolean;
public readonly organizationPersons?: ApiGen_Concepts_PersonOrganization[];
public readonly primaryContactId?: number;
public readonly primaryContactId?: string;
public readonly initialPrimaryContact?: ApiGen_Concepts_Person;
public readonly lessorTypeCode?: ApiGen_Base_CodeType<string>;
public readonly tenantType?: string;
Expand Down Expand Up @@ -95,7 +95,11 @@ export class FormTenant {
organizationId: !isValidId(model.personId) ? model.organizationId ?? null : null,
lessorType: model.lessorTypeCode ?? null,
tenantTypeCode: toTypeCodeNullable(model.tenantType),
primaryContactId: !isValidId(model.personId) ? model.primaryContactId ?? null : null,
primaryContactId: !isValidId(model.personId)
? isValidId(Number(model.primaryContactId))
? Number(model.primaryContactId)
: null
: null,
note: model.note ?? null,
leaseId: model.leaseId ?? 0,
leaseTenantId: null,
Expand Down Expand Up @@ -138,7 +142,7 @@ export class FormTenant {
undefined;
this.lessorTypeCode = apiModel.lessorType ?? undefined;
this.tenantType = fromTypeCode(apiModel.tenantTypeCode) ?? undefined;
this.primaryContactId = apiModel.primaryContactId ?? undefined;
this.primaryContactId = apiModel.primaryContactId?.toString() ?? undefined;
this.initialPrimaryContact = apiModel.primaryContact ?? undefined;
} else if (exists(selectedContactModel)) {
// In this case, construct a tenant using a contact.
Expand All @@ -164,7 +168,7 @@ export class FormTenant {
this.organizationPersons = selectedContactModel?.organization?.organizationPersons ?? [];

const primaryContact = getDefaultContact(selectedContactModel.organization);
this.primaryContactId = primaryContact?.id;
this.primaryContactId = primaryContact?.id.toString();
this.initialPrimaryContact = primaryContact ?? undefined;
}

Expand Down
Loading