Skip to content

Commit 78a33ee

Browse files
committed
refactor: made checkbox usage more in-line with codebase usage
1 parent c6cfbab commit 78a33ee

File tree

2 files changed

+58
-48
lines changed
  • src

2 files changed

+58
-48
lines changed

src/back-end/lib/resources/user.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
nullRequestBodyHandler,
1111
wrapRespond
1212
} from "back-end/lib/server";
13-
1413
import { validateFileRecord, validateUserId } from "back-end/lib/validation";
1514
import { get, isBoolean } from "lodash";
1615
import { getString } from "shared/lib";

src/front-end/typescript/lib/pages/user/list.tsx

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,17 @@ export interface State {
4747
};
4848
}
4949

50-
type ToggleableUserType = UserType.Vendor | UserType.Government;
51-
5250
type InnerMsg =
5351
| ADT<"onInitResponse", TableUser[]>
5452
| ADT<"table", Table.Msg>
5553
| ADT<"showExportModal">
5654
| ADT<"hideExportModal">
57-
| ADT<"userTypeCheckbox", { userType: ToggleableUserType; msg: Checkbox.Msg }>
58-
| ADT<
59-
"fieldCheckbox",
60-
{ field: keyof State["fieldCheckboxes"]; msg: Checkbox.Msg }
61-
>
55+
| ADT<"userTypeCheckboxGovernment", Checkbox.Msg>
56+
| ADT<"userTypeCheckboxVendor", Checkbox.Msg>
57+
| ADT<"fieldCheckboxFirstName", Checkbox.Msg>
58+
| ADT<"fieldCheckboxLastName", Checkbox.Msg>
59+
| ADT<"fieldCheckboxEmail", Checkbox.Msg>
60+
| ADT<"fieldCheckboxOrganizationName", Checkbox.Msg>
6261
| ADT<"exportContactList">
6362
| ADT<"exportComplete">;
6463

