Skip to content

Commit

Permalink
chore: code optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
rimorin committed Aug 30, 2024
1 parent 42b6e34 commit 58f8837
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 203 deletions.
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
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: 1 addition & 1 deletion src/components/navigation/territorylist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const TerritoryListing = memo(
className="d-flex justify-content-between align-items-start"
>
<>
{element.code} - {element.name} ({element.aggregates})
{element.code} - {element.name}
</>
<AggregationBadge
aggregate={element.aggregates}
Expand Down
5 changes: 3 additions & 2 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 Down Expand Up @@ -97,7 +98,7 @@ const AdminTable = ({
<td
className={`text-center align-middle inline-cell ${policy?.getUnitColor(
detailsElement,
aggregates.value
aggregates?.value || DEFAULT_AGGREGATES.value
)}`}
onClick={handleUnitStatusUpdate}
key={`${index}-${detailsElement.number}`}
Expand Down
3 changes: 2 additions & 1 deletion src/components/table/privatetable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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,
Expand Down Expand Up @@ -39,7 +40,7 @@ const PrivateTerritoryTable = ({
<div
className={`landed-unit fluid-bolding fluid-text ${hhpolicy?.getUnitColor(
element,
aggregates.value
aggregates?.value || DEFAULT_AGGREGATES.value
)}`}
style={{ padding: "0.3rem 0" }}
>
Expand Down
3 changes: 2 additions & 1 deletion src/components/table/publictable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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,
Expand All @@ -29,7 +30,7 @@ const PublicTerritoryTable = ({
<td
className={`text-center align-middle inline-cell ${hhPolicy?.getUnitColor(
element,
aggregates.value
aggregates?.value || DEFAULT_AGGREGATES.value
)}`}
onClick={handleUnitStatusUpdate}
data-floor={item.floor}
Expand Down
Loading

0 comments on commit 58f8837

Please sign in to comment.