-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PSP-5492 Update Historical # and Type on Property Details (Property A…
…ttributes) (#4016) * Update frontend service calls to API * Add new type code dropdown * Update historical numbers - frontend * Save the list of historical file numbers * Clear associated fields when historical file number type is changed * Controller, service and repository changes for updating historical numbers * Test updates * Update form validation rules * Test corrections * Fix merge conflicts * Lint fixes * CR feedback * Fix model mappings * Fix lookup table key
- Loading branch information
Showing
22 changed files
with
503 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...atures/mapSideBar/property/tabs/propertyDetails/update/UpdateHistoricalNumbersSubForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { FieldArray, useFormikContext } from 'formik'; | ||
import React from 'react'; | ||
import { Col, Row } from 'react-bootstrap'; | ||
|
||
import { LinkButton, RemoveButton } from '@/components/common/buttons'; | ||
import { Input, Select } from '@/components/common/form'; | ||
import { SectionField } from '@/components/common/Section/SectionField'; | ||
import * as API from '@/constants/API'; | ||
import useLookupCodeHelpers from '@/hooks/useLookupCodeHelpers'; | ||
import { exists } from '@/utils'; | ||
|
||
import { HistoricalNumberForm, UpdatePropertyDetailsFormModel } from './models'; | ||
|
||
export interface IUpdateHistoricalNumbersSubFormProps { | ||
propertyId: number; | ||
} | ||
|
||
export const UpdateHistoricalNumbersSubForm: React.FC<IUpdateHistoricalNumbersSubFormProps> = ({ | ||
propertyId, | ||
}) => { | ||
const { values, setFieldValue } = useFormikContext<UpdatePropertyDetailsFormModel>(); | ||
const { getOptionsByType } = useLookupCodeHelpers(); | ||
|
||
// (sort alpha; exceptions: 1. Other at end, and 2. PS second in list) | ||
// The order is set via displayOrder in the DB | ||
const historicalNumberTypes = getOptionsByType(API.HISTORICAL_NUMBER_TYPES); | ||
|
||
return ( | ||
<FieldArray | ||
name="historicalNumbers" | ||
render={arrayHelpers => ( | ||
<> | ||
{values.historicalNumbers?.map((hn, index) => ( | ||
<React.Fragment key={`property-historical-${index}`}> | ||
<Row className="py-3" data-testid={`historical-number-row-${index}`}> | ||
<Col xs="auto" xl="5"> | ||
<Input field={`historicalNumbers.${index}.historicalNumber`} /> | ||
</Col> | ||
<Col xs="auto" xl="5" className="pl-0"> | ||
<Select | ||
data-testid={`select-historical-type-${index}`} | ||
placeholder="Select type..." | ||
field={`historicalNumbers.${index}.historicalNumberType`} | ||
options={historicalNumberTypes} | ||
value={hn.historicalNumberType} | ||
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => { | ||
const selected = e?.target?.value; | ||
if (exists(selected) && selected !== 'OTHER') { | ||
// clear associated field when historical file # type changes | ||
setFieldValue(`historicalNumbers.${index}.otherHistoricalNumberType`, ''); | ||
} | ||
}} | ||
/> | ||
</Col> | ||
<Col xs="auto" xl="2" className="pl-0"> | ||
<RemoveButton | ||
dataTestId={`historical-number-remove-button-${index}`} | ||
onRemove={() => { | ||
arrayHelpers.remove(index); | ||
}} | ||
/> | ||
</Col> | ||
</Row> | ||
{values.historicalNumbers[index]?.historicalNumberType === 'OTHER' && ( | ||
<SectionField label="Describe other" required> | ||
<Input field={`historicalNumbers.${index}.otherHistoricalNumberType`} required /> | ||
</SectionField> | ||
)} | ||
</React.Fragment> | ||
))} | ||
<LinkButton | ||
data-testid="add-historical-number" | ||
onClick={() => { | ||
const hn = new HistoricalNumberForm(); | ||
hn.propertyId = propertyId; | ||
arrayHelpers.push(hn); | ||
}} | ||
> | ||
+ Add historical file # | ||
</LinkButton> | ||
</> | ||
)} | ||
/> | ||
); | ||
}; | ||
|
||
export default UpdateHistoricalNumbersSubForm; |
Oops, something went wrong.