Skip to content

Commit

Permalink
Demo tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnaab committed Feb 29, 2024
1 parent ff23b5f commit 30cd10b
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 84 deletions.
146 changes: 75 additions & 71 deletions packages/design/src/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,82 +147,86 @@ export default function Form({
}
})}
>
<fieldset className="usa-fieldset">
<legend className="usa-legend usa-legend--large">
Request to Change Name
</legend>
<div className="usa-form-group">
{false && (
<fieldset className="usa-fieldset">
<legend className="usa-legend usa-legend--large">
Request to Change Name
</legend>
<div className="usa-form-group">
<fieldset className="usa-fieldset">
<legend className="usa-legend usa-legend--large">
County where you live
</legend>
<label className="usa-label">Name of your county *</label>
<input
className="usa-input"
id="input-users1_address_line_one"
name="users1_address_line_one"
type="text"
aria-describedby="input-message-users1_address_line_one"
value=""
/>
</fieldset>
<div className="usa-form-group">
<fieldset className="usa-fieldset">
<legend className="usa-legend usa-legend--large">
County where you live
</legend>
<label className="usa-label">
Name of your county *
</label>
<input
className="usa-input"
id="input-users1_address_line_one"
name="users1_address_line_one"
type="text"
aria-describedby="input-message-users1_address_line_one"
value=""
/>
</fieldset>
</div>
</div>
</div>

<div className="usa-form-group">
<div className="usa-form-group">
<fieldset className="usa-fieldset">
<legend className="usa-legend usa-legend--large">
Your current name
</legend>
<label className="usa-label">First name *</label>
<input
className="usa-input"
id="input-users1_first_name"
name="users1_first_name"
type="text"
aria-describedby="input-message-users1_first_name"
value=""
/>
<label className="usa-label">Middle name *</label>
<input
className="usa-input"
id="input-users1_middle_name"
name="users1_middle_name"
type="text"
aria-describedby="input-message-users1_middle_name"
value=""
/>
<label className="usa-label">Last name *</label>
<input
className="usa-input"
id="input-users1_last_name"
name="users1_last_name"
type="text"
aria-describedby="input-message-users1_last_name"
value=""
/>
</fieldset>
<fieldset className="usa-fieldset">
<p>
To ask the court to change your name, you must fill out
this form, and:
</p>
<ul>
<li>
Attach a certified copy of your birth certificate and
a copy of your photo ID, and
</li>
<li>
File your form and attachements in the same county
where you live.
</li>
</ul>
</fieldset>
<div className="usa-form-group">
<fieldset className="usa-fieldset">
<legend className="usa-legend usa-legend--large">
Your current name
</legend>
<label className="usa-label">First name *</label>
<input
className="usa-input"
id="input-users1_first_name"
name="users1_first_name"
type="text"
aria-describedby="input-message-users1_first_name"
value=""
/>
<label className="usa-label">Middle name *</label>
<input
className="usa-input"
id="input-users1_middle_name"
name="users1_middle_name"
type="text"
aria-describedby="input-message-users1_middle_name"
value=""
/>
<label className="usa-label">Last name *</label>
<input
className="usa-input"
id="input-users1_last_name"
name="users1_last_name"
type="text"
aria-describedby="input-message-users1_last_name"
value=""
/>
</fieldset>
<fieldset className="usa-fieldset">
<p>
To ask the court to change your name, you must fill
out this form, and:
</p>
<ul>
<li>
Attach a certified copy of your birth certificate
and a copy of your photo ID, and
</li>
<li>
File your form and attachements in the same county
where you live.
</li>
</ul>
</fieldset>
</div>
</div>
</div>
</fieldset>
</fieldset>
)}

