diff --git a/src/components/modal/congoptions.tsx b/src/components/modal/congoptions.tsx index 16ee6834..3943e8b2 100644 --- a/src/components/modal/congoptions.tsx +++ b/src/components/modal/congoptions.tsx @@ -1,13 +1,6 @@ import NiceModal, { useModal, bootstrapDialog } from "@ebay/nice-modal-react"; import { useRollbar } from "@rollbar/react"; -import { - set, - ref, - get, - query, - orderByChild, - DataSnapshot -} from "firebase/database"; +import { set, ref } from "firebase/database"; import { useState, FormEvent, @@ -35,12 +28,12 @@ import { HHOptionProps, UpdateCongregationOptionsModalProps } from "../../utils/interface"; -import pollingQueryFunction from "../../utils/helpers/pollingquery"; import GenericInputField from "../form/input"; import ModalSubmitButton from "../form/submit"; import { confirmAlert } from "react-confirm-alert"; import { flushSync } from "react-dom"; import { usePostHog } from "posthog-js/react"; +import { getOptions } from "../../utils/helpers/getcongoptions"; const UpdateCongregationOptions = NiceModal.create( ({ currentCongregation }: UpdateCongregationOptionsModalProps) => { @@ -184,38 +177,16 @@ const UpdateCongregationOptions = NiceModal.create( ); useEffect(() => { - const getOptions = async () => { + const getHHOptions = async () => { try { - const optionsSnapshot = await pollingQueryFunction(() => - get( - query( - ref( - database, - `congregations/${currentCongregation}/options/list` - ), - orderByChild("sequence") - ) - ) - ); - const optionValues: Array = []; - optionsSnapshot.forEach((element: DataSnapshot) => { - const optionDetails = element.val(); - const optionCode = element.key as string; - const option = { - code: optionCode, - description: optionDetails.description, - isCountable: optionDetails.isCountable || false, - isDefault: optionDetails.isDefault || false, - sequence: optionDetails.sequence - }; - optionValues.push(option); - }); + const optionValues: Array = + await getOptions(currentCongregation); setOptions(optionValues); } catch (error) { errorHandler(error, rollbar); } }; - getOptions(); + getHHOptions(); }, [currentCongregation]); return ( 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/newprivateadd.tsx b/src/components/modal/newprivateadd.tsx index b5fdd36c..eaca6cc2 100644 --- a/src/components/modal/newprivateadd.tsx +++ b/src/components/modal/newprivateadd.tsx @@ -8,7 +8,8 @@ import { TERRITORY_TYPES, STATUS_CODES, NOT_HOME_STATUS_CODES, - WIKI_CATEGORIES + WIKI_CATEGORIES, + DEFAULT_AGGREGATES } from "../../utils/constants"; import isValidPostal from "../../utils/helpers/checkvalidpostal"; import isValidPostalSequence from "../../utils/helpers/checkvalidseq"; @@ -112,7 +113,9 @@ const NewPrivateAddress = NiceModal.create( location: location, units: floorDetails, type: TERRITORY_TYPES.PRIVATE, - coordinates: coordinates + coordinates: coordinates, + aggregates: DEFAULT_AGGREGATES, + delta: 0 }) ); posthog?.capture("create_private_address", { diff --git a/src/components/modal/newpublicadd.tsx b/src/components/modal/newpublicadd.tsx index dbf9244d..3cc08a72 100644 --- a/src/components/modal/newpublicadd.tsx +++ b/src/components/modal/newpublicadd.tsx @@ -9,7 +9,8 @@ import { TERRITORY_TYPES, STATUS_CODES, NOT_HOME_STATUS_CODES, - WIKI_CATEGORIES + WIKI_CATEGORIES, + DEFAULT_AGGREGATES } from "../../utils/constants"; import isValidPostal from "../../utils/helpers/checkvalidpostal"; import isValidPostalSequence from "../../utils/helpers/checkvalidseq"; @@ -116,7 +117,9 @@ const NewPublicAddress = NiceModal.create( units: floorDetails, type: TERRITORY_TYPES.PUBLIC, location: location, - coordinates: coordinates + coordinates: coordinates, + aggregates: DEFAULT_AGGREGATES, + delta: 0 }) ); posthog?.capture("create_public_address", { diff --git a/src/components/modal/newterritorycd.tsx b/src/components/modal/newterritorycd.tsx index 83abe5d5..da4fd009 100644 --- a/src/components/modal/newterritorycd.tsx +++ b/src/components/modal/newterritorycd.tsx @@ -4,7 +4,11 @@ import { child, ref, get, set } from "firebase/database"; import { useState, FormEvent, ChangeEvent } from "react"; import { Modal, Form } from "react-bootstrap"; import { database } from "../../firebase"; -import { USER_ACCESS_LEVELS, WIKI_CATEGORIES } from "../../utils/constants"; +import { + DEFAULT_AGGREGATES, + USER_ACCESS_LEVELS, + WIKI_CATEGORIES +} from "../../utils/constants"; import pollingVoidFunction from "../../utils/helpers/pollingvoid"; import errorHandler from "../../utils/helpers/errorhandler"; import pollingQueryFunction from "../../utils/helpers/pollingquery"; @@ -45,7 +49,8 @@ const NewTerritoryCode = NiceModal.create( } await pollingVoidFunction(() => set(territoryCodeReference, { - name: name + name: name, + aggregates: DEFAULT_AGGREGATES }) ); posthog?.capture("create_territory", { 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}% - - ) : ( -