Skip to content

Commit f7ecd50

Browse files
committed
added better error messages
1 parent bde7863 commit f7ecd50

5 files changed

Lines changed: 38 additions & 1 deletion

File tree

client/src/components/form/Checkboxes/Checkboxes.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const Checkboxes = ({
1717
setSelectAll,
1818
autoFocus,
1919
isRequired,
20+
errorFeedback,
2021
}) => {
2122
useEffect(() => {
2223
if (selectAll) {
@@ -166,6 +167,7 @@ const Checkboxes = ({
166167
</React.Fragment>
167168
);
168169
})}
170+
{errorFeedback ? <p className="text-input-error-message">{errorFeedback}</p> : <></>}
169171
</div>
170172
</>
171173
);
@@ -186,6 +188,7 @@ Checkboxes.propTypes = {
186188
setSelectAll: PropTypes.func,
187189
autoFocus: PropTypes.bool,
188190
isRequired: PropTypes.bool,
191+
errorFeedback: PropTypes.string,
189192
};
190193

191194
export { Checkboxes };

client/src/components/form/Checkboxes/Checkboxes.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@ input[type='checkbox']:disabled::before {
8181
display: inline-block;
8282
font-size: 16px;
8383
}
84+
85+
.text-input-error-message {
86+
margin-top: 20px;
87+
}

client/src/pages/Registration/RegistrationFields.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export const fields = {
237237
inputTitle: 'Country Code',
238238
maxLength: 4,
239239
noEdit: false,
240+
errorMessage: 'Please enter an area code',
240241
validation: (value) => {
241242
if (/^[+0-9]*$/.test(value)) {
242243
if (value.length <= 4) {
@@ -305,6 +306,7 @@ export const fields = {
305306
inputTitle: 'Country Code',
306307
maxLength: 4,
307308
noEdit: false,
309+
errorMessage: 'Please enter an area code',
308310
validation: (value) => {
309311
if (/^[+0-9]*$/.test(value)) {
310312
if (value.length <= 4) {
@@ -392,6 +394,7 @@ export const fields = {
392394
],
393395
isRequiredInput: true,
394396
noEdit: false,
397+
errorMessage: 'Please choose None if you do not have any allergies or dietary restrictions',
395398
localStorageKey: 'registration-allergies',
396399
onChanged: (values, disableField) => {
397400
if (values.includes('Other')) {

client/src/pages/Registration/RegistrationForm.jsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const PageRegistrationForm = ({ editFieldsPage, initialValues, onEditSubmit }) =
2828
const [canRegister, setCanRegister] = useState(true);
2929
const [checkoutUrl, setCheckoutUrl] = useState('');
3030
const [errorAfterEdit, setErrorAfterEdit] = useState(false);
31+
const [anyError, setAnyError] = useState(false);
3132

3233
const { axios } = useAxios();
3334

@@ -46,8 +47,10 @@ const PageRegistrationForm = ({ editFieldsPage, initialValues, onEditSubmit }) =
4647
const isFormValid = validateForm();
4748
// console.log(isFormValid)
4849
if (!isFormValid) {
50+
setAnyError(true);
4951
return setCanRegister(true);
5052
} else {
53+
setAnyError(true);
5154
try {
5255
// const convertedFroshObject = { ...froshObject };
5356

@@ -297,6 +300,7 @@ const PageRegistrationForm = ({ editFieldsPage, initialValues, onEditSubmit }) =
297300
: false
298301
}
299302
disabledIndices={field.disabledIndices}
303+
errorFeedback={field.errorFeedback}
300304
initialSelectedIndices={
301305
editFieldsPage === true
302306
? field.values.reduce((prev, curr, index) => {
@@ -436,6 +440,11 @@ const PageRegistrationForm = ({ editFieldsPage, initialValues, onEditSubmit }) =
436440
title: 'General',
437441
component: (
438442
<>
443+
{anyError == true && selectedTab == 0 ? (
444+
<h3 className="registration-error-msg">
445+
Please make sure you have filled out all required fields correctly.
446+
</h3>
447+
) : null}
439448
<div className="registration-first-step-header-container">
440449
<img className="registration-icon-logo" src={MainFroshLogo}></img>
441450
<div>
@@ -459,7 +468,16 @@ const PageRegistrationForm = ({ editFieldsPage, initialValues, onEditSubmit }) =
459468
},
460469
{
461470
title: 'Health & Safety',
462-
component: generateStepComponent(formFields['HealthSafety'], 'HealthSafety'),
471+
component: (
472+
<>
473+
{anyError == true && selectedTab == 1 ? (
474+
<h3 className="registration-error-msg">
475+
Please make sure you have filled out all required fields correctly.
476+
</h3>
477+
) : null}
478+
{generateStepComponent(formFields['HealthSafety'], 'HealthSafety')}
479+
</>
480+
),
463481
},
464482
{
465483
title: 'Extra Events',

client/src/pages/Registration/RegistrationForm.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
max-width: 1000px;
1515
}
1616

17+
.registration-error-msg {
18+
color: rgb(230, 41, 41);
19+
font-size: 18px;
20+
font-weight: 400;
21+
margin-top: 20px;
22+
margin-bottom: 10px;
23+
text-align: center;
24+
}
25+
1726
.registration-tab-content {
1827
padding: 20px 20px;
1928
display: flex;

0 commit comments

Comments
 (0)