Skip to content

Commit 19fb00a

Browse files
committed
fixed adding new user so the form clears and alert is displayed
1 parent 2bcac6e commit 19fb00a

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/components/helper/newUserHelper.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export const handleNewUser = (e) => {
3030
);
3131
return;
3232
}
33-
return createNewUser(email, username, password, phone);
33+
console.log('sending user data to createNewUser');
34+
// return createNewUser(email, username, password, phone);
35+
createNewUser(email, username, password, phone);
3436
};
3537

3638
export const confirmPassword = () => {
@@ -88,33 +90,27 @@ export const createNewUser = (email, username, password, phone) => {
8890
phone: phone,
8991
}),
9092
})
91-
.then((response) => {
92-
return response.json();
93-
})
94-
.then((data) => {
95-
if (Object.prototype.hasOwnProperty.call(data, 'error')) {
96-
window.alert(data.error);
97-
} else {
98-
document.getElementById('signupUsername').value = '';
99-
document.getElementById('signupPassword').value = '';
100-
document.getElementById('signupPasswordConfirmation').value = '';
101-
document.getElementById('signupEmail').value = '';
102-
document.getElementById('signupPhone').value = '';
103-
document.getElementById('password-length-alert').innerHTML = '';
104-
document.getElementById('password-confirmation-alert').innerHTML = '';
93+
.then(() => {
94+
document.getElementById('signupUsername').value = '';
95+
document.getElementById('signupPassword').value = '';
96+
document.getElementById('signupPasswordConfirmation').value = '';
97+
document.getElementById('signupEmail').value = '';
98+
document.getElementById('signupPhone').value = '';
99+
document.getElementById('password-length-alert').innerHTML = '';
100+
document.getElementById('password-confirmation-alert').innerHTML = '';
105101

106-
window.alert(`New user has been successfully created. \n\n
102+
window.alert(`New user has been successfully created. \n\n
107103
An email with the user's credentials and login instructions has been sent to ${email}`);
108104

109-
getUpdatedUserList();
110-
}
105+
getUpdatedUserList();
111106
})
112107
.catch((err) => {
113108
console.log(err);
114109
});
115110
};
116111

117112
export const getUpdatedUserList = () => {
113+
console.log('store username: ', store.userInfo.username);
118114
fetch('http://localhost:3000/admin', {
119115
method: 'POST',
120116
headers: {
@@ -129,7 +125,10 @@ export const getUpdatedUserList = () => {
129125
.then((data) => {
130126
console.log('this is data from newUserHelper', data);
131127
updateUserList(data);
132-
});
128+
})
129+
.catch((err) => {
130+
console.log('error in getUpdatedUserList: ', err);
131+
})
133132
};
134133

135134
export const updateUserList = (data) => {

0 commit comments

Comments
 (0)