Skip to content

Commit d56e138

Browse files
committed
Create reusable jurisdiction options
1 parent c118260 commit d56e138

12 files changed

Lines changed: 38 additions & 54 deletions

File tree

pdf-manager/lib/fields.ts

Lines changed: 5 additions & 6 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;
@@ -46,11 +46,10 @@ export function loadJurisdictions(): Jurisdiction[] {
4646
if (_jurisdictions) return _jurisdictions;
4747
const content = readFileSync(JURISDICTIONS_PATH, "utf8");
4848
const regex = /^\s*(\w{2}):\s*\{\s*name:\s*"([^"]+)"/gm;
49-
const result: Jurisdiction[] = [];
50-
for (const m of content.matchAll(regex)) {
51-
result.push({ name: m[2], abbreviation: m[1].toUpperCase() });
52-
}
53-
_jurisdictions = result;
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/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(([id, jurisdiction]) => (
210-
<ComboBoxItem key={id} id={id}>
211-
{jurisdiction.name}
209+
{JURISDICTION_OPTIONS.map((option) => (
210+
<ComboBoxItem key={option.value} id={option.value}>
211+
{option.label}
212212
</ComboBoxItem>
213213
))}
214214
</ComboBox>

web/src/constants/jurisdictions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,11 @@ export const JURISDICTIONS = {
7878

7979
/** Lowercase state/territory abbreviation, matching content collection jurisdiction IDs. */
8080
export type JurisdictionId = keyof typeof JURISDICTIONS;
81+
82+
/** `{ label, value }` options for jurisdiction selects/comboboxes. */
83+
export const JURISDICTION_OPTIONS = Object.entries(JURISDICTIONS).map(
84+
([id, jurisdiction]) => ({
85+
label: jurisdiction.name,
86+
value: id as JurisdictionId,
87+
}),
88+
);

web/src/content/forms/court-order-ma-minor/steps/BirthplaceStep.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ComboBoxField } from "#components/forms/ComboBoxField";
22
import { FormStep, useFieldVisible } from "#components/forms/FormStep";
33
import { ShortTextField } from "#components/forms/ShortTextField";
44
import { COUNTRIES } from "#constants/countries";
5-
import { JURISDICTIONS } from "#constants/jurisdictions";
5+
import { JURISDICTION_OPTIONS } from "#constants/jurisdictions";
66
import { defineStep } from "#lib/forms/defineStep";
77
import { nameOrFallback } from "#lib/forms/resolveStepContent";
88

@@ -33,12 +33,7 @@ export const birthplaceStep = defineStep({
3333
name="birthplaceState"
3434
label="State"
3535
placeholder="Select a state"
36-
options={Object.entries(JURISDICTIONS).map(
37-
([id, jurisdiction]) => ({
38-
label: jurisdiction.name,
39-
value: id,
40-
}),
41-
)}
36+
options={JURISDICTION_OPTIONS}
4237
/>
4338
)}
4439
</FormStep>

web/src/content/forms/court-order-ma-minor/steps/CoGuardianStep.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { PhoneField } from "#components/forms/PhoneField";
1010
import { ShortTextField } from "#components/forms/ShortTextField";
1111
import { YesNoField } from "#components/forms/YesNoField";
12-
import { JURISDICTIONS } from "#constants/jurisdictions";
12+
import { JURISDICTION_OPTIONS } from "#constants/jurisdictions";
1313
import { defineStep } from "#lib/forms/defineStep";
1414
import { nameOrFallback } from "#lib/forms/resolveStepContent";
1515

@@ -85,9 +85,9 @@ function CoGuardianStateField() {
8585
errorMessage={error?.message}
8686
menuTrigger="focus"
8787
>
88-
{Object.entries(JURISDICTIONS).map(([id, jurisdiction]) => (
89-
<ComboBoxItem key={id} id={id}>
90-
{jurisdiction.name}
88+
{JURISDICTION_OPTIONS.map((option) => (
89+
<ComboBoxItem key={option.value} id={option.value}>
90+
{option.label}
9191
</ComboBoxItem>
9292
))}
9393
</ComboBox>

web/src/content/forms/court-order-ma-minor/steps/GuardianStep.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { PhoneField } from "#components/forms/PhoneField";
1010
import { ShortTextField } from "#components/forms/ShortTextField";
1111
import { YesNoField } from "#components/forms/YesNoField";
12-
import { JURISDICTIONS } from "#constants/jurisdictions";
12+
import { JURISDICTION_OPTIONS } from "#constants/jurisdictions";
1313
import { defineStep } from "#lib/forms/defineStep";
1414
import { nameOrFallback } from "#lib/forms/resolveStepContent";
1515

@@ -78,9 +78,9 @@ function GuardianStateField() {
7878
errorMessage={error?.message}
7979
menuTrigger="focus"
8080
>
81-
{Object.entries(JURISDICTIONS).map(([id, jurisdiction]) => (
82-
<ComboBoxItem key={id} id={id}>
83-
{jurisdiction.name}
81+
{JURISDICTION_OPTIONS.map((option) => (
82+
<ComboBoxItem key={option.value} id={option.value}>
83+
{option.label}
8484
</ComboBoxItem>
8585
))}
8686
</ComboBox>

web/src/content/forms/court-order-ma/steps/BirthplaceStep.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ComboBoxField } from "#components/forms/ComboBoxField";
22
import { FormStep, useFieldVisible } from "#components/forms/FormStep";
33
import { ShortTextField } from "#components/forms/ShortTextField";
44
import { COUNTRIES } from "#constants/countries";
5-
import { JURISDICTIONS } from "#constants/jurisdictions";
5+
import { JURISDICTION_OPTIONS } from "#constants/jurisdictions";
66
import { defineStep } from "#lib/forms/defineStep";
77

88
export const birthplaceStep = defineStep({
@@ -35,12 +35,7 @@ export const birthplaceStep = defineStep({
3535
name="birthplaceState"
3636
label="State"
3737
placeholder="Select a state"
38-
options={Object.entries(JURISDICTIONS).map(
39-
([id, jurisdiction]) => ({
40-
label: jurisdiction.name,
41-
value: id,
42-
}),
43-
)}
38+
options={JURISDICTION_OPTIONS}
4439
/>
4540
)}
4641
</FormStep>

0 commit comments

Comments
 (0)