|
1 | | -import {flow, pipe} from 'fp-ts/lib/function'; |
| 1 | +import {pipe} from 'fp-ts/lib/function'; |
2 | 2 | import * as E from 'fp-ts/Either'; |
3 | 3 | import {html, safe, toLoggedInContent} from '../../types/html'; |
4 | 4 | import {User} from '../../types'; |
5 | 5 | import {Form} from '../../types/form'; |
6 | | -import * as t from 'io-ts'; |
7 | | -import * as tt from 'io-ts-types'; |
8 | | -import {formatValidationErrors} from 'io-ts-reporters'; |
9 | | -import {failureWithStatus} from '../../types/failure-with-status'; |
10 | | -import {StatusCodes} from 'http-status-codes'; |
11 | 6 |
|
12 | 7 | type ViewModel = { |
13 | 8 | user: User; // The user logged in |
14 | | - memberNumber: number; // The user we are updating the email for. |
15 | | - |
16 | | - // TODO - Show the emails already registered for this user. |
17 | 9 | }; |
18 | 10 |
|
19 | 11 | const renderForm = (viewModel: ViewModel) => |
20 | 12 | pipe( |
21 | 13 | html` |
22 | 14 | <h1>Add email</h1> |
23 | | - <form action="?next=/member/${viewModel.memberNumber}" method="post"> |
| 15 | + <form action="?next=/member/${viewModel.user.memberNumber}" method="post"> |
24 | 16 | <label for="email">Email address</label> |
25 | 17 | <input type="email" name="email" id="email" /> |
26 | 18 | <input |
27 | 19 | type="hidden" |
28 | 20 | name="memberNumber" |
29 | | - value="${viewModel.memberNumber}" |
| 21 | + value="${viewModel.user.memberNumber}" |
30 | 22 | /> |
31 | 23 | <button type="submit">Add email</button> |
32 | 24 | </form> |
33 | 25 | `, |
34 | 26 | toLoggedInContent(safe('Add email')) |
35 | 27 | ); |
36 | 28 |
|
37 | | -const paramsCodec = t.strict({ |
38 | | - member: tt.NumberFromString, |
39 | | -}); |
40 | | - |
41 | 29 | const constructForm: Form<ViewModel>['constructForm'] = |
42 | | - input => |
43 | | - ({user}) => |
44 | | - pipe( |
45 | | - input, |
46 | | - paramsCodec.decode, |
47 | | - E.mapLeft( |
48 | | - flow( |
49 | | - formatValidationErrors, |
50 | | - failureWithStatus( |
51 | | - 'Parameters submitted to the form were invalid', |
52 | | - StatusCodes.BAD_REQUEST |
53 | | - ) |
54 | | - ) |
55 | | - ), |
56 | | - E.map(params => ({ |
57 | | - user, |
58 | | - memberNumber: params.member, |
59 | | - })) |
60 | | - ); |
| 30 | + _input => |
| 31 | + ({user}) => E.right({ |
| 32 | + user |
| 33 | + }); |
61 | 34 |
|
62 | 35 | export const addEmailForm: Form<ViewModel> = { |
63 | 36 | renderForm, |
|
0 commit comments