Skip to content

Commit

Permalink
Toast Message Changes (#60)
Browse files Browse the repository at this point in the history
* Toast Message Changes

* added language constant

* added language constant
  • Loading branch information
vidyaaKhandekar authored Dec 3, 2024
1 parent df6c3bc commit 48dc999
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
8 changes: 7 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,25 @@
"SIGNUP_LAST_NAME": "Last Name",
"SIGNUP_MOBILE_NUMBER": "Mobile Number",
"SIGNUP_CREATE_PASSWORD": "Create Password",
"SIGNUP_CREATE_PASSWORD_IS_REQUIRED": "Password is required.",
"SIGNUP_CONFIRM_PASSWORD": "Confirm Password",
"SIGNUP_CONFIRM_PASSWORD_IS_REQUIRED": "Confirm Password is required.",
"SIGNUP_PASSWORD_CONFIRM_PASSWORD_IS_REQUIRED": "Both Password and Confirm Password are required.",
"SIGNUP_PASSWORD_VALIDATION_MESSAGE": "Password must contain at least one letter, one number, and one special character (@, !, #, $, %).",
"SIGNUP_PASSWORD_NOT_MATCHING": "Passwords do not match.",
"SIGNUP_INVALID_MOBILE_NUMBER":"Invalid mobile number",
"SIGNUP_ALREADY_HAVE_AN_ACCOUNT": "Already Have An Account?",
"SIGNUP_FIRST_NAME_REQUIRED": "First name is required.",
"SIGNUP_LAST_NAME_REQUIRED": "Last name is required.",
"SIGNUP_SUCCESSFULL":"Register Successfull",
"SIGNUP_FAILED":"Register failed ",
"SIGNIN_INVALID_USERNAME_PASSWORD_MESSAGE": "Invalid Username and Password",
"SIGNIN_USER_NAME_IS_REQUIRED": "User Name is required",
"SIGNIN_PASSWORD_IS_REQUIRED": "Password is required",
"SIGNIN_DONT_HAVE_AN_ACCOUNT": "Don't Have An Account?",
"SIGNIN_ERROR_FETCHING_DATA": "Error fetching user data or documents",
"SIGNIN_LOGGEDIN_SUCCESSFULLY": "You are successfully logged in",
"SIGNIN_SUCCESSFULL":"Login Successfull",
"SIGNIN_FAILED":"Login failed ",
"CONFIRMATION_DIALOGUE_SHARE_INFORMATION": "Share Information",
"CONFIRMATION_DIALOGUE_DENY": "Deny",
"CONFIRMATION_DIALOGUE_ACCEPT": "Accept",
Expand Down
14 changes: 7 additions & 7 deletions src/screens/auth/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const SignIn: React.FC = () => {
// Set form validity
setIsFormValid(isValid);
}, [username, password]);
const [token, setToken] = useState();

const handleLogin = async () => {
try {
Expand All @@ -41,22 +40,25 @@ const SignIn: React.FC = () => {
const response = await loginUser({ username, password });
if (response) {
toast({
title: t("SIGNIN_LOGGEDIN_SUCCESSFULLY"),
title: t("SIGNIN_SUCCESSFULL"),
status: "success",
duration: 3000,
isClosable: true,
});
setToken(response);

localStorage.setItem("authToken", response.data.access_token);
localStorage.setItem("refreshToken", response.data.refresh_token);
navigate(0);
}
} catch (error) {
console.log("error", error);

toast({
title: t("SIGNIN_INVALID_USERNAME_PASSWORD_MESSAGE"),
title: t("SIGNIN_FAILED"),
status: "error",
duration: 1000,
duration: 10000,
isClosable: true,
description: t("SIGNIN_INVALID_USERNAME_PASSWORD_MESSAGE"),
});
} finally {
setLoading(false);
Expand All @@ -66,8 +68,6 @@ const SignIn: React.FC = () => {
const handleBack = () => {
navigate("/");
};
console.log("response", token);

return (
<Layout
isMenu={false}
Expand Down
21 changes: 10 additions & 11 deletions src/screens/auth/SignUpWithPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,41 +107,40 @@ const SignUpWithPassword: React.FC = () => {
toast({
title: t("SIGNUP_INVALID_MOBILE_NUMBER"),
status: "error",
duration: 3000,
duration: 5000,
isClosable: true,
});
return;
}
if (userDetails.password !== confirmPassword) {
toast({
title: t("SIGNUP_PASSWORDS_DO_NOT_MATCH"),
title: t("SIGNUP_PASSWORD_NOT_MATCHING"),
status: "error",
duration: 3000,
duration: 5000,
isClosable: true,
});
return;
}
try {
setLoading(true);
const response = await registerWithPassword(userDetails);
console.log("response", response);

if (response) {
toast({
title: "Sign Up Successfully",
title: t("SIGNUP_SUCCESSFULL"),
status: "success",
description: `Your Username is ${response?.data?.userName}`,
duration: 15000,
duration: 10000,
isClosable: true,
});
navigate("/signin");
}
} catch (error) {
toast({
title: "Sign Up Failed",
description: error,
title: t("SIGNUP_FAILED"),
description: error?.data?.error,
status: "error",
duration: 3000,
duration: 15000,
isClosable: true,
});
} finally {
Expand Down Expand Up @@ -208,15 +207,15 @@ const SignUpWithPassword: React.FC = () => {
value={userDetails.password}
onChange={(e) => handleInputChange(e, "password")}
isInvalid={!userDetails.password.trim()}
errorMessage={t("SIGNUP_PASSWORD_REQUIRED")}
errorMessage={t("SIGNUP_CREATE_PASSWORD_IS_REQUIRED")}
/>

<FloatingPasswordInput
label={t("SIGNUP_CONFIRM_PASSWORD")}
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
isInvalid={confirmPassword.trim() === ""}
errorMessage={t("SIGNUP_CONFIRM_PASSWORD_REQUIRED")}
errorMessage={t("SIGNUP_CONFIRM_PASSWORD_IS_REQUIRED")}
/>
{UserName.length > 0 && (
<Text textAlign="center" fontSize="14px" mt={4}>
Expand Down
10 changes: 2 additions & 8 deletions src/services/auth/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const loginUser = async (loginData: object) => {
},
});

console.log("response.data", response.data);
return response.data;
} catch (error: unknown) {
if (axios.isAxiosError(error) && error.response) {
Expand Down Expand Up @@ -83,8 +82,6 @@ export const getUser = async () => {
if (axios.isAxiosError(error) && error.response) {
return Promise.reject(error.response.data);
} else {
console.log("get user failed");

return Promise.reject(new Error("Network Error"));
}
}
Expand Down Expand Up @@ -252,10 +249,9 @@ export const registerUser = async (userData: UserData) => {
`${apiBaseUrl}/auth/register_with_password`,
userData
);
console.log(response);

return response?.data;
} catch (error) {
console.log(error);
return error;
}
};
Expand All @@ -265,15 +261,13 @@ export const registerWithPassword = async (userData) => {
`${apiBaseUrl}/auth/register_with_password`,
userData
);
console.log(response.data);

return response.data; // Handle the response data
} catch (error) {
console.log(error);
console.error(
"Error during registration:",
error.response?.data?.message?.[0] || ""
);
throw error.response?.data?.message?.[0];
throw error.response;
}
};

0 comments on commit 48dc999

Please sign in to comment.