| PIBnoOfCharacters: "PIB mora imati 9 karaktera!", | PIBnoOfCharacters: "PIB mora imati 9 karaktera!", | ||||
| welcome: "Dobro došli na trampu, želimo vam uspešno trampovanje!", | welcome: "Dobro došli na trampu, želimo vam uspešno trampovanje!", | ||||
| imageError: "Slika je obavezna!", | imageError: "Slika je obavezna!", | ||||
| serverError: "Greška sa serverom!" | |||||
| }, | }, | ||||
| forgotPassword: { | forgotPassword: { | ||||
| title: "Povrati lozinku", | title: "Povrati lozinku", |
| import ThirdPartOfRegistration from "./ThirdPart/ThirdPartOfRegistration"; | import ThirdPartOfRegistration from "./ThirdPart/ThirdPartOfRegistration"; | ||||
| import { useDispatch } from "react-redux"; | import { useDispatch } from "react-redux"; | ||||
| import { fetchRegisterUser } from "../../../store/actions/register/registerActions"; | import { fetchRegisterUser } from "../../../store/actions/register/registerActions"; | ||||
| import { makeErrorToastMessage } from "../../../store/utils/makeToastMessage"; | |||||
| const Register = () => { | const Register = () => { | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| setCurrentStep(1); | setCurrentStep(1); | ||||
| setMailError(mail); | setMailError(mail); | ||||
| if ( | if ( | ||||
| error.error.response.data.toString() === | |||||
| error?.error?.response?.data?.toString() === | |||||
| "User with email already exists" | "User with email already exists" | ||||
| ) { | ) { | ||||
| setMailErrorMessage(t("register.emailTaken")); | setMailErrorMessage(t("register.emailTaken")); | ||||
| } else { | } else { | ||||
| setMailErrorMessage(t("register.emailFormat")); | setMailErrorMessage(t("register.emailFormat")); | ||||
| } | } | ||||
| } else { | |||||
| } else if (error?.error?.response?.data?.toString() === "Company with PIB already exists") { | |||||
| setInformations({ mail, password, image }); | setInformations({ mail, password, image }); | ||||
| setCurrentStep(2); | setCurrentStep(2); | ||||
| setPIBError(PIB.toString()); | setPIBError(PIB.toString()); | ||||
| setPIBErrorMessage(t("register.PIBTaken")); | setPIBErrorMessage(t("register.PIBTaken")); | ||||
| } else { | |||||
| makeErrorToastMessage(t("register.serverError")) | |||||
| } | } | ||||
| }; | }; | ||||
| import { setCategories } from "../actions/categories/categoriesActions"; | import { setCategories } from "../actions/categories/categoriesActions"; | ||||
| function* fetchCategories() { | function* fetchCategories() { | ||||
| const { data } = yield call(attemptFetchCategories); | |||||
| yield put(setCategories(data)); | |||||
| try { | |||||
| const { data } = yield call(attemptFetchCategories); | |||||
| if (data) { | |||||
| yield put(setCategories(data)); | |||||
| } | |||||
| return true; | |||||
| } catch (e) { | |||||
| console.log(e); | |||||
| return false; | |||||
| } | |||||
| } | } | ||||
| export default function* categoriesSaga() { | export default function* categoriesSaga() { |
| import { setLocations } from "../actions/locations/locationsActions"; | import { setLocations } from "../actions/locations/locationsActions"; | ||||
| function* fetchLocations() { | function* fetchLocations() { | ||||
| const {data} = yield call(attemptFetchLocations) | |||||
| yield put(setLocations(data)); | |||||
| try { | |||||
| const { data } = yield call(attemptFetchLocations); | |||||
| console.log(data); | |||||
| if (data) { | |||||
| yield put(setLocations(data)); | |||||
| } | |||||
| } catch (e) { | |||||
| console.log(e); | |||||
| } | |||||
| } | } | ||||
| export default function* locationsSaga() { | export default function* locationsSaga() { | ||||
| yield all([ | |||||
| takeLatest(LOCATIONS_FETCH, fetchLocations) | |||||
| ]) | |||||
| } | |||||
| yield all([takeLatest(LOCATIONS_FETCH, fetchLocations)]); | |||||
| } |
| yield put(setUserJwtToken({token: payload, exp: newTokenDecoded.exp})); | yield put(setUserJwtToken({token: payload, exp: newTokenDecoded.exp})); | ||||
| yield call(addHeaderToken, payload); | yield call(addHeaderToken, payload); | ||||
| yield call(authScopeSetHelper, JWT_TOKEN, payload); | yield call(authScopeSetHelper, JWT_TOKEN, payload); | ||||
| return true; | |||||
| } | } | ||||
| catch(e){ | catch(e){ | ||||
| console.log(e); | console.log(e); | ||||
| return false; | |||||
| } | } | ||||
| } | } | ||||
| function* fetchMineProfile() { | function* fetchMineProfile() { | ||||
| try { | try { | ||||
| const userId = yield select(selectUserId); | const userId = yield select(selectUserId); | ||||
| const data = yield call(attemptFetchProfile, userId); | |||||
| console.log(data); | |||||
| if (data) yield put(setMineProfile(data.data)); | |||||
| if (userId) { | |||||
| const data = yield call(attemptFetchProfile, userId); | |||||
| console.log(data); | |||||
| if (data) yield put(setMineProfile(data.data)); | |||||
| } | |||||
| } catch (e) { | } catch (e) { | ||||
| console.log(e); | console.log(e); | ||||
| } | } |
| if (payload.values.website?.length === 0) | if (payload.values.website?.length === 0) | ||||
| delete requestData.company.contacts.web; | delete requestData.company.contacts.web; | ||||
| yield call(attemptRegister, requestData); | yield call(attemptRegister, requestData); | ||||
| console.log('jos nije crash') | |||||
| if (payload.handleResponseSuccess) { | if (payload.handleResponseSuccess) { | ||||
| yield call(payload.handleResponseSuccess); | yield call(payload.handleResponseSuccess); | ||||
| } | } | ||||
| return true; | |||||
| } catch (e) { | } catch (e) { | ||||
| let type; | |||||
| console.log(e) | |||||
| let type = "server"; | |||||
| if ( | if ( | ||||
| e.response?.data?.toString() === "User with email already exists" || | |||||
| e.response?.data?.toString() === '"email" must be a valid email' | |||||
| e?.response?.data?.toString() === "User with email already exists" || | |||||
| e?.response?.data?.toString() === '"email" must be a valid email' | |||||
| ) { | ) { | ||||
| type = "mail"; | type = "mail"; | ||||
| } else if ( | } else if ( | ||||
| e.response?.data?.toString() === "Company with PIB already exists" | |||||
| e?.response?.data?.toString() === "Company with PIB already exists" | |||||
| ) { | ) { | ||||
| type = "PIB"; | type = "PIB"; | ||||
| } | } | ||||
| if (payload.handleResponseError) { | if (payload.handleResponseError) { | ||||
| yield call(payload.handleResponseError, error); | yield call(payload.handleResponseError, error); | ||||
| } | } | ||||
| return false; | |||||
| } | } | ||||
| } | } | ||||
| const defaultOptions = { | const defaultOptions = { | ||||
| position: "top-center", | position: "top-center", | ||||
| autoClose: 5000, | |||||
| autoClose: 2000, | |||||
| hideProgressBar: true, | hideProgressBar: true, | ||||
| closeOnClick: true, | closeOnClick: true, | ||||
| pauseOnHover: true, | pauseOnHover: true, | ||||
| pauseOnFocusLoss: false, | |||||
| draggable: true, | draggable: true, | ||||
| } | } | ||||
| export const makeToastMessage = (text, options = defaultOptions) => toast(text, options); | |||||
| export const makeToastMessage = (text, options = defaultOptions) => toast(text, options); | |||||
| export const makeErrorToastMessage = (text, options = defaultOptions) => toast.error(text, options); |