| @@ -1,10 +1,23 @@ | |||
| import React from "react"; | |||
| import PropTypes from "prop-types"; | |||
| import { OffersContainer } from "./Offers.styled"; | |||
| import MockupdataOffers from "../MockupdataOffers"; | |||
| import OfferCard from "../../Cards/OfferCard/OfferCard"; | |||
| import MockupdataOffers from "../MockupdataOffers"; | |||
| // import { fetchOffers } from "../../../store/actions/offers/offersActions"; | |||
| // import { useDispatch, useSelector } from "react-redux"; | |||
| // import { selectOffers } from "../../../store/selectors/offersSelectors"; | |||
| const Offers = (props) => { | |||
| // Market place nije zavrsen | |||
| // Koriste se Mockup podaci | |||
| // const dispatch = useDispatch(); | |||
| // const offers = useSelector(selectOffers); | |||
| // useEffect(() => { | |||
| // dispatch(fetchOffers()); | |||
| // }, []) | |||
| return ( | |||
| <OffersContainer> | |||
| {MockupdataOffers.map((item) => { | |||
| @@ -20,10 +20,11 @@ const FirstPartOfRegistration = (props) => { | |||
| const { t } = useTranslation(); | |||
| useEffect(() => { | |||
| if (props.mailError?.length > 0) { | |||
| console.log(props.error); | |||
| if (props.error.length > 0) { | |||
| setEmailTakenStatus(true); | |||
| } | |||
| }, [props.mailError]); | |||
| }, [props.error]); | |||
| const formik = useFormik({ | |||
| initialValues: { | |||
| @@ -98,7 +99,8 @@ const FirstPartOfRegistration = (props) => { | |||
| textcolor="white" | |||
| disabled={ | |||
| formik.values.mail.length === 0 || | |||
| formik.values.password.length === 0 | |||
| formik.values.password.length === 0 || | |||
| formik.values.mail === props.error | |||
| } | |||
| > | |||
| {t("common.continue")} | |||
| @@ -110,7 +112,7 @@ const FirstPartOfRegistration = (props) => { | |||
| FirstPartOfRegistration.propTypes = { | |||
| children: PropTypes.node, | |||
| handleSubmit: PropTypes.func, | |||
| mailError: PropTypes.string, | |||
| error: PropTypes.string, | |||
| }; | |||
| export default FirstPartOfRegistration; | |||
| @@ -36,8 +36,8 @@ const Register = () => { | |||
| }; | |||
| const handleResponseError = (error) => { | |||
| console.log(error); | |||
| if (error.type === "email") { | |||
| console.log("handleResponse: ", error); | |||
| if (error.type === "mail") { | |||
| const { mail } = informations; | |||
| setInformations({}); | |||
| setCurrentStep(1); | |||
| @@ -46,15 +46,13 @@ const Register = () => { | |||
| const { mail, password, PIB } = informations; | |||
| setInformations({ mail, password }); | |||
| setCurrentStep(2); | |||
| setPIBError(PIB); | |||
| setPIBError(PIB.toString()); | |||
| } | |||
| }; | |||
| const registerUser = (values) => { | |||
| dispatch( | |||
| fetchRegisterUser(values), | |||
| handleResponseSuccess, | |||
| handleResponseError | |||
| fetchRegisterUser({values, handleResponseSuccess, handleResponseError}) | |||
| ); | |||
| }; | |||
| @@ -1,4 +1,4 @@ | |||
| import React, { useState } from "react"; | |||
| import React, { useEffect, useState } from "react"; | |||
| import PropTypes from "prop-types"; | |||
| import { | |||
| FormContainer, | |||
| @@ -15,14 +15,11 @@ const SecondPartOfRegistration = (props) => { | |||
| const { t } = useTranslation(); | |||
| const [PIBTakenStatus, setPIBTakenStatus] = useState(false); | |||
| const handleForm = (values) => { | |||
| // validate email | |||
| if (true) { // eslint-disable-line | |||
| props.handleSubmit(values) | |||
| } else { | |||
| useEffect(() => { | |||
| if (props.error.length > 0) { | |||
| setPIBTakenStatus(true); | |||
| } | |||
| } | |||
| }, [props.error]) | |||
| const formik = useFormik({ | |||
| initialValues: { | |||
| @@ -33,7 +30,7 @@ const SecondPartOfRegistration = (props) => { | |||
| nameOfFirm: Yup.string().required(t("login.usernameRequired")), | |||
| PIB: Yup.number().required(t("login.passwordRequired")).min(100000000).max(999999999), | |||
| }), | |||
| onSubmit: handleForm, | |||
| onSubmit: props.handleSubmit, | |||
| validateOnBlur: true, | |||
| enableReinitialize: true, | |||
| }); | |||
| @@ -76,7 +73,8 @@ const SecondPartOfRegistration = (props) => { | |||
| textcolor="white" | |||
| disabled={ | |||
| formik.values.PIB.length === 0 || | |||
| formik.values.nameOfFirm.length === 0 | |||
| formik.values.nameOfFirm.length === 0 || | |||
| formik.values.PIB.toString() === props.error | |||
| } | |||
| > | |||
| {t("common.continue")} | |||
| @@ -88,6 +86,7 @@ const SecondPartOfRegistration = (props) => { | |||
| SecondPartOfRegistration.propTypes = { | |||
| children: PropTypes.node, | |||
| handleSubmit: PropTypes.func, | |||
| error: PropTypes.string, | |||
| }; | |||
| export default SecondPartOfRegistration; | |||
| @@ -155,4 +155,7 @@ export default { | |||
| setCookie: '/affiliate/picture', | |||
| setFingerprint: '/affiliate/fingerprint', | |||
| }, | |||
| offers: { | |||
| getOffers: 'offers' | |||
| } | |||
| }; | |||
| @@ -0,0 +1,6 @@ | |||
| import { getRequest } from "." | |||
| import apiEndpoints from "./apiEndpoints" | |||
| export const attemptFetchOffers = () => { | |||
| return getRequest(apiEndpoints.offers.getOffers) | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| import { createClearType, createErrorType, createFetchType, createSuccessType } from "../actionHelpers"; | |||
| const OFFERS_SCOPE = "OFFERS_SCOPE"; | |||
| export const OFFERS_FETCH = createFetchType(OFFERS_SCOPE); | |||
| export const OFFERS_SUCCESS = createSuccessType(OFFERS_SCOPE); | |||
| export const OFFERS_ERROR = createErrorType(OFFERS_SCOPE); | |||
| export const OFFERS_CLEAR = createClearType(OFFERS_SCOPE); | |||
| export const OFFERS_SET = "OFFERS_SET"; | |||
| @@ -0,0 +1,21 @@ | |||
| import { OFFERS_CLEAR, OFFERS_ERROR, OFFERS_FETCH, OFFERS_SET, OFFERS_SUCCESS } from "./offersActionConstants"; | |||
| export const fetchOffers = (payload) => ({ | |||
| type: OFFERS_FETCH, | |||
| payload, | |||
| }) | |||
| export const fetchOffersSuccess = (payload) => ({ | |||
| type: OFFERS_SUCCESS, | |||
| payload | |||
| }) | |||
| export const fetchOffersError = (payload) => ({ | |||
| type: OFFERS_ERROR, | |||
| payload, | |||
| }) | |||
| export const clearOffers = () => ({ | |||
| type: OFFERS_CLEAR, | |||
| }) | |||
| export const setOffers = (payload) => ({ | |||
| type: OFFERS_SET, | |||
| payload, | |||
| }) | |||
| @@ -7,6 +7,7 @@ import storage from "redux-persist/lib/storage"; | |||
| import createFilter from "redux-persist-transform-filter"; | |||
| import persistReducer from "redux-persist/es/persistReducer"; | |||
| import filtersReducer from "./filters/filtersReducer"; | |||
| import offersReducer from "./offers/offersReducer"; | |||
| const loginPersistConfig = { | |||
| key: "login", | |||
| @@ -42,4 +43,5 @@ export default combineReducers({ | |||
| loading: loadingReducer, | |||
| filters: filtersReducer, | |||
| randomData: persistReducer(randomDataPersistConfig, randomDataReducer), | |||
| offers: offersReducer | |||
| }); | |||
| @@ -0,0 +1,34 @@ | |||
| import { | |||
| OFFERS_CLEAR, | |||
| OFFERS_ERROR, | |||
| OFFERS_SET, | |||
| } from "../../actions/offers/offersActionConstants"; | |||
| import createReducer from "../../utils/createReducer"; | |||
| const initialState = { | |||
| offers: [], | |||
| error: "", | |||
| }; | |||
| export default createReducer( | |||
| { | |||
| [OFFERS_ERROR]: fetchOffersError, | |||
| [OFFERS_CLEAR]: clearOffers, | |||
| [OFFERS_SET]: setOffers, | |||
| }, | |||
| initialState | |||
| ); | |||
| function fetchOffersError(state, action) { | |||
| return { ...state, error: action.payload }; | |||
| } | |||
| function clearOffers() { | |||
| return initialState; | |||
| } | |||
| function setOffers(state, action) { | |||
| return { | |||
| ...state, | |||
| offers: action.payload, | |||
| }; | |||
| } | |||
| @@ -1,12 +1,14 @@ | |||
| import { all } from 'redux-saga/effects'; | |||
| import forgotPasswordSaga from './forgotPasswordSaga'; | |||
| import loginSaga from './loginSaga'; | |||
| import offersSaga from './offersSaga'; | |||
| import registerSaga from './registerSaga'; | |||
| export default function* rootSaga() { | |||
| yield all([ | |||
| loginSaga(), | |||
| registerSaga(), | |||
| forgotPasswordSaga() | |||
| forgotPasswordSaga(), | |||
| offersSaga() | |||
| ]); | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| import { all, takeLatest, call } from "@redux-saga/core/effects"; | |||
| import { attemptFetchOffers } from "../../request/offersRequest"; | |||
| import { OFFERS_FETCH } from "../actions/offers/offersActionConstants"; | |||
| function* fetchOffers() { | |||
| try { | |||
| const data = yield call(attemptFetchOffers); | |||
| console.log(data); | |||
| } catch (e) { | |||
| console.log(e); | |||
| } | |||
| } | |||
| export default function* offersSaga() { | |||
| yield all([takeLatest(OFFERS_FETCH, fetchOffers)]); | |||
| } | |||
| @@ -4,25 +4,26 @@ import { REGISTER_USER_FETCH } from "../actions/register/registerActionConstants | |||
| function* fetchRegisterUser({payload}) { | |||
| try { | |||
| console.log("payload: ", payload) | |||
| const requestData = { | |||
| email: payload.mail.toString(), | |||
| password: payload.password.toString(), | |||
| email: payload.values.mail.toString(), | |||
| password: payload.values.password.toString(), | |||
| roles: [ | |||
| { | |||
| role: "User" | |||
| } | |||
| ], | |||
| company: { | |||
| name: payload.nameOfFirm.toString(), | |||
| PIB: payload.PIB.toString(), | |||
| name: payload.values.nameOfFirm.toString(), | |||
| PIB: payload.values.PIB.toString(), | |||
| contacts: { | |||
| telephone: payload.phoneNumber.toString(), | |||
| location: payload.location.toString(), | |||
| web: payload.website.toString() | |||
| telephone: payload.values.phoneNumber.toString(), | |||
| location: payload.values.location.toString(), | |||
| web: payload.values.website.toString() | |||
| } | |||
| } | |||
| } | |||
| console.log("payload: ", payload) | |||
| console.log(requestData); | |||
| const data = yield call(attemptRegister, requestData); | |||
| console.log(data); | |||
| @@ -30,9 +31,19 @@ function* fetchRegisterUser({payload}) { | |||
| yield call(payload.handleResponseSuccess); | |||
| } | |||
| } catch (e) { | |||
| console.log(e.response); | |||
| console.log(e.response.data); | |||
| let type; | |||
| if (e.response?.data?.toString() === 'User with email already exists') { | |||
| type = 'mail' | |||
| } else if (e.response?.data?.toString() === 'Company with PIB already exists') { | |||
| type = "PIB" | |||
| } | |||
| const error = { | |||
| error: e, | |||
| type | |||
| } | |||
| if (payload.handleResponseError) { | |||
| yield call(payload.handleResponseError); | |||
| yield call(payload.handleResponseError, error); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,13 @@ | |||
| import { createSelector } from 'reselect'; | |||
| const offersSelector = (state) => state.offers; | |||
| export const selectOffers = createSelector( | |||
| offersSelector, | |||
| (state) => state.offers, | |||
| ); | |||
| export const selectOffersError = createSelector( | |||
| offersSelector, | |||
| (state) => state.error, | |||
| ); | |||