diff --git a/app/components/AdminDropdown/BoroughDropdown.test.tsx b/app/components/AdminDropdown/BoroughDropdown.test.tsx
index 1695b0e..70d6d6b 100644
--- a/app/components/AdminDropdown/BoroughDropdown.test.tsx
+++ b/app/components/AdminDropdown/BoroughDropdown.test.tsx
@@ -14,7 +14,7 @@ describe("BoroughDropdown", () => {
const updateSearchParams = vi.fn();
render(
,
);
@@ -28,7 +28,7 @@ describe("BoroughDropdown", () => {
const firstBoroughId = boroughs[0].id;
render(
,
@@ -37,6 +37,8 @@ describe("BoroughDropdown", () => {
await act(() => userEvent.selectOptions(screen.getByRole("combobox"), ""));
expect(updateSearchParams).toHaveBeenCalledWith({
districtType: "cd",
+ boroughId: null,
+ districtId: null,
});
});
@@ -45,7 +47,7 @@ describe("BoroughDropdown", () => {
const firstBoroughId = boroughs[0].id;
render(
,
);
@@ -56,6 +58,7 @@ describe("BoroughDropdown", () => {
expect(updateSearchParams).toHaveBeenCalledWith({
districtType: "cd",
boroughId: firstBoroughId,
+ districtId: null,
});
});
});
diff --git a/app/components/AdminDropdown/BoroughDropdown.tsx b/app/components/AdminDropdown/BoroughDropdown.tsx
index a2a1d23..3e08526 100644
--- a/app/components/AdminDropdown/BoroughDropdown.tsx
+++ b/app/components/AdminDropdown/BoroughDropdown.tsx
@@ -1,30 +1,24 @@
import { Borough } from "~/gen";
import { AdminDropdownProps, AdminDropdown } from ".";
-import { BoroughId } from "~/root";
+import { AdminParams, BoroughId } from "~/utils/types";
export interface BoroughDropdownProps
extends Pick {
- updateSearchParams: (value: Record) => void;
boroughs: Array | null;
+ setAdminParams: (value: AdminParams) => void;
}
export function BoroughDropdown({
selectValue,
- updateSearchParams,
boroughs,
+ setAdminParams,
}: BoroughDropdownProps) {
const updateBoroughId = (nextBoroughId: BoroughId) => {
- const nextSearchParams: Record =
- nextBoroughId !== null
- ? {
- districtType: "cd",
- boroughId: nextBoroughId,
- }
- : {
- districtType: "cd",
- };
-
- updateSearchParams(nextSearchParams);
+ setAdminParams({
+ districtType: "cd",
+ boroughId: nextBoroughId,
+ districtId: null,
+ });
};
const boroughOptions = boroughs?.map((borough) => (
diff --git a/app/components/AdminDropdown/CityCouncilDistrictDropdown.test.tsx b/app/components/AdminDropdown/CityCouncilDistrictDropdown.test.tsx
index 386cea2..5730324 100644
--- a/app/components/AdminDropdown/CityCouncilDistrictDropdown.test.tsx
+++ b/app/components/AdminDropdown/CityCouncilDistrictDropdown.test.tsx
@@ -17,7 +17,7 @@ describe("CityCouncilDistrictDropdown", () => {
const updateSearchParams = vi.fn();
render(
,
);
@@ -31,7 +31,7 @@ describe("CityCouncilDistrictDropdown", () => {
const firstCityCouncilDistrictId = cityCouncilDistricts[0].id;
render(
,
@@ -40,6 +40,8 @@ describe("CityCouncilDistrictDropdown", () => {
await act(() => userEvent.selectOptions(screen.getByRole("combobox"), ""));
expect(updateSearchParams).toHaveBeenCalledWith({
districtType: "ccd",
+ boroughId: null,
+ districtId: null,
});
});
@@ -48,7 +50,7 @@ describe("CityCouncilDistrictDropdown", () => {
const firstCityCouncilDistrictId = cityCouncilDistricts[0].id;
render(
,
);
@@ -61,6 +63,7 @@ describe("CityCouncilDistrictDropdown", () => {
);
expect(updateSearchParams).toHaveBeenCalledWith({
districtType: "ccd",
+ boroughId: null,
districtId: firstCityCouncilDistrictId,
});
});
diff --git a/app/components/AdminDropdown/CityCouncilDistrictDropdown.tsx b/app/components/AdminDropdown/CityCouncilDistrictDropdown.tsx
index 251c00e..6638457 100644
--- a/app/components/AdminDropdown/CityCouncilDistrictDropdown.tsx
+++ b/app/components/AdminDropdown/CityCouncilDistrictDropdown.tsx
@@ -1,33 +1,23 @@
import { CityCouncilDistrict } from "~/gen";
import { AdminDropdownProps, AdminDropdown } from ".";
-import { DistrictId } from "~/root";
+import { AdminParams, DistrictId } from "~/utils/types";
export interface CityCouncilDistrictDropdownProps
extends Pick {
- updateSearchParams: (value: Record) => void;
cityCouncilDistricts: Array | null;
+ setAdminParams: (value: AdminParams) => void;
}
export function CityCouncilDistrictDropdown({
selectValue,
- updateSearchParams,
cityCouncilDistricts,
+ setAdminParams,
}: CityCouncilDistrictDropdownProps) {
const updateDistrictId = (nextDistrictId: DistrictId) => {
- const districtType = "ccd";
-
- if (nextDistrictId === null) {
- updateSearchParams({
- districtType,
- });
- return;
- }
- if (nextDistrictId !== null) {
- updateSearchParams({
- districtType,
- districtId: nextDistrictId,
- });
- return;
- }
+ setAdminParams({
+ districtType: "ccd",
+ boroughId: null,
+ districtId: nextDistrictId,
+ });
};
const cityCouncilDistrictOptions = cityCouncilDistricts?.map((cd) => (
diff --git a/app/components/AdminDropdown/CommunityDistrictDropdown.test.tsx b/app/components/AdminDropdown/CommunityDistrictDropdown.test.tsx
index 6bee34c..2e23fdf 100644
--- a/app/components/AdminDropdown/CommunityDistrictDropdown.test.tsx
+++ b/app/components/AdminDropdown/CommunityDistrictDropdown.test.tsx
@@ -20,7 +20,7 @@ describe("CommunityDistrictDropdown", () => {
render(
,
);
@@ -36,14 +36,18 @@ describe("CommunityDistrictDropdown", () => {
render(
,
);
await act(() => userEvent.selectOptions(screen.getByRole("combobox"), ""));
- expect(updateSearchParams).toHaveBeenCalledWith({ districtType: "cd" });
+ expect(updateSearchParams).toHaveBeenCalledWith({
+ districtType: "cd",
+ boroughId: null,
+ districtId: null,
+ });
});
it("should set search params when nextDistrictID is empty", async () => {
@@ -53,7 +57,7 @@ describe("CommunityDistrictDropdown", () => {
render(
,
@@ -63,6 +67,7 @@ describe("CommunityDistrictDropdown", () => {
expect(updateSearchParams).toHaveBeenCalledWith({
districtType: "cd",
boroughId,
+ districtId: null,
});
});
@@ -72,7 +77,7 @@ describe("CommunityDistrictDropdown", () => {
render(
,
diff --git a/app/components/AdminDropdown/CommunityDistrictDropdown.tsx b/app/components/AdminDropdown/CommunityDistrictDropdown.tsx
index 601f857..998469c 100644
--- a/app/components/AdminDropdown/CommunityDistrictDropdown.tsx
+++ b/app/components/AdminDropdown/CommunityDistrictDropdown.tsx
@@ -1,44 +1,27 @@
import { CommunityDistrict } from "~/gen";
import { AdminDropdown, AdminDropdownProps } from ".";
-import { BoroughId, DistrictId } from "~/root";
-
+import { AdminParams, BoroughId, DistrictId } from "~/utils/types";
export interface CommunityDistrictDropdownProps
extends Pick {
boroughId: BoroughId;
- updateSearchParams: (value: Record) => void;
communityDistricts: Array | null;
+ setAdminParams: (value: AdminParams) => void;
}
+
export function CommunityDistrictDropdown({
selectValue,
- updateSearchParams,
boroughId,
communityDistricts,
+ setAdminParams,
}: CommunityDistrictDropdownProps) {
const updateDistrictId = (nextDistrictId: DistrictId) => {
- const districtType = "cd";
- if (boroughId === null) {
- updateSearchParams({
- districtType,
- });
- return;
- }
-
- if (boroughId !== null && nextDistrictId === null) {
- updateSearchParams({
- districtType,
- boroughId,
- });
- return;
- }
- if (boroughId !== null && nextDistrictId !== null) {
- updateSearchParams({
- districtType,
- boroughId,
- districtId: nextDistrictId,
- });
- return;
- }
+ setAdminParams({
+ districtType: "cd",
+ boroughId: boroughId,
+ districtId: nextDistrictId,
+ });
};
+
const communityDistrictOptions = communityDistricts?.map((cd) => (