Skip to content

Commit fc50f94

Browse files
committed
Re-structure registration form so that logic is clearer and standardise some action type naming
1 parent db41c4f commit fc50f94

File tree

10 files changed

+260
-222
lines changed

10 files changed

+260
-222
lines changed

src/IsaacAppTypes.tsx

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as ApiTypes from "./IsaacApiTypes";
22
import {ACTION_TYPE, DOCUMENT_TYPE, EXAM_BOARD, TAG_ID} from "./app/services/constants";
33

4+
45
export type Action =
56
| {type: ACTION_TYPE.TEST_ACTION}
67

@@ -10,28 +11,27 @@ export type Action =
1011
| {type: ACTION_TYPE.API_GONE_AWAY}
1112

1213
| {type: ACTION_TYPE.USER_UPDATE_REQUEST}
13-
| {type: ACTION_TYPE.USER_UPDATE_FAILURE}
14-
| {type: ACTION_TYPE.USER_DETAILS_UPDATE}
15-
| {type: ACTION_TYPE.USER_DETAILS_UPDATE_SUCCESS}
16-
| {type: ACTION_TYPE.USER_DETAILS_UPDATE_FAILURE; errorMessage: string}
14+
| {type: ACTION_TYPE.USER_UPDATE_RESPONSE_FAILURE}
15+
| {type: ACTION_TYPE.USER_DETAILS_UPDATE_REQUEST}
16+
| {type: ACTION_TYPE.USER_DETAILS_UPDATE_RESPONSE_SUCCESS; user: ApiTypes.RegisteredUserDTO}
17+
| {type: ACTION_TYPE.USER_DETAILS_UPDATE_RESPONSE_FAILURE; errorMessage: string}
1718
| {type: ACTION_TYPE.USER_AUTH_SETTINGS_REQUEST}
18-
| {type: ACTION_TYPE.USER_AUTH_SETTINGS_SUCCESS; userAuthSettings: ApiTypes.UserAuthenticationSettingsDTO}
19-
| {type: ACTION_TYPE.USER_AUTH_SETTINGS_FAILURE; errorMessage: string}
19+
| {type: ACTION_TYPE.USER_AUTH_SETTINGS_RESPONSE_SUCCESS; userAuthSettings: ApiTypes.UserAuthenticationSettingsDTO}
20+
| {type: ACTION_TYPE.USER_AUTH_SETTINGS_RESPONSE_FAILURE; errorMessage: string}
2021
| {type: ACTION_TYPE.USER_PREFERENCES_REQUEST}
21-
| {type: ACTION_TYPE.USER_PREFERENCES_SUCCESS; userPreferences: UserPreferencesDTO}
22-
| {type: ACTION_TYPE.USER_PREFERENCES_FAILURE; errorMessage: string}
22+
| {type: ACTION_TYPE.USER_PREFERENCES_RESPONSE_SUCCESS; userPreferences: UserPreferencesDTO}
23+
| {type: ACTION_TYPE.USER_PREFERENCES_RESPONSE_FAILURE; errorMessage: string}
2324

2425
| {type: ACTION_TYPE.USER_LOG_IN_REQUEST; provider: ApiTypes.AuthenticationProvider}
2526
| {type: ACTION_TYPE.USER_LOG_IN_RESPONSE_SUCCESS; user: ApiTypes.RegisteredUserDTO}
26-
| {type: ACTION_TYPE.USER_LOG_IN_FAILURE; errorMessage: string}
27+
| {type: ACTION_TYPE.USER_LOG_IN_RESPONSE_FAILURE; errorMessage: string}
2728
| {type: ACTION_TYPE.USER_PASSWORD_RESET_REQUEST}
2829
| {type: ACTION_TYPE.USER_INCOMING_PASSWORD_RESET_REQUEST}
29-
| {type: ACTION_TYPE.USER_INCOMING_PASSWORD_RESET_REQUEST_SUCCESS}
30-
| {type: ACTION_TYPE.USER_INCOMING_PASSWORD_RESET_REQUEST_FAILURE; errorMessage: string}
31-
| {type: ACTION_TYPE.USER_PASSWORD_RESET_REQUEST_SUCCESS}
32-
| {type: ACTION_TYPE.USER_PASSWORD_RESET}
33-
| {type: ACTION_TYPE.USER_PASSWORD_RESET_SUCCESS}
34-
| {type: ACTION_TYPE.USER_PASSWORD_RESET_FAILURE; errorMessage: string}
30+
| {type: ACTION_TYPE.USER_INCOMING_PASSWORD_RESET_SUCCESS}
31+
| {type: ACTION_TYPE.USER_INCOMING_PASSWORD_RESET_FAILURE; errorMessage: string}
32+
| {type: ACTION_TYPE.USER_PASSWORD_RESET_REQUEST}
33+
| {type: ACTION_TYPE.USER_PASSWORD_RESET_RESPONSE_SUCCESS}
34+
| {type: ACTION_TYPE.USER_PASSWORD_RESET_RESPONSE_FAILURE; errorMessage: string}
3535
| {type: ACTION_TYPE.USER_LOG_OUT_REQUEST}
3636
| {type: ACTION_TYPE.USER_LOG_OUT_RESPONSE_SUCCESS}
3737
| {type: ACTION_TYPE.AUTHENTICATION_REQUEST_REDIRECT; provider: string}
@@ -45,8 +45,8 @@ export type Action =
4545
| {type: ACTION_TYPE.USER_REQUEST_EMAIL_VERIFICATION_RESPONSE_FAILURE}
4646

