Skip to content

Commit 1590c1d

Browse files
committed
Working form to add email
1 parent 9aec5b4 commit 1590c1d

File tree

1 file changed

+7
-34
lines changed

1 file changed

+7
-34
lines changed

src/commands/members/add-email-form.ts

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,36 @@
1-
import {flow, pipe} from 'fp-ts/lib/function';
1+
import {pipe} from 'fp-ts/lib/function';
22
import * as E from 'fp-ts/Either';
33
import {html, safe, toLoggedInContent} from '../../types/html';
44
import {User} from '../../types';
55
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';
116

127
type ViewModel = {
138
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.
179
};
1810

1911
const renderForm = (viewModel: ViewModel) =>
2012
pipe(
2113
html`
2214
<h1>Add email</h1>
23-
<form action="?next=/member/${viewModel.memberNumber}" method="post">
15+
<form action="?next=/member/${viewModel.user.memberNumber}" method="post">
2416
<label for="email">Email address</label>
2517
<input type="email" name="email" id="email" />
2618
<input
2719
type="hidden"
2820
name="memberNumber"
29-
value="${viewModel.memberNumber}"
21+
value="${viewModel.user.memberNumber}"
3022
/>
3123
<button type="submit">Add email</button>
3224
</form>
3325
`,
3426
toLoggedInContent(safe('Add email'))
3527
);
3628

37-
const paramsCodec = t.strict({
38-
member: tt.NumberFromString,
39-
});
40-
4129
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+
});
6134

6235
export const addEmailForm: Form<ViewModel> = {
6336
renderForm,

0 commit comments

Comments
 (0)