From 4a00dd1817ea59961273419935d13a55fe80e584 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Tue, 4 Jul 2023 14:34:31 +0800 Subject: [PATCH] Fixed registration page --- src/components/Api/Api.tsx | 4 ++-- src/routes/Register/Register.tsx | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/components/Api/Api.tsx b/src/components/Api/Api.tsx index f6c5975..5d2e6dd 100644 --- a/src/components/Api/Api.tsx +++ b/src/components/Api/Api.tsx @@ -48,10 +48,10 @@ export function UserRegister(register: RegistrationParams) { return instance .post("/api/v1/accounts/users/", register) .then(async (response) => { - return [response.status]; + return [true, response.status]; }) .catch((error) => { - return [error.response.status, error.response.data]; + return [false, error.response.status, error.response.data]; }); } diff --git a/src/routes/Register/Register.tsx b/src/routes/Register/Register.tsx index 8e0a567..f484f11 100644 --- a/src/routes/Register/Register.tsx +++ b/src/routes/Register/Register.tsx @@ -141,12 +141,7 @@ export default function Register() { last_name: user.last_name, }).then((result) => { console.log(result); - try { - setUser({ - ...user, - feedback: ParseError(JSON.stringify(result[1])), - }); - } catch { + if (result[0]) { setUser({ ...user, first_name: "", @@ -158,6 +153,14 @@ export default function Register() { feedback: "Success! An email has been sent to activate your account", }); + setTimeout(() => { + navigation.navigate("Login"); + }, 10000); + } else { + setUser({ + ...user, + feedback: ParseError(JSON.stringify(result[2])), + }); } }); {