4747
| {type: ACTION_TYPE.EMAIL_AUTHENTICATION_REQUEST}
48-
| {type: ACTION_TYPE.EMAIL_AUTHENTICATION_SUCCESS}
49-
| {type: ACTION_TYPE.EMAIL_AUTHENTICATION_FAILURE; errorMessage: string}
48+
| {type: ACTION_TYPE.EMAIL_AUTHENTICATION_RESPONSE_SUCCESS}
49+
| {type: ACTION_TYPE.EMAIL_AUTHENTICATION_RESPONSE_FAILURE; errorMessage: string}
5050

5151
| {type: ACTION_TYPE.CONSTANTS_UNITS_REQUEST}
5252
| {type: ACTION_TYPE.CONSTANTS_UNITS_RESPONSE_FAILURE}
@@ -76,9 +76,9 @@ export type Action =
7676
| {type: ACTION_TYPE.GAMEBOARD_REQUEST; gameboardId: string | null}
7777
| {type: ACTION_TYPE.GAMEBOARD_RESPONSE_SUCCESS; gameboard: ApiTypes.GameboardDTO}
7878

79-
| {type: ACTION_TYPE.CONTACT_FORM_SEND}
80-
| {type: ACTION_TYPE.CONTACT_FORM_SEND_SUCCESS}
81-
| {type: ACTION_TYPE.CONTACT_FORM_SEND_FAILURE; errorMessage: string}
79+
| {type: ACTION_TYPE.CONTACT_FORM_SEND_REQUEST}
80+
| {type: ACTION_TYPE.CONTACT_FORM_SEND_RESPONSE_SUCCESS}
81+
| {type: ACTION_TYPE.CONTACT_FORM_SEND_RESPONSE_FAILURE; errorMessage: string}
8282

8383
| {type: ACTION_TYPE.ASSIGNMENTS_REQUEST}
8484
| {type: ACTION_TYPE.ASSIGNMENTS_RESPONSE_SUCCESS; assignments: ApiTypes.AssignmentDTO[]}
@@ -137,6 +137,7 @@ export type LoggedInUser = {loggedIn: true} & ApiTypes.RegisteredUserDTO | {logg
137137
export interface ValidationUser extends ApiTypes.RegisteredUserDTO {
138138
password: string | null;
139139
}
140+
export type LoggedInValidationUser = ValidationUser & {loggedIn: true} | {loggedIn: false};
140141

141142
export interface LinkInfo {
142143
title: string;
@@ -157,8 +158,6 @@ export interface School {
157158
dataSource: string;
158159
}
159160

160-
export type LoggedInValidationUser = ValidationUser & {loggedIn: true} | {loggedIn: false};
161-
162161
export interface Toast {
163162
color: string;
164163
title: string;

src/app/components/elements/UserDetails.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {CardBody, Col, CustomInput, FormFeedback, FormGroup, Input, Label, Row} from "reactstrap";
22
import {School, UserExamPreferences, ValidationUser} from "../../../IsaacAppTypes";
3-
import {validateDob, validateEmail} from "../../services/validation";
3+
import {isDobOverThirteen, validateEmail} from "../../services/validation";
44
import {EXAM_BOARD} from "../../services/constants";
55
import React, {ChangeEvent, MutableRefObject, useEffect, useRef, useState} from "react";
66
import {api} from "../../services/api";
@@ -125,9 +125,9 @@ export const UserDetails = ({myUser, setMyUser, isEmailValid, setIsEmailValid, i
125125
name="date-of-birth"
126126
defaultValue={myUser.dateOfBirth}
127127
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
128-
const dateOfBirth = event.target.value;
129-
setIsDobValid(validateDob(dateOfBirth));
130-
setMyUser(Object.assign(myUser, {dateOfBirth: new Date(dateOfBirth)}))
128+
const dateOfBirth = event.target.valueAsDate;
129+
setIsDobValid(isDobOverThirteen(dateOfBirth));
130+
setMyUser(Object.assign(myUser, {dateOfBirth: dateOfBirth}))
131131
}}
132132
aria-describedby="ageValidationMessage"
133133
/>

src/app/components/pages/MyAccount.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useEffect, useState} from 'react';
1+
import React, {useState} from 'react';
22
import {connect} from "react-redux";
33
import classnames from "classnames";
44
import {
@@ -16,14 +16,14 @@ import {
1616
Input,
1717
Row,
1818
} from "reactstrap";
19-
import {RegisteredUserDTO, UserAuthenticationSettingsDTO} from "../../../IsaacApiTypes";
19+
import {UserAuthenticationSettingsDTO} from "../../../IsaacApiTypes";
2020
import {AppState, ErrorState} from "../../state/reducers";
2121
import {updateCurrentUser, resetPassword} from "../../state/actions";
2222
import {LoggedInUser, UserPreferencesDTO, LoggedInValidationUser} from "../../../IsaacAppTypes";
2323
import {UserDetails} from "../elements/UserDetails";
2424
import {UserPassword} from "../elements/UserPassword";
2525
import {UserEmailPreference} from "../elements/UserEmailPreferences";
26-
import {validateDob, validateEmail} from "../../services/validation";
26+
import {validateEmail} from "../../services/validation";
2727
import {Link} from "react-router-dom";
2828
import {BreadcrumbTrail} from "../elements/BreadcrumbTrail";
2929
import {EXAM_BOARD} from "../../services/constants";

0 commit comments

Comments
 (0)