@@ -7,6 +7,13 @@ import TextInput from "../Shared/TextInput";
77import SubmitButton from "../Shared/SubmitButton" ;
88import CurrencyInput from "../Shared/CurrencyInput" ;
99import NumberInput from "../Shared/NumberInput" ;
10+ import PostingListContainer , {
11+ PostingRecord ,
12+ } from "../TransactionForm/PostingListContainer" ;
13+ import MetaListContainer , {
14+ MetaRecord ,
15+ } from "../TransactionForm/MetaListContainer" ;
16+ import HeaderLine from "../Shared/HeaderLine" ;
1017
1118export enum FieldType {
1219 str = "str" ,
@@ -15,6 +22,9 @@ export enum FieldType {
1522 date = "date" ,
1623 currency = "currency" ,
1724 account = "account" ,
25+ postings = "postings" ,
26+ meta = "meta" ,
27+ header = "header" ,
1828}
1929
2030export interface BaseField {
@@ -52,7 +62,23 @@ export interface AccountField extends BaseField {
5262 readonly default ?: string ;
5363}
5464
55- export type Field = OtherField | CurrencyField | FileField | AccountField ;
65+ export interface PostingsField extends BaseField {
66+ readonly type : FieldType . postings ;
67+ readonly default ?: Array < PostingRecord > ;
68+ }
69+
70+ export interface MetaField extends BaseField {
71+ readonly type : FieldType . postings ;
72+ readonly default ?: Array < MetaRecord > ;
73+ }
74+
75+ export type Field =
76+ | OtherField
77+ | CurrencyField
78+ | FileField
79+ | AccountField
80+ | PostingsField
81+ | MetaField ;
5682
5783export interface Props {
5884 readonly action ?: string ;
@@ -62,6 +88,7 @@ export interface Props {
6288 readonly files : Array < string > ;
6389 readonly currencies : Array < string > ;
6490 readonly accounts : Array < string > ;
91+ readonly accountCurrencies : Record < string , Array < string > > ;
6592 readonly defaultDate : string ;
6693 readonly errors ?: Array < string > ;
6794 readonly submit ?: string ;
@@ -72,6 +99,7 @@ interface FieldProps {
7299 readonly files : Array < string > ;
73100 readonly currencies : Array < string > ;
74101 readonly accounts : Array < string > ;
102+ readonly accountCurrencies : Record < string , Array < string > > ;
75103 readonly defaultDate : string ;
76104}
77105
@@ -81,6 +109,7 @@ const FormField: FunctionComponent<FieldProps> = ({
81109 files,
82110 accounts,
83111 defaultDate,
112+ accountCurrencies,
84113} : FieldProps ) => {
85114 let initialValue = field . default ;
86115 if ( window . history . state ?. [ field . name ] !== undefined ) {
@@ -158,7 +187,7 @@ const FormField: FunctionComponent<FieldProps> = ({
158187 label = { displayName }
159188 name = { field . name }
160189 currencies = { currencies }
161- initialValue = { initialValue }
190+ initialValue = { initialValue as string }
162191 error = { field . error }
163192 multiple = { field . multiple }
164193 creatable = { field . creatable }
@@ -216,6 +245,31 @@ const FormField: FunctionComponent<FieldProps> = ({
216245 } }
217246 />
218247 ) ;
248+ case FieldType . postings :
249+ return (
250+ < PostingListContainer
251+ initialPostings = { initialValue as Array < PostingRecord > }
252+ name = { field . name }
253+ accounts = { accounts }
254+ accountCurrencies = { accountCurrencies }
255+ defaultCurrencies = { currencies }
256+ required = { field . required }
257+ error = { field . error }
258+ // TODO: handle on change and the history
259+ />
260+ ) ;
261+ case FieldType . meta :
262+ return (
263+ < MetaListContainer
264+ initialMeta = { initialValue as Array < MetaRecord > }
265+ name = { field . name }
266+ required = { field . required }
267+ error = { field . error }
268+ // TODO: handle on change and the history
269+ />
270+ ) ;
271+ case FieldType . header :
272+ return < HeaderLine title = { displayName } /> ;
219273 }
220274} ;
221275
@@ -227,6 +281,7 @@ const Form: FunctionComponent<Props> = ({
227281 files,
228282 currencies,
229283 accounts,
284+ accountCurrencies,
230285 defaultDate,
231286 errors,
232287 submit,
@@ -240,6 +295,7 @@ const Form: FunctionComponent<Props> = ({
240295 currencies = { currencies }
241296 files = { files }
242297 accounts = { accounts }
298+ accountCurrencies = { accountCurrencies }
243299 defaultDate = { defaultDate }
244300 />
245301 ) ) }
0 commit comments