Add a new route for username availability check
Though this query is using the same jamid service as the contact query,
they should handle the responses from jamid service differently.
Change-Id: I42da3c5fc05ffe721a33288a2c7276eb52a9c624
diff --git a/client/src/pages/Registration.tsx b/client/src/pages/Registration.tsx
index e857f7b..1b63d33 100644
--- a/client/src/pages/Registration.tsx
+++ b/client/src/pages/Registration.tsx
@@ -69,22 +69,19 @@
// useCheckIfUsernameIsRegisteredMutation.mutate(username);
checkIfUserameIsRegistered(username)
.then((response) => {
- //server responds 200 if name IS found
- if (response.status === HttpStatusCode.Ok) {
- setUsernameStatus('taken');
+ const { status, data } = response;
+ if (status === HttpStatusCode.Ok) {
+ if (data === 'taken') {
+ setUsernameStatus('taken');
+ } else {
+ setUsernameStatus('success');
+ }
}
})
.catch((e) => {
- // console.log(e.response.data);
const { status } = e.response;
if (status === HttpStatusCode.BadRequest) {
- //TODO: server sends invalid username as the message, add it to the locale
- // console.log(e.response.data);
setUsernameStatus('invalid');
- } else if (status === HttpStatusCode.NotFound) {
- //TODO: server didn't find this username, therefore it can be registered, add the message to the locale
- // console.log(e.response.data);
- setUsernameStatus('success');
} else {
setAlertContent({ messageI18nKey: 'unknown_error_alert', severity: 'error', alertOpen: true });
}