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

PIMS 1604/1597/1620/1601 - Bug Fixes #2344

Merged
merged 13 commits into from
Apr 24, 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
8 changes: 4 additions & 4 deletions express-api/src/services/parcels/parcelServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const parcelRepo = AppDataSource.getRepository(Parcel);
* @throws ErrorWithCode If the parcel already exists or is unable to be added.
*/
const addParcel = async (parcel: DeepPartial<Parcel>) => {
const inPID = Number(parcel.PID);
const numberPID = Number(parcel.PID);

const matchPID = inPID.toString().search(/^\d{9}$/);
if (parcel.PID != null && matchPID === -1) {
const stringPID = numberPID.toString();
if (parcel.PID != null && (stringPID.length > 9 || isNaN(numberPID))) {
throw new ErrorWithCode('PID must be a number and in the format #########');
}

const existingParcel = parcel.PID != null ? await getParcelByPid(inPID) : undefined;
const existingParcel = parcel.PID != null ? await getParcelByPid(numberPID) : undefined;

if (existingParcel) {
throw new ErrorWithCode('Parcel already exists.', 409);
Expand Down
3 changes: 2 additions & 1 deletion react-app/src/components/property/PropertyDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from './PropertyDialog';
import { PropertyType } from './PropertyForms';
import MetresSquared from '@/components/text/MetresSquared';
import { zeroPadPID } from '@/utilities/formatters';

interface IPropertyDetail {
onClose: () => void;
Expand Down Expand Up @@ -150,7 +151,7 @@ const PropertyDetail = (props: IPropertyDetail) => {
} else {
const info: any = {
Classification: data.Classification,
PID: data.PID,
PID: data.PID ? zeroPadPID(data.PID) : undefined,
PIN: data.PIN,
PostalCode: data.Postal,
AdministrativeArea: data.AdministrativeArea?.Name,
Expand Down
15 changes: 9 additions & 6 deletions react-app/src/components/property/PropertyDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
PropertyType,
NetBookValue,
} from './PropertyForms';
import { parseFloatOrNull, parseIntOrNull } from '@/utilities/formatters';
import { parseFloatOrNull, parseIntOrNull, zeroPadPID } from '@/utilities/formatters';

interface IParcelInformationEditDialog {
initialValues: Parcel;
Expand Down Expand Up @@ -59,8 +59,8 @@ export const ParcelInformationEditDialog = (props: IParcelInformationEditDialog)
infoFormMethods.reset({
NotOwned: initialValues?.NotOwned,
Address1: initialValues?.Address1,
PID: initialValues?.PID ? zeroPadPID(initialValues.PID) : '',
PIN: String(initialValues?.PIN ?? ''),
PID: String(initialValues?.PID ?? ''),
Postal: initialValues?.Postal,
AdministrativeAreaId: initialValues?.AdministrativeAreaId,
LandArea: String(initialValues?.LandArea ?? ''),
Expand Down Expand Up @@ -155,7 +155,7 @@ export const BuildingInformationEditDialog = (props: IBuildingInformationEditDia
TotalArea: '',
RentableArea: '',
BuildingTenancy: '',
BuildingTenancyUpdatedOn: dayjs(),
BuildingTenancyUpdatedOn: null,
Location: null,
},
});
Expand All @@ -164,7 +164,7 @@ export const BuildingInformationEditDialog = (props: IBuildingInformationEditDia
infoFormMethods.reset({
Address1: initialValues?.Address1,
PIN: String(initialValues?.PIN ?? ''),
PID: String(initialValues?.PID ?? ''),
PID: initialValues?.PID ? zeroPadPID(initialValues.PID) : '',
Postal: initialValues?.Postal,
AdministrativeAreaId: initialValues?.AdministrativeAreaId,
IsSensitive: initialValues?.IsSensitive,
Expand All @@ -176,7 +176,9 @@ export const BuildingInformationEditDialog = (props: IBuildingInformationEditDia
TotalArea: String(initialValues?.TotalArea ?? ''),
RentableArea: String(initialValues?.RentableArea ?? ''),
BuildingTenancy: initialValues?.BuildingTenancy,
BuildingTenancyUpdatedOn: dayjs(initialValues?.BuildingTenancyUpdatedOn),
BuildingTenancyUpdatedOn: initialValues?.BuildingTenancyUpdatedOn
? dayjs(initialValues?.BuildingTenancyUpdatedOn)
: null,
Location: initialValues?.Location,
});
}, [initialValues]);
Expand All @@ -193,7 +195,8 @@ export const BuildingInformationEditDialog = (props: IBuildingInformationEditDia
formValues.PIN = parseIntOrNull(formValues.PIN);
formValues.TotalArea = parseFloatOrNull(formValues.TotalArea);
formValues.RentableArea = parseFloatOrNull(formValues.RentableArea);
formValues.BuildingTenancyUpdatedOn = formValues.BuildingTenancyUpdatedOn.toDate();
formValues.BuildingTenancyUpdatedOn =
formValues.BuildingTenancyUpdatedOn?.toDate() ?? null;
api.buildings.updateBuildingById(initialValues.Id, formValues).then(() => postSubmit());
}
}}
Expand Down
26 changes: 15 additions & 11 deletions react-app/src/components/property/PropertyForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@ export const GeneralInformationForm = (props: IGeneralInformationForm) => {
}}
rules={{
validate: (val, formVals) =>
(val.length <= 9 &&
(val.length > 0 || formVals['PIN'].length > 0 || propertyType === 'Building')) ||
'Must have set either PID or PIN',
(String(val).length <= 9 &&
(String(val).length > 0 ||
String(formVals['PIN']).length > 0 ||
propertyType === 'Building')) ||
'Must have set either PID or PIN not exceeding 9 digits.',
}}
/>
</Grid>
Expand All @@ -211,9 +213,11 @@ export const GeneralInformationForm = (props: IGeneralInformationForm) => {
}}
rules={{
validate: (val, formVals) =>
(val.length <= 9 &&
(val.length > 0 || formVals['PID'].length > 0 || propertyType === 'Building')) ||
'Must have set either PID or PIN',
(String(val).length <= 9 &&
(String(val).length > 0 ||
String(formVals['PID']).length > 0 ||
propertyType === 'Building')) ||
'Must have set either PID or PIN not exceeding 9 digits.',
}}
/>
</Grid>
Expand Down Expand Up @@ -400,15 +404,15 @@ export const BuildingInformationForm = (props: IBuildingInformationForm) => {
<Grid item xs={6}>
<TextFormField
name={`RentableArea`}
rules={{
validate: (val, formVals) =>
val <= formVals.TotalArea ||
`Cannot be larger than Total area: ${val} <= ${formVals?.TotalArea}`,
}}
required
label={'Net usable area'}
fullWidth
numeric
rules={{
validate: (val, formVals) =>
val <= formVals.TotalArea ||
`Cannot be larger than Total Area: ${val} <= ${formVals?.TotalArea}`,
}}
InputProps={{
endAdornment: (
<InputAdornment position="end">
Expand Down
8 changes: 5 additions & 3 deletions react-app/src/components/property/PropertyTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,23 @@ const PropertyTable = (props: IPropertyTable) => {
);
},
renderCell: (params) => {
const classificationName = classifications?.find((cl) => cl.Id === params.value)?.Name;
//const classificationName = classifications?.find((cl) => cl.Id === params.value)?.Name;
return (
<ClassificationInline
color={classification[params.row.ClassificationId].textColor}
backgroundColor={classification[params.row.ClassificationId].bgColor}
title={classificationName ?? ''}
title={params.value}
/>
);
},
valueGetter: (_value, row) =>
classifications?.find((cl) => cl.Id === row.ClassificationId)?.Name ?? '',
},
{
field: 'PID',
headerName: 'PID',
flex: 1,
valueFormatter: (value: number | null) => value ?? 'N/A',
valueGetter: (value: number | null) => (value ? String(value).padStart(9, '0') : 'N/A'),
},
{
field: 'AgencyId',
Expand Down
14 changes: 12 additions & 2 deletions react-app/src/utilities/formatters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,20 @@ export const formatMoney = (value?: number | ''): string => {
return formatter.format(value || 0);
};

export const parseIntOrNull = (int: string) => {
export const parseIntOrNull = (int: string | number) => {
if (typeof int === 'number') {
return int;
}
return int.length > 0 ? parseInt(int) : null;
};

export const parseFloatOrNull = (flt: string) => {
export const parseFloatOrNull = (flt: string | number) => {
if (typeof flt === 'number') {
return flt;
}
return flt.length > 0 ? parseFloat(flt) : null;
};

export const zeroPadPID = (pid: number | string): string => {
return String(pid).padStart(9, '0');
};
Loading