Skip to content

Commit

Permalink
Merge pull request #899 from betagouv/supprimer_villes_test_page_reseau
Browse files Browse the repository at this point in the history
Test d'adresse uniquement sur la fiche réseau, pas de villes
  • Loading branch information
totakoko authored Oct 17, 2024
2 parents 30fa918 + da171b1 commit 4f3b30d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/Network/EligibilityTestBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const EligibilityTestBox = ({ networkId }: EligibilityTestBoxProps) => {
Testez l'éligibilité d'une adresse pour ce réseau.
</Text>

<AddressAutocomplete placeholder="Tapez ici votre adresse" onAddressSelected={onAddressSelected} />
<AddressAutocomplete placeholder="Tapez ici votre adresse" onAddressSelected={onAddressSelected} excludeCities />

<Box display="flex" alignItems="center" justifyContent="end">
{formState === 'eligibilitySubmissionError' && (
Expand Down
3 changes: 3 additions & 0 deletions src/components/addressAutocomplete/AddressAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type AddressProps = {
popoverClassName?: string;
onAddressSelected: (address: string, geoAddress?: SuggestionItem) => any;
onChange?: (e: string) => void;
excludeCities?: boolean;
};

const findAddressInSuggestions = (address: string, suggestions: SuggestionItem[]): SuggestionItem | undefined => {
Expand All @@ -41,6 +42,7 @@ const AddressAutocomplete = ({
centred,
onAddressSelected,
onChange,
excludeCities = false,
}: AddressProps) => {
const router = useRouter();
const [address, setAddress] = useState('');
Expand All @@ -50,6 +52,7 @@ const AddressAutocomplete = ({
debounceTime,
limit: 5,
minCharactersLength,
excludeCities,
});

const handleSelect = useCallback(
Expand Down
10 changes: 7 additions & 3 deletions src/components/addressAutocomplete/useSuggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ enum Status {
Error = 'error',
}
type ValueOf<Obj> = Obj[keyof Obj];
type configProps = {
type UseSuggestionsProps = {
limit?: number;
autocomplete?: boolean;
debounceTime?: number;
minCharactersLength?: number;
excludeCities?: boolean;
};

const useSuggestions = ({ limit = 5, debounceTime = 300, minCharactersLength = 3 }: configProps) => {
const useSuggestions = ({ limit = 5, debounceTime = 300, minCharactersLength = 3, excludeCities }: UseSuggestionsProps) => {
const [suggestions, setSuggestions] = useState<SuggestionItem[]>([]);
const [status, setStatus] = useState<ValueOf<Status>>(Status.Idle);
const isMounted = useIsMounted();
Expand All @@ -36,7 +37,10 @@ const useSuggestions = ({ limit = 5, debounceTime = 300, minCharactersLength = 3
limit: limit.toString(),
});

setSuggestions(fetchedSuggestions.features);
const features = excludeCities
? fetchedSuggestions.features.filter((feature) => feature.properties.type !== 'municipality')
: fetchedSuggestions.features;
setSuggestions(features);
setStatus(Status.Success);
} catch (e) {
setStatus(Status.Error);
Expand Down
2 changes: 1 addition & 1 deletion src/types/Suggestions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface SuggestionItem {
score: number;
housenumber: string;
id: string;
type: string;
type: 'housenumber' | 'street' | 'locality' | 'municipality';
name: string;
postcode: string;
citycode: string;
Expand Down

0 comments on commit 4f3b30d

Please sign in to comment.