| @@ -15,31 +15,15 @@ import { useTranslation } from "react-i18next"; | |||
| import { SelectField } from "../CreateOffer.styled"; | |||
| import { useSelector } from "react-redux"; | |||
| import useIsMobile from "../../../../hooks/useIsMobile"; | |||
| import { useRive } from "rive-react"; | |||
| import AnimationRiv from "../../../../assets/animations/register.riv"; | |||
| const FirstPartCreateOffer = (props) => { | |||
| const [subcat, setSubcat] = useState([]); | |||
| const locations = useSelector((state) => state.locations.locations); | |||
| const categories = useSelector((state) => state.categories.categories); | |||
| const [isPlayed, setIsPlayed] = useState(false); | |||
| const { isMobile } = useIsMobile(); | |||
| const {RiveComponent, rive} = useRive({ | |||
| src:AnimationRiv, | |||
| autoplay: false, | |||
| animations: "Successful Registration" | |||
| }) | |||
| useEffect(() => { | |||
| if (rive && !isPlayed) { | |||
| rive.play(); | |||
| setIsPlayed(true); | |||
| console.log(rive); | |||
| } | |||
| }, [rive]) | |||
| const { t } = useTranslation(); | |||
| useEffect(() => { | |||
| if (!props.offer) { | |||
| if (Object.keys(props.informations).length !== 0) { | |||
| @@ -102,7 +86,6 @@ const FirstPartCreateOffer = (props) => { | |||
| return ( | |||
| <> | |||
| <CreateOfferFormContainer component="form" onSubmit={formik.handleSubmit}> | |||
| <RiveComponent /> | |||
| <FieldLabel leftText={t("offer.title")} /> | |||
| <TitleField | |||
| name="nameOfProduct" | |||
| @@ -7,7 +7,7 @@ const Checkbox = (props) => { | |||
| return ( | |||
| <CheckboxButton | |||
| leftText={item.city} | |||
| rightText={item.offerCount} | |||
| // rightText={item.offerCount} | |||
| value={item} | |||
| checked={ | |||
| props.filters.find( | |||
| @@ -48,7 +48,7 @@ const ImagePicker = (props) => { | |||
| setImage(reader.result); | |||
| }; | |||
| reader.onerror = (error) => { | |||
| console.log(error); | |||
| console.dir(error); | |||
| }; | |||
| }; | |||
| const handleDelete = () => { | |||
| @@ -28,7 +28,7 @@ const PasswordField = forwardRef((props, ref) => { | |||
| // }, [formik.isValid]) | |||
| useEffect(() => { | |||
| console.log(error); | |||
| console.dir(error); | |||
| }, [error]) | |||
| return ( | |||
| @@ -44,7 +44,7 @@ const Register = () => { | |||
| }; | |||
| const handleResponseError = (error) => { | |||
| console.log(error); | |||
| console.dir(error); | |||
| const { mail, password, PIB, image } = informations; | |||
| if (error.type === "mail") { | |||
| setInformations({ image }); | |||
| @@ -5,10 +5,11 @@ import { | |||
| RegisterDescription, | |||
| RegisterTitle, | |||
| } from "./RegisterSuccessful.styled"; | |||
| import { ReactComponent as Success } from "../../../assets/images/svg/register-success.svg"; | |||
| import { useTranslation } from "react-i18next"; | |||
| import { useHistory } from "react-router-dom"; | |||
| import { LOGIN_PAGE } from "../../../constants/pages"; | |||
| import { HOME_PAGE } from "../../../constants/pages"; | |||
| import RegisterRiv from "../../../assets/animations/register.riv"; | |||
| import { useRive } from "rive-react"; | |||
| const RegisterSuccessful = () => { | |||
| const { t } = useTranslation(); | |||
| @@ -17,13 +18,18 @@ const RegisterSuccessful = () => { | |||
| //Redirect to Login page when registration is successful | |||
| useEffect(() => { | |||
| setTimeout(() => { | |||
| history.replace(LOGIN_PAGE); | |||
| }, 2500); | |||
| history.replace(HOME_PAGE); | |||
| }, 1700); | |||
| }, []); | |||
| const { RiveComponent } = useRive({ | |||
| src: RegisterRiv, | |||
| autoplay: true, | |||
| }); | |||
| return ( | |||
| <RegisterSuccessfulContainer> | |||
| <Success /> | |||
| <RiveComponent /> | |||
| <RegisterTitle component="h1" variant="h5"> | |||
| {t("register.success")} | |||
| @@ -8,7 +8,11 @@ export const RegisterSuccessfulContainer = styled(Container)` | |||
| flex-direction: column; | |||
| align-items: center; | |||
| width: 536px; | |||
| height: 200px; | |||
| padding: 0; | |||
| & div canvas { | |||
| height: 300px; | |||
| } | |||
| `; | |||
| export const RegisterTitle = styled(Typography)` | |||
| font-family: "Mulish"; | |||
| @@ -4,7 +4,7 @@ import queryString from "qs"; | |||
| const request = axios.create({ | |||
| // baseURL: "http://192.168.88.150:3001/", | |||
| // baseURL: "http://192.168.88.175:3005/", | |||
| baseURL: "https://trampa-api-test.dilig.net/", | |||
| baseURL: "http://192.168.88.143:3001/", | |||
| headers: { | |||
| "Content-Type": "application/json", | |||
| }, | |||
| @@ -13,7 +13,7 @@ import { logoutUser, refreshUserToken } from "../actions/login/loginActions"; | |||
| // import { setUserAccessToken } from "../actions/user/userActions"; | |||
| //Change URL with .env | |||
| const baseURL = "https://trampa-api-test.dilig.net/"; | |||
| const baseURL = "http://192.168.88.143:3001/"; | |||
| // const baseURL = "http://192.168.88.175:3005/"; | |||
| // const baseURL = "http://192.168.88.175:3005/"; | |||
| @@ -14,7 +14,7 @@ function* fetchCategories() { | |||
| yield put(fetchCategoriesSuccess()); | |||
| } catch (e) { | |||
| yield put(fetchCategoriesError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -28,7 +28,7 @@ function* fetchChats() { | |||
| yield put(fetchChatsSuccess()); | |||
| } catch (e) { | |||
| yield put(fetchChatsError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -40,7 +40,7 @@ function* fetchHeaderChats() { | |||
| yield put(fetchHeaderChatsSuccess()); | |||
| } catch (e) { | |||
| yield put(fetchHeaderChatsError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| function* fetchOneChat(payload) { | |||
| @@ -59,7 +59,7 @@ function* fetchOneChat(payload) { | |||
| yield put(fetchOneChatSuccess()); | |||
| } catch (e) { | |||
| yield put(fetchOneChatError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -82,7 +82,7 @@ function* sendMessage(payload) { | |||
| } | |||
| } catch (e) { | |||
| yield put(sendMessageError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| function* startNewChat(payload) { | |||
| @@ -102,7 +102,7 @@ function* startNewChat(payload) { | |||
| } | |||
| } catch (e) { | |||
| yield put(startNewChatError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -12,7 +12,7 @@ function* increaseCounter(payload) { | |||
| yield put(increaseCounterSuccess()); | |||
| } catch (e) { | |||
| yield put(increaseCounterError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -11,7 +11,7 @@ function* fetchExchange(payload) { | |||
| } | |||
| catch (e) { | |||
| yield put(fetchExchangeError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -24,7 +24,7 @@ function* validateExchange(payload) { | |||
| } | |||
| catch(e) { | |||
| yield put(validateExchangeError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -14,7 +14,7 @@ function* forgotPassword({payload}) { | |||
| } | |||
| } | |||
| catch(e) { | |||
| console.log(e); | |||
| console.dir(e); | |||
| if (payload.handleResponseError) { | |||
| yield call(payload.handleResponseError); | |||
| } | |||
| @@ -111,7 +111,7 @@ function* logout(payload) { | |||
| yield call(payload.payload) | |||
| } | |||
| } catch (error) { | |||
| console.log(error); // eslint-disable-line | |||
| console.dir(error); // eslint-disable-line | |||
| } finally { | |||
| yield call(authScopeClearHelper); | |||
| yield call(removeHeaderToken); | |||
| @@ -132,7 +132,7 @@ function* refreshUserToken({payload}) { | |||
| return true; | |||
| } | |||
| catch(e){ | |||
| console.log(e); | |||
| console.dir(e); | |||
| return false; | |||
| } | |||
| } | |||
| @@ -183,7 +183,7 @@ function* fetchMoreOffers(payload) { | |||
| yield put(fetchMoreOffersSuccess()); | |||
| } catch (e) { | |||
| yield put(fetchMoreOffersError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -196,7 +196,7 @@ function* createOffer(payload) { | |||
| } | |||
| } catch (e) { | |||
| yield put(addOfferError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -222,7 +222,7 @@ function* fetchMineOffers() { | |||
| yield put(fetchMineOffersSuccess()); | |||
| } catch (e) { | |||
| yield put(fetchMineOffersError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -235,7 +235,7 @@ function* fetchProfileOffers(payload) { | |||
| yield put(setProfileOffers(data.data)); | |||
| yield put(fetchProfileOffersSuccess()); | |||
| } catch (e) { | |||
| console.log(e); | |||
| console.dir(e); | |||
| if (e.response.status === 400) { | |||
| yield call(history.push, NOT_FOUND_PAGE); | |||
| } | |||
| @@ -253,7 +253,7 @@ function* removeOffer(payload) { | |||
| } | |||
| } catch (e) { | |||
| yield put(removeOfferError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -268,7 +268,7 @@ function* editOffer(payload) { | |||
| } | |||
| } catch (e) { | |||
| yield put(editOfferError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -28,7 +28,7 @@ function* fetchProfile(payload) { | |||
| yield put(fetchProfileSuccess()); | |||
| } catch (e) { | |||
| yield put(fetchErrorProfile()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -40,7 +40,7 @@ function* fetchMineProfile() { | |||
| yield put(fetchMineProfileSuccess()); | |||
| } catch (e) { | |||
| yield put(fetcHMineProfileError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -86,7 +86,7 @@ function* changeMineProfile(payload) { | |||
| console.log(data); | |||
| } catch (e) { | |||
| yield put(editMineProfileError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -19,7 +19,7 @@ function* setQueryString(payload) { | |||
| const newQueryString = convertQueryStringForBackend(payload.payload); | |||
| yield put(setQueryStringRedux(newQueryString)); | |||
| } catch (e) { | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -1,10 +1,23 @@ | |||
| import { all, takeLatest, call, put } from "@redux-saga/core/effects"; | |||
| import { JWT_REFRESH_TOKEN, JWT_TOKEN } from "../../constants/localStorage"; | |||
| import { addHeaderToken } from "../../request"; | |||
| import { attemptLogin } from "../../request/loginRequest"; | |||
| import { attemptFetchProfile } from "../../request/profileRequest"; | |||
| import { attemptRegister } from "../../request/registerRequest"; | |||
| import { authScopeSetHelper } from "../../util/helpers/authScopeHelpers"; | |||
| import { | |||
| fetchUserError, | |||
| fetchUserSuccess, | |||
| } from "../actions/login/loginActions"; | |||
| import { setMineProfile } from "../actions/profile/profileActions"; | |||
| import { REGISTER_USER_FETCH } from "../actions/register/registerActionConstants"; | |||
| import jwt from "jsonwebtoken"; | |||
| import { | |||
| fetchRegisterUserError, | |||
| fetchRegisterUserSuccess, | |||
| } from "../actions/register/registerActions"; | |||
| import { rejectErrorCodeHelper } from "../../util/helpers/rejectErrorCodeHelper"; | |||
| import i18next from "i18next"; | |||
| function* fetchRegisterUser({ payload }) { | |||
| try { | |||
| @@ -32,12 +45,44 @@ function* fetchRegisterUser({ payload }) { | |||
| if (payload.values.website?.length === 0) | |||
| delete requestData.company.contacts.web; | |||
| yield call(attemptRegister, requestData); | |||
| const { data } = yield call(attemptLogin, { | |||
| email: payload.values.mail, | |||
| password: payload.values.password, | |||
| }); | |||
| if (data.token) { | |||
| const token = data.token; | |||
| const refresh = data.refresh; | |||
| const tokenDecoded = jwt.decode(token); | |||
| const refreshDecoded = jwt.decode(refresh); | |||
| const accessToken = { | |||
| token: token, | |||
| exp: tokenDecoded.exp, | |||
| }; | |||
| const refreshToken = { | |||
| token: refresh, | |||
| exp: refreshDecoded.exp, | |||
| }; | |||
| const userId = tokenDecoded._id; | |||
| yield call(authScopeSetHelper, JWT_TOKEN, token); | |||
| yield call(authScopeSetHelper, JWT_REFRESH_TOKEN, refresh); | |||
| yield call(addHeaderToken, token); | |||
| const profileData = yield call(attemptFetchProfile, userId); | |||
| if (profileData) yield put(setMineProfile(profileData.data)); | |||
| yield put( | |||
| fetchUserSuccess({ | |||
| JwtToken: accessToken, | |||
| RefreshToken: refreshToken, | |||
| userId, | |||
| }) | |||
| ); | |||
| } | |||
| if (payload.handleResponseSuccess) { | |||
| yield call(payload.handleResponseSuccess); | |||
| } | |||
| yield put(fetchRegisterUserSuccess()); | |||
| } catch (e) { | |||
| console.log(e); | |||
| console.dir(e); | |||
| let type = "server"; | |||
| if ( | |||
| e?.response?.data?.toString() === "User with email already exists!" || | |||
| @@ -56,6 +101,16 @@ function* fetchRegisterUser({ payload }) { | |||
| if (payload.handleResponseError) { | |||
| yield call(payload.handleResponseError, error); | |||
| } | |||
| if (e.response && e.response.data) { | |||
| console.log(e.response.status); | |||
| let errorMessage = yield call(rejectErrorCodeHelper, e.response.status); | |||
| if (e.response.status === 400 || e.response.status === 404) { | |||
| errorMessage = i18next.t("login.wrongCredentials", { | |||
| lng: "rs", | |||
| }); | |||
| } | |||
| yield put(fetchUserError(errorMessage)); | |||
| } | |||
| yield put(fetchRegisterUserError()); | |||
| } | |||
| } | |||
| @@ -22,7 +22,7 @@ function* fetchReviews(payload) { | |||
| yield put(fetchReviewsSuccess()); | |||
| } catch (e) { | |||
| yield put(fetchReviewsError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| @@ -35,7 +35,7 @@ function* giveReview(payload) { | |||
| yield put(giveReviewSuccess()); | |||
| } catch (e) { | |||
| yield put(giveReviewError()); | |||
| console.log(e); | |||
| console.dir(e); | |||
| } | |||
| } | |||