Skip to content

Commit 85ec203

Browse files
authored
Deduplicate state/jurisdiction references (#665)
1 parent ed85609 commit 85ec203

63 files changed

Lines changed: 248 additions & 390 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ pnpm-debug.log*
3232
# tests
3333
artifacts/
3434
coverage/
35-
/test-results/
36-
/playwright-report/
37-
/blob-report/
38-
/playwright/.cache/
35+
test-results/
36+
playwright-report/
37+
blob-report/
38+
playwright/.cache/
3939

4040
# cloudflare
4141
.wrangler/

docs/src/content/docs/guides/building-forms.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { defineForm } from "#lib/forms/defineForm";
3535
export default defineForm({
3636
title: "Court Order",
3737
description: "If you live in Massachusetts and want to update your name, this is the place to start.",
38-
state: "ma",
38+
jurisdiction: "ma",
3939
category: "court-order",
4040
steps: [
4141
// Step definitions...

pdf-manager/lib/fields.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export interface FormField {
2121
}
2222

2323
export interface Jurisdiction {
24+
id: string;
2425
name: string;
25-
abbreviation: string;
2626
}
2727

2828
let _formFields: FormField[] | null = null;
@@ -45,12 +45,11 @@ export function loadFormFields(): FormField[] {
4545
export function loadJurisdictions(): Jurisdiction[] {
4646
if (_jurisdictions) return _jurisdictions;
4747
const content = readFileSync(JURISDICTIONS_PATH, "utf8");
48-
const regex = /\{\s*name:\s*"([^"]+)",\s*abbreviation:\s*"([^"]+)"/g;
49-
const result: Jurisdiction[] = [];
50-
for (const m of content.matchAll(regex)) {
51-
result.push({ name: m[1], abbreviation: m[2] });
52-
}
53-
_jurisdictions = result;
48+
const regex = /^\s*(\w{2}):\s*\{\s*name:\s*"([^"]+)"/gm;
49+
_jurisdictions = [...content.matchAll(regex)].map(([, id, name]) => ({
50+
id,
51+
name,
52+
}));
5453
return _jurisdictions;
5554
}
5655

pdf-manager/lib/handlers.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,5 @@ export async function handleReplacePdf(c: Context) {
227227
}
228228

229229
export async function handleGetJurisdictions(c: Context) {
230-
return c.json([
231-
{ name: "Federal", abbreviation: "federal" },
232-
...loadJurisdictions(),
233-
]);
230+
return c.json([{ id: "federal", name: "Federal" }, ...loadJurisdictions()]);
234231
}

pdf-manager/src/components/AddPdfModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ export function AddPdfModal({ isOpen, onClose, onSuccess }: AddPdfModalProps) {
136136
<option value="" disabled>
137137
Select…
138138
</option>
139-
{jurisdictions.map((j) => (
140-
<option key={j.abbreviation} value={j.abbreviation}>
141-
{j.name}
139+
{jurisdictions.map((jurisdiction) => (
140+
<option key={jurisdiction.id} value={jurisdiction.id}>
141+
{jurisdiction.name}
142142
</option>
143143
))}
144144
</select>

pdf-manager/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export interface PdfMeta {
1414
}
1515

1616
export interface Jurisdiction {
17+
id: string;
1718
name: string;
18-
abbreviation: string;
1919
}
2020

2121
export interface Diff {

web/src/components/SupportMap.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { feature } from "topojson-client";
77
import type { GeometryCollection, Topology } from "topojson-specification";
88
import { formatStateList } from "#lib/utils/formatStateList";
99
10-
const stateEntries = await getCollection("states");
10+
const stateEntries = await getCollection("jurisdictions");
1111
1212
const stateSupport = stateEntries.reduce(
1313
(acc: Record<string, string>, entry) => {

web/src/components/forms/AddressField/AddressField.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe("AddressField", () => {
4747
// Select a state
4848
await userEvent.click(stateSelect);
4949
const californiaOption = screen.getByRole("option", {
50-
name: JURISDICTIONS.CA,
50+
name: JURISDICTIONS.ca.name,
5151
});
5252
await userEvent.click(californiaOption);
5353

@@ -238,7 +238,7 @@ describe("AddressField", () => {
238238
});
239239
await userEvent.click(stateSelect);
240240
const newYorkOption = screen.getByRole("option", {
241-
name: JURISDICTIONS.NY,
241+
name: JURISDICTIONS.ny.name,
242242
});
243243
await userEvent.click(newYorkOption);
244244

web/src/components/forms/AddressField/AddressField.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type MaskitoOptions, maskitoTransform } from "@maskito/core";
22
import { type Key, useState } from "react";
33
import { Controller, useFormContext } from "react-hook-form";
44
import type { FieldName } from "#constants/fields";
5-
import { JURISDICTIONS } from "#constants/jurisdictions";
5+
import { JURISDICTION_OPTIONS } from "#constants/jurisdictions";
66
import { ComboBox, ComboBoxItem } from "../../common/ComboBox";
77
import { TextField } from "../../common/TextField";
88
import "./AddressField.css";
@@ -206,9 +206,9 @@ export function AddressField({
206206
errorMessage={error?.message}
207207
menuTrigger="focus"
208208
>
209-
{Object.entries(JURISDICTIONS).map(([value, label]) => (
210-
<ComboBoxItem key={value} id={value}>
211-
{label}
209+
{JURISDICTION_OPTIONS.map((option) => (
210+
<ComboBoxItem key={option.value} id={option.value}>
211+
{option.label}
212212
</ComboBoxItem>
213213
))}
214214
</ComboBox>

web/src/constants/forms.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Step } from "#lib/forms/types";
22
import type { FormData } from "./fields";
3-
import type { StateId } from "./jurisdictions";
3+
import type { JurisdictionId } from "./jurisdictions";
44
import type { PDFId } from "./pdf";
55

66
export const FORM_SLUGS = [
@@ -80,8 +80,8 @@ export interface FormConfig {
8080
title: string;
8181
/** Optional description */
8282
description?: string;
83-
/** State abbreviation, e.g. "ma" */
84-
state?: StateId;
83+
/** Jurisdiction ID, e.g. "ma" */
84+
jurisdiction?: JurisdictionId;
8585
/** Category identifier */
8686
category: CategoryId;
8787
/** Costs associated with this form */

0 commit comments

Comments
 (0)