diff --git a/README.md b/README.md index 0d67e2f..90cb2a7 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,12 @@ Install Node 19+ npm install --legacy-peer-deps +create database trigger_database; +grant all privileges on trigger_database.* TO 'triggeradmin'@'localhost' identified by 'trigger'; +flush privileges; + +import defaultDatabase.sql into your database server + To run: npm run dev @@ -16,11 +22,9 @@ npm run build Run with pm2: npm install -g pm2 sudo pm2 serve ./dist --no-daemon --spa --port 3000 - +sudo pm2 start server.cjs # TODO - Image uploads for backgrounds -- Create actions section - - Improve mobile diff --git a/src/components/DataTable/columns/PersonalizationColumns.tsx b/src/components/DataTable/columns/PersonalizationColumns.tsx index 3ba1b68..4be82ed 100644 --- a/src/components/DataTable/columns/PersonalizationColumns.tsx +++ b/src/components/DataTable/columns/PersonalizationColumns.tsx @@ -41,6 +41,18 @@ export function PersonalizationColumns() { Cell: ({ renderedCellValue }) => renderedCellValue, Header: ({ column }) => column.columnDef.header, }, + { + accessorFn: (row: any) => { + if (row.physicalAddress) { + return `${row.physicalAddress}`; + } + return ''; + }, + id: 'physicalAddress', + header: 'Address', + Cell: ({ renderedCellValue }) => renderedCellValue, + Header: ({ column }) => column.columnDef.header, + }, ], [], ); diff --git a/src/hooks/index.ts b/src/hooks/index.ts index ccade18..83bc434 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -1,2 +1,2 @@ -export { useQueryAPI, useWeatherAPI, useMutationAPI } from './useAPI'; +export { useQueryAPI, useWeatherAPI, useMutationAPI, useCensusAPI } from './useAPI'; export { useCommonHooks } from './useCommonHooks'; diff --git a/src/hooks/useAPI.ts b/src/hooks/useAPI.ts index 37137bb..f35eaad 100644 --- a/src/hooks/useAPI.ts +++ b/src/hooks/useAPI.ts @@ -142,6 +142,23 @@ export function useWeatherAPI({ endpoint }: { endpoint: string }) { }); } +export function useCensusAPI({ address }: { address: string }) { + const url = `https://geocoding.geo.census.gov/geocoder/locations/onelineaddress?address=${address?.replaceAll(' ', '+').replaceAll(',', '%2C').replaceAll('#', '%23')}&benchmark=4&format=json`; + + const callEndpoint = async () => { + const response = await fetch(url); + if (!response.ok) { + throw new Error(`${response.status} ${response.statusText}`); + } + return await response.json(); + }; + + return useQuery({ + queryKey: ['GET', url], + queryFn: () => callEndpoint(), + }); +} + export function useFileUploadAPI() { const callEndpoint = async ( method: string, diff --git a/src/hooks/useCommonHooks.ts b/src/hooks/useCommonHooks.ts index f94765a..322679a 100644 --- a/src/hooks/useCommonHooks.ts +++ b/src/hooks/useCommonHooks.ts @@ -3,7 +3,7 @@ import { appTheme } from 'contexts'; import { useAtom } from 'jotai'; import { useEffect, useState } from 'react'; import { toast } from 'react-toastify'; -import { useQueryAPI, useWeatherAPI } from './useAPI'; +import { useCensusAPI, useQueryAPI, useWeatherAPI } from './useAPI'; export function useCommonHooks() { const isMobile = window.matchMedia('(max-width: 600px)').matches; @@ -161,6 +161,18 @@ export function useCommonHooks() { } }, [wolClients, wolClientsIsFetched]); + const { data: locationData } = useCensusAPI({ + address: personalData?.[0]?.physicalAddress, + }); + + const [location, setLocation] = useState([]); + + useEffect(() => { + if (locationData) { + setLocation(locationData); + } + }, [locationData]); + return { isMobile, theme, @@ -222,6 +234,7 @@ export function useCommonHooks() { wolClientsIsFetched, wolClientsIsFetching, wolClientsIsLoading, + location, notify, }; }