<fieldset className="usa-fieldset">
{prompt.parts.map((part, index) => {
Expand Down
13 changes: 7 additions & 6 deletions packages/documents/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
addFormOutput,
addFormElements,
addFormElementMap,
updateFormSummary,
} from '@atj/forms';
import { PDFDocument, getDocumentFieldData } from './pdf';
import { getSuggestedFormElementsFromCache } from './suggestions';
Expand All @@ -23,12 +24,12 @@ export const addDocument = async (
const cachedPdf = await getSuggestedFormElementsFromCache(fileDetails.data);

if (cachedPdf) {
const withElements = addFormElementMap(
form,
cachedPdf.elements,
cachedPdf.root
);
const updatedForm = addFormOutput(withElements, {
form = updateFormSummary(form, {
title: cachedPdf.title,
description: '',
});
form = addFormElementMap(form, cachedPdf.elements, cachedPdf.root);
const updatedForm = addFormOutput(form, {
data: fileDetails.data,
path: fileDetails.name,
fields: cachedPdf.outputs,
Expand Down
2 changes: 1 addition & 1 deletion packages/documents/src/pdf/al_name_change.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"raw_text": "Request to Change Name Case Number: (the clerk fills this in) \n8/08 (For An Adult) \n<question>In the Probate Court of (county): County, Alabama <input label=County_Name1 instructions={field_dict['field_instructions']}></question>\n<question>Your current name: <input label=Current_First_Name1 instructions={field_dict['field_instructions']}><input label=Current_Middle_Name1 instructions={field_dict['field_instructions']}><input label=Current_Last_Name1 instructions={field_dict['field_instructions']}></question>\nfirst middle last \nTo ask the court to change your name, you must fill out this form, and: \n\u2022 Attach a certified copy of your birth certificate and a copy of your photo ID, and \n\u2022 File your form and attachments in the same county where you live. \nI declare that the following information is true: \n<question>My current name is: <input label=Current_First_Name2 instructions={field_dict['field_instructions']}><input label=Current_Middle_Name2 instructions={field_dict['field_instructions']}><input label=Current_Last_Name2 instructions={field_dict['field_instructions']}></question>\nfirst middle last \n<question>My address is: <input label=Street_Address instructions={field_dict['field_instructions']}><input label=City instructions={field_dict['field_instructions']}><input label=State instructions={field_dict['field_instructions']}><input label=Zip instructions={field_dict['field_instructions']}></question>\nstreet city state zip \n<question>My phone numbers are (home): (work): <input label=Home_Phone instructions={field_dict['field_instructions']}><input label=Work_Phone instructions={field_dict['field_instructions']}></question>\n<question>My date of birth is (mm/dd/yyyy): <input label=DOB instructions={field_dict['field_instructions']}></question>\n<question>My name at birth was: <input label=Birth_First_Name instructions={field_dict['field_instructions']}><input label=Birth_Middle_Name instructions={field_dict['field_instructions']}><input label=Birth_Last_Name instructions={field_dict['field_instructions']}></question>\nfirst middle last \n<question>I am an adult (19 or older), of sound mind, and live in (name of Alabama county): <input label=County_Name2 instructions={field_dict['field_instructions']}></question>\n<question>The attached copy of my photo ID is my (check one): <button type=radio> Driver\u2019s license, # <input label=PhotoID instructions=NA><input label=DL# instructions={field_dict['field_instructions']}></question>\n<question><input label=PhotoID instructions=NA><button type=radio> Non-driver\u2019s photo, ID #: <input label=ID# instructions={field_dict['field_instructions']}></question>\n<question>I ask the court to change my name because (explain why you want to change your name): <input label=Why_change_name1 instructions={field_dict['field_instructions']}></question>\n<question><input label=Why_change_name2 instructions={field_dict['field_instructions']}></question>\n<question><input label=Why_change_name3 instructions={field_dict['field_instructions']}></question>\n<question>I want my new name to be: <input label=New_First_Name instructions={field_dict['field_instructions']}><input label=New_Middle_Name instructions={field_dict['field_instructions']}><input label=New_Last_Name instructions={field_dict['field_instructions']}></question>\nfirst middle last \nI also declare: \n\u2022 I am not now facing criminal charges, nor am I involved in any other court case. \n\u2022 I have never been convicted of a criminal sex offense (as defined in Alabama Code \u00a7 15-20-21), \na crime of moral turpitude, or a felony. \n\u2022 I am not asking to change my name to avoid paying my debts or to commit fraud. \n\u2022 I swear that all of the information I have provided above is complete and accurate. \nI ask the court to grant this request and to issue an order changing my name. \nSign below in front of a notary: \n Date: \nNotary fills out below\u2014 \nSworn to and subscribed before me, the undersigned authority, \nBy (Print name of notary): \nOn this date: (Notary\u2019s seal here) \n / / \n Notary signs here Date notary\u2019s commission expires \nRev. 8/08 \uf8e9 2008 Alabama State Bar ",
"title": "",
"title": "PS-12 - Request to Change Name (For An Adult)",
"description": "",
"elements": [
{
Expand Down
6 changes: 5 additions & 1 deletion packages/documents/src/pdf/extract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as pdfLib from 'pdf-lib';

import type { DocumentFieldMap, DocumentFieldValue } from '@atj/forms';
import {
createForm,
type DocumentFieldMap,
type DocumentFieldValue,
} from '@atj/forms';

export const getDocumentFieldData = async (
pdfBytes: Uint8Array
Expand Down
31 changes: 27 additions & 4 deletions packages/documents/src/pdf/mock-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { type InputElement } from '@atj/forms/src/config/elements/input';

import json from './al_name_change.json' assert { type: 'json' };
import { FieldsetElement } from '@atj/forms/src/config/elements/fieldset';
import { ParagraphElement } from '@atj/forms/src/config/elements/paragraph';

const TxInput = z.object({
input_type: z.literal('Tx'),
Expand Down Expand Up @@ -93,6 +94,7 @@ export type ParsedPdf = {
elements: FormElementMap;
outputs: DocumentFieldMap; // to populate FormOutput
root: FormElementId;
title: string;
};

export const parseAlabamaNameChangeForm = (): ParsedPdf => {
Expand All @@ -101,24 +103,45 @@ export const parseAlabamaNameChangeForm = (): ParsedPdf => {
elements: {},
outputs: {},
root: 'root',
title: extracted.title,
};
const rootSequence: FormElementId[] = [];
for (const element of extracted.elements) {
const fieldsetElements: FormElementId[] = [];
if (element.inputs.length === 0) {
parsedPdf.elements[element.id] = {
type: 'paragraph',
id: element.id,
default: {
text: '',
maxLength: 2048,
},
data: {
text: element.element_params.text,
maxLength: 2048,
},
required: false,
} satisfies ParagraphElement;
continue;
}
for (const input of element.inputs) {
if (input.input_type === 'Tx') {
const id = PdfFieldMap[input.input_params.output_id];
console.log(input.input_params.output_id.toLowerCase(), id);
fieldsetElements.push(id);
parsedPdf.elements[id] = {
type: 'input',
id,
default: {} as unknown as any,
default: {
required: false,
label: '',
initial: '',
maxLength: 128,
},
data: {
label: input.input_params.instructions,
},
required: false,
} satisfies FormElement<InputElement>;
} satisfies InputElement;
fieldsetElements.push(id);
parsedPdf.outputs[id] = {
type: 'TextField',
name: input.input_params.text,
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/src/config/elements/sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type FormElementConfig } from '..';
import { type FormElement, type FormElementId } from '../../element';
import { createPromptForElement } from '../../pattern';
import { safeZodParse } from '../../util/zod';
import { getFormElement, getFormElementMap } from '../..';
import { getFormElement } from '../..';

export type SequenceElement = FormElement<{
elements: FormElementId[];
Expand Down
10 changes: 10 additions & 0 deletions packages/forms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,13 @@ export const addFormOutput = (form: FormDefinition, document: FormOutput) => {
export const getFormElement = (form: FormDefinition, id: FormElementId) => {
return form.elements[id];
};

export const updateFormSummary = (
form: FormDefinition,
summary: FormSummary
) => {
return {
...form,
summary,
};
};

0 comments on commit 30cd10b

Please sign in to comment.