Просмотр исходного кода

Added server error, added image types to pictures

feature/587
Djordje Mitrovic 3 лет назад
Родитель
Сommit
79e1a31a17

+ 1
- 0
src/i18n/resources/rs.js Просмотреть файл

@@ -96,6 +96,7 @@ export default {
PIBnoOfCharacters: "PIB mora imati 9 karaktera!",
welcome: "Dobro došli na trampu, želimo vam uspešno trampovanje!",
imageError: "Slika je obavezna!",
serverError: "Greška sa serverom!"
},
forgotPassword: {
title: "Povrati lozinku",

+ 5
- 2
src/pages/RegisterPages/Register/Register.js Просмотреть файл

@@ -25,6 +25,7 @@ import SecondPartOfRegistration from "./SecondPart/SecondPartOfRegistration";
import ThirdPartOfRegistration from "./ThirdPart/ThirdPartOfRegistration";
import { useDispatch } from "react-redux";
import { fetchRegisterUser } from "../../../store/actions/register/registerActions";
import { makeErrorToastMessage } from "../../../store/utils/makeToastMessage";

const Register = () => {
const { t } = useTranslation();
@@ -50,18 +51,20 @@ const Register = () => {
setCurrentStep(1);
setMailError(mail);
if (
error.error.response.data.toString() ===
error?.error?.response?.data?.toString() ===
"User with email already exists"
) {
setMailErrorMessage(t("register.emailTaken"));
} else {
setMailErrorMessage(t("register.emailFormat"));
}
} else {
} else if (error?.error?.response?.data?.toString() === "Company with PIB already exists") {
setInformations({ mail, password, image });
setCurrentStep(2);
setPIBError(PIB.toString());
setPIBErrorMessage(t("register.PIBTaken"));
} else {
makeErrorToastMessage(t("register.serverError"))
}
};


+ 10
- 2
src/store/saga/categoriesSaga.js Просмотреть файл

@@ -4,8 +4,16 @@ import { CATEGORIES_FETCH } from "../actions/categories/categoriesActionConstant
import { setCategories } from "../actions/categories/categoriesActions";

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() {

+ 11
- 6
src/store/saga/locationsSaga.js Просмотреть файл

@@ -4,12 +4,17 @@ import { LOCATIONS_FETCH } from "../actions/locations/locationsActionConstants";
import { setLocations } from "../actions/locations/locationsActions";

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() {
yield all([
takeLatest(LOCATIONS_FETCH, fetchLocations)
])
}
yield all([takeLatest(LOCATIONS_FETCH, fetchLocations)]);
}

+ 2
- 0
src/store/saga/loginSaga.js Просмотреть файл

@@ -132,9 +132,11 @@ function* refreshUserToken({payload}) {
yield put(setUserJwtToken({token: payload, exp: newTokenDecoded.exp}));
yield call(addHeaderToken, payload);
yield call(authScopeSetHelper, JWT_TOKEN, payload);
return true;
}
catch(e){
console.log(e);
return false;
}
}


+ 5
- 3
src/store/saga/profileSaga.js Просмотреть файл

@@ -29,9 +29,11 @@ function* fetchProfile(payload) {
function* fetchMineProfile() {
try {
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) {
console.log(e);
}

+ 8
- 4
src/store/saga/registerSaga.js Просмотреть файл

@@ -28,18 +28,21 @@ function* fetchRegisterUser({ payload }) {
if (payload.values.website?.length === 0)
delete requestData.company.contacts.web;
yield call(attemptRegister, requestData);
console.log('jos nije crash')
if (payload.handleResponseSuccess) {
yield call(payload.handleResponseSuccess);
}
return true;
} catch (e) {
let type;
console.log(e)
let type = "server";
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";
} else if (
e.response?.data?.toString() === "Company with PIB already exists"
e?.response?.data?.toString() === "Company with PIB already exists"
) {
type = "PIB";
}
@@ -50,6 +53,7 @@ function* fetchRegisterUser({ payload }) {
if (payload.handleResponseError) {
yield call(payload.handleResponseError, error);
}
return false;
}
}


+ 4
- 2
src/store/utils/makeToastMessage.js Просмотреть файл

@@ -2,11 +2,13 @@ import { toast } from 'react-toastify';

const defaultOptions = {
position: "top-center",
autoClose: 5000,
autoClose: 2000,
hideProgressBar: true,
closeOnClick: true,
pauseOnHover: true,
pauseOnFocusLoss: false,
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);

Загрузка…
Отмена
Сохранить