generated from cfpb/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contact): states and territories now come from a fetched endpoint
- Loading branch information
1 parent
0c45b51
commit 17eb4ab
Showing
4 changed files
with
74 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { request } from 'api/axiosService'; | ||
import type { SblAuthProperties } from 'api/useSblAuth'; | ||
import type { StateFetchedType } from 'types/filingTypes'; | ||
|
||
export const fetchAddressStates = async ( | ||
auth: SblAuthProperties, | ||
): Promise<NonNullable<StateFetchedType[]>> => { | ||
return request<undefined, NonNullable<StateFetchedType[]>>({ | ||
url: `/v1/institutions/address-states`, | ||
method: 'get', | ||
headers: { Authorization: `Bearer ${auth.user?.access_token}` }, | ||
}); | ||
}; | ||
|
||
export default fetchAddressStates; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { UseQueryResult } from '@tanstack/react-query'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import fetchAddressStates from 'api/requests/fetchAddressStates'; | ||
import useSblAuth from 'api/useSblAuth'; | ||
import type { StateFetchedType } from 'types/filingTypes'; | ||
import type { FinancialInstitutionRS } from 'types/formTypes'; | ||
|
||
const formatLabelValue = ( | ||
fetchedAddressStates: StateFetchedType[], | ||
): FinancialInstitutionRS[] => | ||
fetchedAddressStates.map(object => ({ | ||
label: object.name, | ||
value: object.code, | ||
})); | ||
|
||
const useAddressStates = (): UseQueryResult<FinancialInstitutionRS[]> => { | ||
const auth = useSblAuth(); | ||
|
||
return useQuery({ | ||
queryKey: [`fetch-address-states`], | ||
queryFn: async (): Promise<FinancialInstitutionRS[]> => { | ||
const fetchedAddressStates = await fetchAddressStates(auth); | ||
return formatLabelValue(fetchedAddressStates); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useAddressStates; |