Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging #325

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 6 additions & 35 deletions src/components/modal/congoptions.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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<HHOptionProps> = [];
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<HHOptionProps> =
await getOptions(currentCongregation);
setOptions(optionValues);
} catch (error) {
errorHandler(error, rollbar);
}
};
getOptions();
getHHOptions();
}, [currentCongregation]);

return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/modal/inviteuser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions src/components/modal/newprivateadd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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", {
Expand Down
7 changes: 5 additions & 2 deletions src/components/modal/newpublicadd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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", {
Expand Down
9 changes: 7 additions & 2 deletions src/components/modal/newterritorycd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -45,7 +49,8 @@ const NewTerritoryCode = NiceModal.create(
}
await pollingVoidFunction(() =>
set(territoryCodeReference, {
name: name
name: name,
aggregates: DEFAULT_AGGREGATES
})
);
posthog?.capture("create_territory", {
Expand Down
2 changes: 2 additions & 0 deletions src/components/modal/updatestatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
({
Expand Down Expand Up @@ -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,
{
Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/updateuser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 12 additions & 11 deletions src/components/navigation/aggrbadge.tsx
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -12,14 +12,15 @@ const AggregationBadge = memo(
}
if (aggregate > 90) statusColor = "danger";
return (
<span style={{ marginRight: "0.25rem" }}>
{isDataFetched ? (
<Badge pill bg={statusColor} className={badgeStyle}>
{aggregate}%
</Badge>
) : (
<Spinner as="span" animation="border" size="sm" aria-hidden="true" />
)}
<span style={{ margin: "0 0.25rem" }}>
<Badge
pill
bg={statusColor}
className={badgeStyle}
style={{ width: width }}
>
{aggregate}%
</Badge>
</span>
);
}
Expand Down
10 changes: 9 additions & 1 deletion src/components/navigation/territorylist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { memo } from "react";
import { Offcanvas, ListGroup } from "react-bootstrap";
import { TERRITORY_SELECTOR_VIEWPORT_HEIGHT } from "../../utils/constants";
import { TerritoryListingProps } from "../../utils/interface";
import AggregationBadge from "./aggrbadge";

const TerritoryListing = memo(
({
Expand Down Expand Up @@ -36,8 +37,15 @@ const TerritoryListing = memo(
key={`list-group-item-${element.code}`}
eventKey={element.code}
active={selectedTerritory === element.code}
className="d-flex justify-content-between align-items-start"
>
{element.code} - {element.name}
<>
{element.code} - {element.name}
</>
<AggregationBadge
aggregate={element.aggregates}
width="3rem"
/>
</ListGroup.Item>
))}
</ListGroup>
Expand Down
9 changes: 5 additions & 4 deletions src/components/table/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
TERRITORY_TYPES,
USER_ACCESS_LEVELS,
DEFAULT_FLOOR_PADDING,
DEFAULT_UNIT_DNC_MS_TIME
DEFAULT_UNIT_DNC_MS_TIME,
DEFAULT_AGGREGATES
} from "../../utils/constants";
import ZeroPad from "../../utils/helpers/zeropad";
import { territoryTableProps } from "../../utils/interface";
Expand All @@ -15,7 +16,7 @@ const AdminTable = ({
postalCode,
floors,
maxUnitNumberLength,
completedPercent,
aggregates,
policy,
adminUnitHeaderStyle,
handleUnitNoUpdate,
Expand All @@ -30,7 +31,7 @@ const AdminTable = ({
isAdmin={true}
postalCode={postalCode}
houses={floors[0]}
completedPercent={completedPercent}
aggregates={aggregates}
handleHouseUpdate={handleUnitStatusUpdate}
policy={policy}
/>
Expand Down Expand Up @@ -97,7 +98,7 @@ const AdminTable = ({
<td
className={`text-center align-middle inline-cell ${policy?.getUnitColor(
detailsElement,
completedPercent.completedValue
aggregates?.value || DEFAULT_AGGREGATES.value
)}`}
onClick={handleUnitStatusUpdate}
key={`${index}-${detailsElement.number}`}
Expand Down
5 changes: 3 additions & 2 deletions src/components/table/privatetable.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Row, Col, Card } from "react-bootstrap";
import { territoryLandedProps } from "../../utils/interface";
import UnitStatus from "./unit";
import { DEFAULT_AGGREGATES } from "../../utils/constants";

const PrivateTerritoryTable = ({
isAdmin,
houses,
completedPercent,
aggregates,
policy: hhpolicy,
handleHouseUpdate
}: territoryLandedProps) => (
Expand Down Expand Up @@ -39,7 +40,7 @@ const PrivateTerritoryTable = ({
<div
className={`landed-unit fluid-bolding fluid-text ${hhpolicy?.getUnitColor(
element,
completedPercent.completedValue
aggregates?.value || DEFAULT_AGGREGATES.value
)}`}
style={{ padding: "0.3rem 0" }}
>
Expand Down
5 changes: 3 additions & 2 deletions src/components/table/publictable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { territoryTableProps } from "../../utils/interface";
import TableHeader from "./header";
import FloorHeader from "./floor";
import UnitStatus from "./unit";
import { DEFAULT_AGGREGATES } from "../../utils/constants";
const PublicTerritoryTable = ({
postalCode,
floors,
maxUnitNumberLength,
completedPercent,
aggregates,
policy: hhPolicy,
handleUnitStatusUpdate
}: territoryTableProps) => (
Expand All @@ -29,7 +30,7 @@ const PublicTerritoryTable = ({
<td
className={`text-center align-middle inline-cell ${hhPolicy?.getUnitColor(
element,
completedPercent.completedValue
aggregates?.value || DEFAULT_AGGREGATES.value
)}`}
onClick={handleUnitStatusUpdate}
data-floor={item.floor}
Expand Down
6 changes: 3 additions & 3 deletions src/components/table/publisher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const PublisherTerritoryTable = ({
postalCode,
floors,
maxUnitNumberLength,
completedPercent,
aggregates,
policy: policy,
territoryType,
handleUnitStatusUpdate
Expand All @@ -19,7 +19,7 @@ const PublisherTerritoryTable = ({
postalCode={postalCode}
houses={floors[0]}
policy={policy}
completedPercent={completedPercent}
aggregates={aggregates}
handleHouseUpdate={handleUnitStatusUpdate}
/>
);
Expand All @@ -29,7 +29,7 @@ const PublisherTerritoryTable = ({
postalCode={postalCode}
floors={floors}
maxUnitNumberLength={maxUnitNumberLength}
completedPercent={completedPercent}
aggregates={aggregates}
handleUnitStatusUpdate={handleUnitStatusUpdate}
policy={policy}
/>
Expand Down
Loading
Loading