Include the Form.person in the form selector.
[ustaxviewer.git] / src / TaxReturnView.tsx
1 // Copyright 2020 Blue Static <https://www.bluestatic.org>
2 // This program is free software licensed under the GNU General Public License,
3 // version 3.0. The full text of the license can be found in LICENSE.txt.
4 // SPDX-License-Identifier: GPL-3.0-only
5
6 import { createMemo, createState } from 'solid-js';
7 import { For } from 'solid-js/dom';
8 import { Form, Person, TaxReturn } from 'ustaxlib/core';
9
10 import FormView from './FormView';
11
12 const S = require('./TaxReturnView.css');
13
14 interface Props {
15 tr: TaxReturn;
16 }
17
18 export default function TaxReturnView(props: Props) {
19 const [ state, setState ] = createState({ form: props.tr.forms[0] });
20
21 const changeForm = e => {
22 setState({ form: props.tr.forms[e.target.value] });
23 };
24
25 const formIndexToName = createMemo(() => props.tr.forms.map((form, i) => {
26 let name = form.name;
27 const person = form.person();
28 if (person !== undefined) {
29 const personName = person === Person.joint ? 'Joint' : person.name;
30 name += ` (${personName})`;
31 }
32 return [i, name];
33 }));
34
35 const formSelector = (
36 <select onchange={changeForm}>
37 <For each={formIndexToName()}>
38 {tuple => (<option value={tuple[0]}>{tuple[1]}</option>)}
39 </For>
40 </select>
41 );
42
43 return (
44 <div>
45 <div class={S.header}>
46 <h1>ustaxlib Federal {props.tr.year}</h1>
47 {formSelector}
48 </div>
49
50 <FormView tr={props.tr} form={state.form as Form<any>} />
51 </div>
52 );
53 }
54