From a78ad8e9c780eb6ffabdfff380b2b6fcb6a1ba3e Mon Sep 17 00:00:00 2001 From: IuliiaSam Date: Tue, 11 Feb 2025 21:01:31 -0500 Subject: [PATCH] Hack Night 2/11/25 Co-authored-by: Joe Co-authored-by: B. Sanders --- src/AddressBox.tsx | 12 +++--- src/App.tsx | 11 +++-- src/EligiblePage.tsx | 1 + ...ng.tsx => IncorrectAddressPageHeading.tsx} | 4 +- src/LoadingPage.tsx | 9 +--- src/SearchPage.tsx | 43 ++++++++----------- src/index.css | 7 +++ src/types.ts | 2 +- 8 files changed, 43 insertions(+), 46 deletions(-) rename src/{NoAddressPageHeading.tsx => IncorrectAddressPageHeading.tsx} (66%) diff --git a/src/AddressBox.tsx b/src/AddressBox.tsx index 0e75ef4..5d17c3b 100644 --- a/src/AddressBox.tsx +++ b/src/AddressBox.tsx @@ -22,7 +22,7 @@ const AutocompleteInput = forwardRef((props_, ref) => { return; // instantiate a Place prediction widget that attaches to input field - const p = new places.Autocomplete(inputRef.current, { + const placesWidget = new places.Autocomplete(inputRef.current, { strictBounds: true, bounds: { south: 42.23286, @@ -34,11 +34,8 @@ const AutocompleteInput = forwardRef((props_, ref) => { // 'place_changed' event fires when user selects a place from the drop-down list of autosuggestions. For reference, see: // https://developers.google.com/maps/documentation/javascript/reference/places-widget#Autocomplete.place_changed - p.addListener('place_changed', () => { - // eslint-disable-next-line no-debugger - // debugger; - - const place = p.getPlace(); + placesWidget.addListener('place_changed', () => { + const place = placesWidget.getPlace(); onPlaceChanged?.(place); }); }, [places, onPlaceChanged]); @@ -50,7 +47,7 @@ const AutocompleteInput = forwardRef((props_, ref) => { if (typeof ref === 'function') ref(input); else - ref.current = input + ref.current = input; } }} {...props} /> ) @@ -58,6 +55,7 @@ const AutocompleteInput = forwardRef((props_, ref) => { const AddressBox = forwardRef((props, ref) => { return ( + // TO-DO: create a .env file to store the apiKey in diff --git a/src/App.tsx b/src/App.tsx index 11f1c7d..b88da26 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,7 +7,7 @@ import EligiblePage from './EligiblePage'; import NotEligiblePage from './NotEligiblePage'; import LoadingPage from './LoadingPage'; import ErrorPage from './ErrorPage'; -import NoAddressPageHeading from './NoAddressPageHeading'; +import IncorrectAddressPageHeading from './IncorrectAddressPageHeading'; import SearchPageHeading from './SearchPageHeading'; // Main App component @@ -22,10 +22,13 @@ function App() { case 'loading': - return - case 'no_address': return <> - + + + + case 'incorrect_address': + return <> + case 'eligible': diff --git a/src/EligiblePage.tsx b/src/EligiblePage.tsx index dd714df..2781da9 100644 --- a/src/EligiblePage.tsx +++ b/src/EligiblePage.tsx @@ -6,6 +6,7 @@ const joinTodayUrl = 'https://app.loanspq.com/xa/xpressApp.aspx?enc=Kw21Wblm1yxp const learnMoreAboutMemberships = 'https://harvardfcu.org/membership/join/' const EligiblePage: React.FC = () => { + // TO-DO: success svg is not displayed on page return ( <>

diff --git a/src/NoAddressPageHeading.tsx b/src/IncorrectAddressPageHeading.tsx similarity index 66% rename from src/NoAddressPageHeading.tsx rename to src/IncorrectAddressPageHeading.tsx index 8ec5881..00a268a 100644 --- a/src/NoAddressPageHeading.tsx +++ b/src/IncorrectAddressPageHeading.tsx @@ -5,8 +5,8 @@ type Props = React.PropsWithChildren; const NoAddressPageHeading: React.FC = () => { return ( <> -

It looks like the address you entered is incorrect. Re-enter your address to try again

-

{'(Image of a face with a raised eyebrow goes here)'}

+

It looks like the address you entered is invalid or incorrect. Re-enter your address to try again

+
) } diff --git a/src/LoadingPage.tsx b/src/LoadingPage.tsx index b1f4c9f..1574961 100644 --- a/src/LoadingPage.tsx +++ b/src/LoadingPage.tsx @@ -5,15 +5,10 @@ import LoadingImage from '../assets/loading.gif'; type Props = React.PropsWithChildren; const LoadingPage: React.FC = () => { - // TO-DO: add spinner return ( - <> -

Do you live, work, worship, or attend school in one of our qualified census tracts?

-

If so, you might be eligible for membership with us! Enter your address below to check and see if you qualify!

-
+
-
- +
) } diff --git a/src/SearchPage.tsx b/src/SearchPage.tsx index 0e5bb96..2ffc4d6 100644 --- a/src/SearchPage.tsx +++ b/src/SearchPage.tsx @@ -14,66 +14,60 @@ type Props = { const SearchPage: React.FC = (props: Props) => { const { setPageState } = props; - // const [inputValue, setInputValue] = useState(""); const inputRef = useRef(null) - // const [censusApiResponse, setCensusApiResponse] = useState(null); - // const addressIsEligible = !!(censusApiResponse && findEligibleAddress(censusApiResponse)); - - // Update the input value on text change - // const handleInputChange = (newValue: string) => { - // console.log(newValue); - // setInputValue(newValue); - // } // Update the input value on fetching the address const handlePlaceChange = useCallback((place: google.maps.places.PlaceResult) => { // Parse a given Autocomplete prediction - // TO-DO: refactor to use place.fetchFields()? + // TO-DO: check if it makes sense to refactor it using place.fetchFields() const addressComponentsToDisplay = ['street_number', 'route', 'neighborhood', 'locality', 'postal_code']; const addressPieces: string[] = []; + // TO-DO: refactor to use code in Find My Location + // if street address is empty, get address by coordinates place.address_components?.forEach(component => { if (addressComponentsToDisplay.includes(component.types[0])) addressPieces.push(component.long_name); }) - if (inputRef.current){ + if (inputRef.current && addressPieces.length){ inputRef.current.value = addressPieces.join(', '); } - // setInputValue(addressPieces.join(', ')); }, []) // Handle the form submission for geocoding request const handleSubmit: React.FormEventHandler = async (e) => { e.preventDefault(); - const address = inputRef.current?.value || '' - if (!address) { - // alert("Please input an address.") - setPageState("no_address"); - return + + const address = inputRef.current?.value || ''; + + if (address.length <= 1) { + setPageState("incorrect_address"); + return; } setPageState("loading"); try { // Retrieve geocoding data for the given address const censusApiResponse = await geocode({ address }); - // console.log('matchedAddress', censusApiResponse.result.addressMatches[0].matchedAddress); - + // Find out if address is eligible and update the page state - // TO-DO: refactor into a function (see Use My Location) const addressIsEligible = !!(censusApiResponse && findEligibleAddress(censusApiResponse)); setPageState(addressIsEligible ? "eligible" : "not_eligible"); } catch (error) { - console.error(error) - setPageState("error") + console.error(error); + setPageState("error"); } } // Process Census API response and find eligible address, if any. function findEligibleAddress(result: CensusApiResponse) { const addressMatches = result.result.addressMatches; - console.log('addressMatches', addressMatches); + + // TO-DO: set state to incorrect_address when addressMatches array is empty + // if (addressMatches.length == 0) { + // setPageState("incorrect_address"); // error state + // } for (const address of addressMatches) { // Check if there is at least one address match and that it contains Census Tract information const tractData = address.geographies["Census Tracts"]; - console.log('tractData: ', tractData); // Verify that Census Tract information is available if (tractData && tractData.length > 0) { @@ -123,7 +117,6 @@ const SearchPage: React.FC = (props: Props) => { if (inputRef.current) inputRef.current.value = matched.formatted_address; - // console.log(); const censusApiResponse = await lookupCoords({ lng: position.coords.longitude, lat: position.coords.latitude, diff --git a/src/index.css b/src/index.css index 535e338..4a32b4a 100644 --- a/src/index.css +++ b/src/index.css @@ -210,6 +210,13 @@ div.loading { transform: rotate(-10deg); } +.elig-wonder-svg { + background-image: url("./assets/HFCU_Emotes_RGB_Full Color_Wonder.svg"); + background-size: 110%; + width: 70px; + height: 70px; +} + .elig-a { color: var(--primary-color); align-self: center; diff --git a/src/types.ts b/src/types.ts index b3386b4..5826561 100644 --- a/src/types.ts +++ b/src/types.ts @@ -100,4 +100,4 @@ export type CensusCoordsApiResponse = { } } -export type EligibilityAppStates = "search" | "loading" | "eligible" | "not_eligible" | "error" | "no_address"; \ No newline at end of file +export type EligibilityAppStates = "search" | "loading" | "eligible" | "not_eligible" | "error" | "incorrect_address"; \ No newline at end of file