-
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.
[TM-1343] get data for countries in popup (#562)
* [TM-1343] get data for countries in popup * [TM-1343] remove some anys * TM-1343 fix tooltip country design * TM-1343 fix build * [TM-1343] fix if --------- Co-authored-by: diego-morales-flores-1996 <[email protected]>
- Loading branch information
1 parent
b8d8111
commit e697141
Showing
9 changed files
with
323 additions
and
80 deletions.
There are no files selected for viewing
62 changes: 58 additions & 4 deletions
62
src/components/elements/Map-mapbox/components/DashboardPopup.tsx
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 |
---|---|---|
@@ -1,15 +1,69 @@ | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import { useEffect, useState } from "react"; | ||
|
||
import { fetchGetV2DashboardTotalSectionHeaderCountry } from "@/generated/apiComponents"; | ||
import TooltipGridMap from "@/pages/dashboard/components/TooltipGridMap"; | ||
import { createQueryParams } from "@/utils/dashboardUtils"; | ||
|
||
const client = new QueryClient(); | ||
|
||
type Item = { | ||
id: string; | ||
title: string; | ||
value: string; | ||
}; | ||
export const DashboardPopup = (event: any) => { | ||
const isoCountry = event?.feature?.properties?.iso; | ||
const countryName = event?.feature?.properties?.country; | ||
const { addPopupToMap } = event; | ||
const [items, setItems] = useState<Item[]>([]); | ||
useEffect(() => { | ||
async function fetchData() { | ||
const parsedFilters = { | ||
programmes: [], | ||
country: isoCountry, | ||
"organisations.type": [], | ||
landscapes: [] | ||
}; | ||
const queryParams: any = createQueryParams(parsedFilters); | ||
const response: any = await fetchGetV2DashboardTotalSectionHeaderCountry({ queryParams: queryParams }); | ||
if (response) { | ||
const parsedItems = [ | ||
{ | ||
id: "1", | ||
title: "No. of Projects", | ||
value: ((response.total_enterprise_count || 0) + (response.total_non_profit_count || 0)).toString() | ||
}, | ||
{ | ||
id: "2", | ||
title: "Trees Planted", | ||
value: (response.total_trees_restored || 0).toString() | ||
}, | ||
{ | ||
id: "3", | ||
title: "Restoration Hectares", | ||
value: (response.total_hectares_restored || 0).toString() | ||
}, | ||
{ | ||
id: "4", | ||
title: "Jobs Created", | ||
value: (response.total_entries || 0).toString() | ||
} | ||
]; | ||
setItems(parsedItems); | ||
addPopupToMap(); | ||
} else { | ||
console.error("No data returned from the API"); | ||
} | ||
} | ||
fetchData(); | ||
}, [isoCountry]); | ||
return ( | ||
<QueryClientProvider client={client}> | ||
<TooltipGridMap label={countryName} learnMore={true} isoCountry={isoCountry} /> | ||
</QueryClientProvider> | ||
<> | ||
{items && ( | ||
<QueryClientProvider client={client}> | ||
<TooltipGridMap label={countryName} learnMore={true} isoCountry={isoCountry} items={items} /> | ||
</QueryClientProvider> | ||
)} | ||
</> | ||
); | ||
}; |
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
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
Oops, something went wrong.