From ccd3c08c178a87576b764fba97e38d8640d094b6 Mon Sep 17 00:00:00 2001 From: John Eric Date: Thu, 29 Aug 2024 08:34:44 +0800 Subject: [PATCH] feat: implement backend aggregates processor --- src/components/modal/inviteuser.tsx | 4 +- src/components/modal/updatestatus.tsx | 2 + src/components/modal/updateuser.tsx | 2 +- src/components/navigation/aggrbadge.tsx | 23 ++-- src/components/navigation/territorylist.tsx | 10 +- src/components/table/admin.tsx | 6 +- src/components/table/privatetable.tsx | 4 +- src/components/table/publictable.tsx | 4 +- src/components/table/publisher.tsx | 6 +- src/pages/admin.tsx | 111 +++++++------------ src/pages/slip.tsx | 13 ++- src/utils/constants.tsx | 6 +- src/utils/helpers/getcompletedpercent.ts | 25 ----- src/utils/helpers/getterritorydetails.ts | 47 ++++---- src/utils/helpers/maxunitlength.ts | 13 +-- src/utils/helpers/processcompletedpercent.ts | 14 --- src/utils/helpers/processpostalno.ts | 2 + src/utils/helpers/updateaddressdelta.ts | 13 +++ src/utils/interface.tsx | 22 ++-- 19 files changed, 143 insertions(+), 184 deletions(-) delete mode 100644 src/utils/helpers/getcompletedpercent.ts delete mode 100644 src/utils/helpers/processcompletedpercent.ts create mode 100644 src/utils/helpers/updateaddressdelta.ts diff --git a/src/components/modal/inviteuser.tsx b/src/components/modal/inviteuser.tsx index c05cd323..4bcf33f1 100644 --- a/src/components/modal/inviteuser.tsx +++ b/src/components/modal/inviteuser.tsx @@ -42,7 +42,7 @@ const InviteUser = NiceModal.create( } const getUserByEmail = httpsCallable( functions, - CLOUD_FUNCTIONS_CALLS.GET_USER_BY_EMAIL + `${import.meta.env.VITE_SYSTEM_ENVIRONMENT}-${CLOUD_FUNCTIONS_CALLS.GET_USER_BY_EMAIL}` ); const user = await getUserByEmail({ email: userEmail }); // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -61,7 +61,7 @@ const InviteUser = NiceModal.create( } const updateUserAccess = httpsCallable( functions, - CLOUD_FUNCTIONS_CALLS.UPDATE_USER_ACCESS + `${import.meta.env.VITE_SYSTEM_ENVIRONMENT}-${CLOUD_FUNCTIONS_CALLS.UPDATE_USER_ACCESS}` ); await updateUserAccess({ uid: userId, diff --git a/src/components/modal/updatestatus.tsx b/src/components/modal/updatestatus.tsx index 51ba903d..08225a19 100644 --- a/src/components/modal/updatestatus.tsx +++ b/src/components/modal/updatestatus.tsx @@ -47,6 +47,7 @@ import HelpButton from "../navigation/help"; import ChangeAddressGeolocation from "./changegeolocation"; import { getGenerativeModel } from "firebase/vertexai-preview"; import { usePostHog } from "posthog-js/react"; +import updateAddressDelta from "../../utils/helpers/updateaddressdelta"; const UpdateUnitStatus = NiceModal.create( ({ @@ -172,6 +173,7 @@ const UpdateUnitStatus = NiceModal.create( ); const updatedStatusType = updateData.status as string; if (updatedStatusType !== status) { + await updateAddressDelta(congregation, postalCode); posthog?.capture( PH_STATUS_KEYS[updatedStatusType] || PH_STATUS_KEYS.DEFAULT, { diff --git a/src/components/modal/updateuser.tsx b/src/components/modal/updateuser.tsx index dcb4b98f..05cbd4df 100644 --- a/src/components/modal/updateuser.tsx +++ b/src/components/modal/updateuser.tsx @@ -36,7 +36,7 @@ const UpdateUser = NiceModal.create( try { const updateUserAccess = httpsCallable( functions, - CLOUD_FUNCTIONS_CALLS.UPDATE_USER_ACCESS + `${import.meta.env.VITE_SYSTEM_ENVIRONMENT}-${CLOUD_FUNCTIONS_CALLS.UPDATE_USER_ACCESS}` ); await updateUserAccess({ uid: uid, diff --git a/src/components/navigation/aggrbadge.tsx b/src/components/navigation/aggrbadge.tsx index 9f250604..cf9c83dd 100644 --- a/src/components/navigation/aggrbadge.tsx +++ b/src/components/navigation/aggrbadge.tsx @@ -1,9 +1,9 @@ import { memo } from "react"; -import { Badge, Spinner } from "react-bootstrap"; -import { aggregateProp } from "../../utils/interface"; +import { Badge } from "react-bootstrap"; +import { aggregateBadgeProp } from "../../utils/interface"; const AggregationBadge = memo( - ({ aggregate = 0, isDataFetched }: aggregateProp) => { + ({ aggregate = 0, width = "2.5rem" }: aggregateBadgeProp) => { let badgeStyle = ""; let statusColor = "success"; if (aggregate > 70 && aggregate <= 90) { @@ -12,14 +12,15 @@ const AggregationBadge = memo( } if (aggregate > 90) statusColor = "danger"; return ( - - {isDataFetched ? ( - - {aggregate}% - - ) : ( -