Skip to content

Commit

Permalink
refactor: toast
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirezaYousefpourM committed Nov 24, 2023
1 parent 71269a8 commit 4c2acfe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions frontend/src/pages/Signup/Signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '../../css/Signup.css';
import {useAPI} from "../../providers/APIProvider/APIProvider.jsx";
import Toast from "../../Components/toast/Toast.jsx";
import {Helper} from "../../utils/Helper.js";
import {useConfig} from "../../providers/config-provider/ConfigProvider.jsx";

const validatePhone = (phone) => {
const PHONE_LENGTH = 11;
Expand Down Expand Up @@ -40,6 +41,10 @@ const SignUpForm = ({onLoginClick}) => {
createUserData,
} = useAPI()

const {
setAccessTokenFromLocalStorage
} = useConfig()

const handleSignUp = useCallback(() => {
const data = {}
data.name = fullname
Expand Down Expand Up @@ -77,13 +82,30 @@ const SignUpForm = ({onLoginClick}) => {
}
// TODO: add API call for sign up
// TODO: route to my-account page
console.log('submit');
};

useEffect(() => {
if (createUserData == null) return

setToastData(Helper.getToastDataFromResponse())
const toastDataTemp = {}
switch (createUserData.status) {
case 200:
case 201:
toastDataTemp.message = "Account Created Successfully! Please Check Your Email."
toastDataTemp.alertType = "success"
break;
case 400:
toastDataTemp.message = "User with This Email Already Exists!"
toastDataTemp.alertType = "error"
break;
default:
toastDataTemp.message = "Unexpected Error! Please Try Again Later."
toastDataTemp.alertType = "error"
break
}

setAccessTokenFromLocalStorage()
setToastData(toastDataTemp)
setOpenToast(true)
}, [createUserData])

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/providers/APIProvider/URL.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const URL = {
},
token: {
default: "token/",
refresh: "token/refresh/", //TODO
refresh: "token/refresh/",
},
payment: {
default: "payment/",
Expand Down

0 comments on commit 4c2acfe

Please sign in to comment.