-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wire PDF field extraction to "import PDF" function.
- Loading branch information
1 parent
79b0ce3
commit 14230f3
Showing
13 changed files
with
214 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../packages/documents/samples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,85 @@ | ||
import { Form, Question, addQuestions } from '@atj/forms'; | ||
import { PDFDocument } from './pdf'; | ||
|
||
export type DocumentTemplate = PDFDocument; | ||
|
||
export type DocumentFieldValue = | ||
| { | ||
type: 'TextField'; | ||
name: string; | ||
label: string; | ||
value: string; | ||
maxLength?: number; | ||
required: boolean; | ||
} | ||
| { | ||
type: 'CheckBox'; | ||
name: string; | ||
label: string; | ||
value: boolean; | ||
required: boolean; | ||
} | ||
| { | ||
type: 'Dropdown'; | ||
name: string; | ||
label: string; | ||
value: string[]; | ||
required: boolean; | ||
} | ||
| { | ||
type: 'OptionList'; | ||
name: string; | ||
label: string; | ||
value: string[]; | ||
required: boolean; | ||
} | ||
| { | ||
type: 'not-supported'; | ||
name: string; | ||
error: string; | ||
}; | ||
|
||
export type DocumentFieldMap = Record<string, DocumentFieldValue>; | ||
|
||
export const addDocumentFieldsToForm = ( | ||
form: Form, | ||
fields: DocumentFieldMap | ||
) => { | ||
const questions: Question[] = []; | ||
Object.entries(fields).map(([key, field]) => { | ||
if (field.type === 'CheckBox') { | ||
questions.push({ | ||
id: field.name, | ||
text: field.label, | ||
initial: field.value, | ||
required: field.required, | ||
}); | ||
} else if (field.type === 'OptionList') { | ||
questions.push({ | ||
id: field.name, | ||
text: field.label, | ||
initial: field.value, | ||
required: field.required, | ||
}); | ||
} else if (field.type === 'Dropdown') { | ||
questions.push({ | ||
id: field.name, | ||
text: field.label, | ||
initial: field.value, | ||
required: field.required, | ||
}); | ||
} else if (field.type === 'TextField') { | ||
questions.push({ | ||
id: field.name, | ||
text: field.label, | ||
initial: field.value, | ||
required: field.required, | ||
}); | ||
} else if (field.type === 'not-supported') { | ||
console.error(`Skipping field: ${field.error}`); | ||
} else { | ||
const _exhaustiveCheck: never = field; | ||
} | ||
}); | ||
return addQuestions(form, questions); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './document'; | ||
export * from './pdf'; | ||
export * from './suggestions'; |
Oops, something went wrong.