@@ -144,29 +143,27 @@ function baseInit(): component_.base.InitReturnValue<State, Msg> {
144143
...component_.cmd.mapMany(tableCmds, (msg) => adt("table", msg) as Msg),
145144
...component_.cmd.mapMany(
146145
govCheckboxCmds,
147-
(msg) =>
148-
adt("userTypeCheckbox", { userType: UserType.Government, msg }) as Msg
146+
(msg) => adt("userTypeCheckboxGovernment", msg) as Msg
149147
),
150148
...component_.cmd.mapMany(
151149
vendorCheckboxCmds,
152-
(msg) =>
153-
adt("userTypeCheckbox", { userType: UserType.Vendor, msg }) as Msg
150+
(msg) => adt("userTypeCheckboxVendor", msg) as Msg
154151
),
155152
...component_.cmd.mapMany(
156153
firstNameCheckboxCmds,
157-
(msg) => adt("fieldCheckbox", { field: "firstName", msg }) as Msg
154+
(msg) => adt("fieldCheckboxFirstName", msg) as Msg
158155
),
159156
...component_.cmd.mapMany(
160157
lastNameCheckboxCmds,
161-
(msg) => adt("fieldCheckbox", { field: "lastName", msg }) as Msg
158+
(msg) => adt("fieldCheckboxLastName", msg) as Msg
162159
),
163160
...component_.cmd.mapMany(
164161
emailCheckboxCmds,
165-
(msg) => adt("fieldCheckbox", { field: "email", msg }) as Msg
162+
(msg) => adt("fieldCheckboxEmail", msg) as Msg
166163
),
167164
...component_.cmd.mapMany(
168165
organizationNameCheckboxCmds,
169-
(msg) => adt("fieldCheckbox", { field: "organizationName", msg }) as Msg
166+
(msg) => adt("fieldCheckboxOrganizationName", msg) as Msg
170167
)
171168
]
172169
];
@@ -255,27 +252,53 @@ const update: component_.page.Update<State, InnerMsg, Route> = ({
255252
return [state.set("showExportModal", true), []];
256253
case "hideExportModal":
257254
return [state.set("showExportModal", false), []];
258-
case "userTypeCheckbox":
255+
case "userTypeCheckboxGovernment":
259256
return component_.base.updateChild({
260257
state,
261-
childStatePath: ["userTypeCheckboxes", msg.value.userType],
258+
childStatePath: ["userTypeCheckboxes", UserType.Government],
262259
childUpdate: Checkbox.update,
263-
childMsg: msg.value.msg,
264-
mapChildMsg: (value) => ({
265-
tag: "userTypeCheckbox",
266-
value: { userType: msg.value.userType, msg: value }
267-
})
260+
childMsg: msg.value,
261+
mapChildMsg: (value) => adt("userTypeCheckboxGovernment", value)
268262
});
269-
case "fieldCheckbox":
263+
case "userTypeCheckboxVendor":
270264
return component_.base.updateChild({
271265
state,
272-
childStatePath: ["fieldCheckboxes", msg.value.field],
266+
childStatePath: ["userTypeCheckboxes", UserType.Vendor],
273267
childUpdate: Checkbox.update,
274-
childMsg: msg.value.msg,
275-
mapChildMsg: (value) => ({
276-
tag: "fieldCheckbox",
277-
value: { field: msg.value.field, msg: value }
278-
})
268+
childMsg: msg.value,
269+
mapChildMsg: (value) => adt("userTypeCheckboxVendor", value)
270+
});
271+
case "fieldCheckboxFirstName":
272+
return component_.base.updateChild({
273+
state,
274+
childStatePath: ["fieldCheckboxes", "firstName"],
275+
childUpdate: Checkbox.update,
276+
childMsg: msg.value,
277+
mapChildMsg: (value) => adt("fieldCheckboxFirstName", value)
278+
});
279+
case "fieldCheckboxLastName":
280+
return component_.base.updateChild({
281+
state,
282+
childStatePath: ["fieldCheckboxes", "lastName"],
283+
childUpdate: Checkbox.update,
284+
childMsg: msg.value,
285+
mapChildMsg: (value) => adt("fieldCheckboxLastName", value)
286+
});
287+
case "fieldCheckboxEmail":
288+
return component_.base.updateChild({
289+
state,
290+
childStatePath: ["fieldCheckboxes", "email"],
291+
childUpdate: Checkbox.update,
292+
childMsg: msg.value,
293+
mapChildMsg: (value) => adt("fieldCheckboxEmail", value)
294+
});
295+
case "fieldCheckboxOrganizationName":
296+
return component_.base.updateChild({
297+
state,
298+
childStatePath: ["fieldCheckboxes", "organizationName"],
299+
childUpdate: Checkbox.update,
300+
childMsg: msg.value,
301+
mapChildMsg: (value) => adt("fieldCheckboxOrganizationName", value)
279302
});
280303
case "exportContactList": {
281304
// Build query parameters from checkbox states
@@ -428,10 +451,7 @@ const getModal: component_.page.GetModal<State, Msg> = (state) => {
428451
className="mb-0"
429452
state={state.userTypeCheckboxes.GOV}
430453
dispatch={component_.base.mapDispatch(dispatch, (msg) =>
431-
adt("userTypeCheckbox" as const, {
432-
userType: UserType.Government as ToggleableUserType,
433-
msg
434-
})
454+
adt("userTypeCheckboxGovernment" as const, msg)
435455
)}
436456
/>
437457
<Checkbox.view
@@ -441,10 +461,7 @@ const getModal: component_.page.GetModal<State, Msg> = (state) => {
441461
className="mb-0"
442462
state={state.userTypeCheckboxes.VENDOR}
443463
dispatch={component_.base.mapDispatch(dispatch, (msg) =>
444-
adt("userTypeCheckbox" as const, {
445-
userType: UserType.Vendor as ToggleableUserType,
446-
msg
447-
})
464+
adt("userTypeCheckboxVendor" as const, msg)
448465
)}
449466
/>
450467
</div>
@@ -458,10 +475,7 @@ const getModal: component_.page.GetModal<State, Msg> = (state) => {
458475
className="mb-0"
459476
state={state.fieldCheckboxes.firstName}
460477
dispatch={component_.base.mapDispatch(dispatch, (msg) =>
461-
adt("fieldCheckbox" as const, {
462-
field: "firstName" as const,
463-
msg
464-
})
478+
adt("fieldCheckboxFirstName" as const, msg)
465479
)}
466480
/>
467481
<Checkbox.view
@@ -471,7 +485,7 @@ const getModal: component_.page.GetModal<State, Msg> = (state) => {
471485
className="mb-0"
472486
state={state.fieldCheckboxes.lastName}
473487
dispatch={component_.base.mapDispatch(dispatch, (msg) =>
474-
adt("fieldCheckbox" as const, { field: "lastName" as const, msg })
488+
adt("fieldCheckboxLastName" as const, msg)
475489
)}
476490
/>
477491
<Checkbox.view
@@ -481,7 +495,7 @@ const getModal: component_.page.GetModal<State, Msg> = (state) => {
481495
className="mb-0"
482496
state={state.fieldCheckboxes.email}
483497
dispatch={component_.base.mapDispatch(dispatch, (msg) =>
484-
adt("fieldCheckbox" as const, { field: "email" as const, msg })
498+
adt("fieldCheckboxEmail" as const, msg)
485499
)}
486500
/>
487501
<Checkbox.view
@@ -491,10 +505,7 @@ const getModal: component_.page.GetModal<State, Msg> = (state) => {
491505
className="mb-0"
492506
state={state.fieldCheckboxes.organizationName}
493507
dispatch={component_.base.mapDispatch(dispatch, (msg) =>
494-
adt("fieldCheckbox" as const, {
495-
field: "organizationName" as const,
496-
msg
497-
})
508+
adt("fieldCheckboxOrganizationName" as const, msg)
498509
)}
499510
/>
500511
</div>

0 commit comments

Comments
 (0)