Skip to content
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 @@ -161,13 +161,15 @@ interface AddressSearchProps {
registerField?: RegisterFieldCallback;
onFoundAddress?: (address: LocationQuery | null) => void;
onFoundLocations?: (locations: FormattedLocation[] | null | undefined) => void;
onLoadingLocations?: (isLoading: boolean) => void;
onError?: (error: Error | null) => void;
}

function AddressSearch({
registerField = () => undefined,
onFoundAddress = () => undefined,
onFoundLocations = () => undefined,
onLoadingLocations = () => undefined,
onError = () => undefined,
}: AddressSearchProps) {
const { t } = useI18n();
Expand All @@ -189,6 +191,7 @@ function AddressSearch({

useEffect(() => {
spinnerButtonRef.current?.toggleSpinner(isLoading);
onLoadingLocations(isLoading);
}, [isLoading]);

useEffect(() => {
Expand All @@ -204,7 +207,6 @@ function AddressSearch({
const handleSearch = useCallback(
(event) => {
onError(null);
onFoundAddress(null);
onSearch(event, textInput);
},
[textInput],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,25 @@ describe('InPersonLocationStep', () => {
});
expect(results).not.to.exist();
});

it('clicking search again after first results do not clear results', async () => {
const { findByText, findByLabelText } = render(
<InPersonContext.Provider value={{ arcgisSearchEnabled: true }}>
<InPersonLocationPostOfficeSearchStep {...DEFAULT_PROPS} />
</InPersonContext.Provider>,
);

await userEvent.type(
await findByLabelText('in_person_proofing.body.location.po_search.address_search_label'),
'800 main',
);
await userEvent.click(
await findByText('in_person_proofing.body.location.po_search.search_button'),
);
await userEvent.click(
await findByText('in_person_proofing.body.location.po_search.search_button'),
);
await findByText('in_person_proofing.body.location.po_search.results_description');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import InPersonLocations, { FormattedLocation } from './in-person-locations';
function InPersonLocationPostOfficeSearchStep({ onChange, toPreviousStep, registerField }) {
const { t } = useI18n();
const [inProgress, setInProgress] = useState(false);
const [isLoadingLocations, setLoadingLocations] = useState(false);
const [autoSubmit, setAutoSubmit] = useState(false);
const { setSubmitEventMetadata } = useContext(AnalyticsContext);
const [locationResults, setLocationResults] = useState<FormattedLocation[] | null | undefined>(
Expand Down Expand Up @@ -89,9 +90,10 @@ function InPersonLocationPostOfficeSearchStep({ onChange, toPreviousStep, regist
registerField={registerField}
onFoundAddress={setFoundAddress}
onFoundLocations={setLocationResults}
onLoadingLocations={setLoadingLocations}
onError={setUspsError}
/>
{locationResults && foundAddress && (
{locationResults && foundAddress && !isLoadingLocations && (
Copy link
Copy Markdown
Contributor Author

@allthesignals allthesignals Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a sign that <InPersonLocations/> needs to be rendered from within <AddressSearch/>? Then we can remove so much context from this component and only require a callback for handleLocationSelect...

<InPersonLocations
locations={locationResults}
onSelect={handleLocationSelect}
Expand Down