Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Apr 16, 2024
1 parent 252f1fb commit 45eb2a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ interface PickOSAddressProps {
setShowPostcodeError: React.Dispatch<React.SetStateAction<boolean>>;
initialSelectedAddress?: Option;
showAddressSelectError: boolean;
setShowAddressSelectError: React.Dispatch<React.SetStateAction<boolean>>;
id?: string;
description?: string;
}
Expand Down Expand Up @@ -55,7 +54,7 @@ export default function PickOSAddress(props: PickOSAddressProps): FCReturn {
);
const [sanitizedPostcode, setSanitizedPostcode] = useState<string | null>(
(props.initialPostcode && toNormalised(props.initialPostcode.trim())) ??
null,
null,
);
const [selectedOption, setSelectedOption] = useState<Option | undefined>(
props.initialSelectedAddress ?? undefined,
Expand Down Expand Up @@ -187,7 +186,7 @@ export default function PickOSAddress(props: PickOSAddressProps): FCReturn {
/>
</InputLabel>
{sanitizedPostcode && (
<ErrorWrapperRoot error={props.showAddressSelectError ? "Select an address to continue" : undefined} role="alert" data-testid="autocomplete-error-wrapper">
<ErrorWrapperRoot error={!selectedOption && props.showAddressSelectError ? "Select an address to continue" : undefined} role="alert" data-testid="autocomplete-error-wrapper">
{/* @ts-ignore */
<address-autocomplete
id="address-autocomplete"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ function Component(props: Props) {
previouslySubmittedData?._address
}
showAddressSelectError={showAddressSelectError}
setShowAddressSelectError={setShowAddressSelectError}
id={props.id}
description={props.description || ""}
/>
Expand Down Expand Up @@ -214,12 +213,12 @@ function Component(props: Props) {
handleSubmit={() => {
// Handle validation (eventually formalise with yup schema?)
if (page === "os-address") {
if (!address?.postcode) {
setShowPostcodeError(true);
return;
} else if (!address?.title) {
if (showPostcodeError && !address) {
setShowAddressSelectError(true);
return;
} else if (!address) {
setShowPostcodeError(true);
return;
} else if (!localAuthorityDistricts) {
setShowDataFetchingError(true);
return;
Expand Down

0 comments on commit 45eb2a5

Please sign in to comment.