Przeglądaj źródła

Finished 2126

bugfix/2126
jovan.cirkovic 3 lat temu
rodzic
commit
252c43f309

+ 6
- 2
src/components/Cards/CreateOfferCard/CreateOffer.js Wyświetl plik

import { closeModal } from "../../../store/actions/modal/modalActions"; import { closeModal } from "../../../store/actions/modal/modalActions";
import { selectQueryString } from "../../../store/selectors/queryStringSelectors"; import { selectQueryString } from "../../../store/selectors/queryStringSelectors";
import { routeMatches } from "../../../util/helpers/routeHelpers"; import { routeMatches } from "../../../util/helpers/routeHelpers";
import { fetchProfile } from "../../../store/actions/profile/profileActions";


const CreateOffer = ({ editOffer, offer, isAdmin, customUserId }) => { const CreateOffer = ({ editOffer, offer, isAdmin, customUserId }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
dynamicRouteMatches(PROFILE_PAGE) || dynamicRouteMatches(PROFILE_PAGE) ||
dynamicRouteMatches(ADMIN_SINGLE_USER_PAGE) dynamicRouteMatches(ADMIN_SINGLE_USER_PAGE)
) { ) {
if (isAdmin)
if (isAdmin) {
dispatch(fetchProfileOffers({ idProfile: customUserId, isAdmin })); dispatch(fetchProfileOffers({ idProfile: customUserId, isAdmin }));
else dispatch(fetchProfileOffers(userId));
} else {
dispatch(fetchProfileOffers(userId));
dispatch(fetchProfile(userId));
}
console.log("tu je gde treba"); console.log("tu je gde treba");
} else if ( } else if (
dynamicRouteMatches(ITEM_DETAILS_PAGE) || dynamicRouteMatches(ITEM_DETAILS_PAGE) ||

+ 16
- 3
src/components/Cards/ItemDetailsCard/ItemDetailsCard.js Wyświetl plik

toggleDeleteOfferModal, toggleDeleteOfferModal,
toggleEditOfferModal, toggleEditOfferModal,
} from "../../../store/actions/modal/modalActions"; } from "../../../store/actions/modal/modalActions";
import { fetchChats } from "../../../store/actions/chat/chatActions";
import { getExistChat } from "../../../store/actions/chat/chatActions";


const ItemDetailsCard = (props) => { const ItemDetailsCard = (props) => {
// const offer = props.offer; // const offer = props.offer;


const date = formatDateLocale(new Date(offer?._created)); const date = formatDateLocale(new Date(offer?._created));


const handleApiResponseSuccess = (value) => {
if (value === false) {
startChat(chats, offer, userId);
} else {
startChat(chats, offer, value._id);
}
};

const startExchange = () => { const startExchange = () => {
dispatch(fetchChats({ userId: userId, offerId: props.offer._id }));
startChat(chats, offer, userId);
dispatch(
getExistChat({
userId: userId,
offerId: props.offer._id,
handleApiResponseSuccess,
})
);
}; };


const showDeleteOfferModalHandler = () => { const showDeleteOfferModalHandler = () => {

+ 4
- 1
src/components/Cards/OfferCard/DeleteOffer/DeleteOffer.js Wyświetl plik

PROFILE_PAGE, PROFILE_PAGE,
} from "../../../../constants/pages"; } from "../../../../constants/pages";
import { OfferDescriptionContainer } from "./DeleteOfferLabeledCard/DeleteOfferLabeledCard.styled"; import { OfferDescriptionContainer } from "./DeleteOfferLabeledCard/DeleteOfferLabeledCard.styled";
import { fetchProfile } from "../../../../store/actions/profile/profileActions";


const DeleteOffer = (props) => { const DeleteOffer = (props) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
if ( if (
dynamicRouteMatches(PROFILE_PAGE) || dynamicRouteMatches(PROFILE_PAGE) ||
dynamicRouteMatches(ADMIN_SINGLE_USER_PAGE) dynamicRouteMatches(ADMIN_SINGLE_USER_PAGE)
)
) {
dispatch(fetchProfileOffers({ idProfile: userId, isAdmin: true })); dispatch(fetchProfileOffers({ idProfile: userId, isAdmin: true }));
dispatch(fetchProfile(userId));
}
if (routeMatches(HOME_PAGE) || routeMatches(BASE_PAGE)) if (routeMatches(HOME_PAGE) || routeMatches(BASE_PAGE))
dispatch(fetchOffers({ queryString })); dispatch(fetchOffers({ queryString }));
if (dynamicRouteMatches(ITEM_DETAILS_PAGE)) { if (dynamicRouteMatches(ITEM_DETAILS_PAGE)) {

+ 1
- 0
src/components/MarketPlace/MarketPlace.js Wyświetl plik

const userId = useSelector(selectUserId); const userId = useSelector(selectUserId);
const dispatch = useDispatch(); const dispatch = useDispatch();
useEffect(() => { useEffect(() => {
console.log("ABG", userId);
if (userId) if (userId)
dispatch( dispatch(
fetchChats({ fetchChats({

+ 2
- 1
src/components/Popovers/MyMessages/MyMessages.js Wyświetl plik

}; };


useEffect(() => { useEffect(() => {
if (history.location.pathname.includes("messages")) return;
if (userId?.length > 1) { if (userId?.length > 1) {
dispatch(fetchHeaderChats(userId)); dispatch(fetchHeaderChats(userId));
} }
const goToMessages = () => { const goToMessages = () => {
if (lastChats.length !== 0) { if (lastChats.length !== 0) {
console.log(chats); console.log(chats);
goToMessage(chats[0]?._id)
goToMessage(chats[0]?._id);
} else { } else {
makeErrorToastMessage(t("messages.noMessagesToast")); makeErrorToastMessage(t("messages.noMessagesToast"));
props.closePopover(); props.closePopover();

+ 6
- 3
src/pages/HomePage/HomePage.js Wyświetl plik

import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { OFFERS_SCOPE } from "../../store/actions/offers/offersActionConstants"; import { OFFERS_SCOPE } from "../../store/actions/offers/offersActionConstants";
import useOffers from "../../hooks/useOffers/useOffers"; import useOffers from "../../hooks/useOffers/useOffers";
import useIsLoggedIn from "../../hooks/useIsLoggedIn";
// import useIsLoggedIn from "../../hooks/useIsLoggedIn";
import AboutPageContent from "../../components/About/AboutPageContent"; import AboutPageContent from "../../components/About/AboutPageContent";
import { selectUserId } from "../../store/selectors/loginSelectors";


const HomePage = (props) => { const HomePage = (props) => {
const { isLoggedIn } = useIsLoggedIn();
// const { isLoggedIn } = useIsLoggedIn();
const userId = useSelector(selectUserId);
const isLoadingOffers = useSelector( const isLoadingOffers = useSelector(
selectIsLoadingByActionType(OFFERS_SCOPE) selectIsLoadingByActionType(OFFERS_SCOPE)
); );
const toggleFilters = () => { const toggleFilters = () => {
setFiltersOpened((prevFiltersOpened) => !prevFiltersOpened); setFiltersOpened((prevFiltersOpened) => !prevFiltersOpened);
}; };
if (isLoggedIn || props?.isMarketplacePage) {
console.log("ABBGAG");
if (userId || props?.isMarketplacePage) {
return ( return (
<HomePageContainer> <HomePageContainer>
<MainLayout <MainLayout

+ 1
- 0
src/request/apiEndpoints.js Wyświetl plik

getOneChat: "users/{userId}/chats/{chatId}", getOneChat: "users/{userId}/chats/{chatId}",
createChat: "users/{userId}/offers/{offerId}/chat", createChat: "users/{userId}/offers/{offerId}/chat",
sendMessage: "chats", sendMessage: "chats",
getExistChat: "users/{userId}/offers/{offerId}/chat",
}, },
exchange: { exchange: {
getExchange: "exchanges", getExchange: "exchanges",

+ 9
- 0
src/request/chatRequest.js Wyświetl plik

}) })
); );
}; };

export const attemptGetExistChat = (payload) => {
return getRequest(
replaceInUrl(apiEndpoints.chat.getExistChat, {
userId: payload.userId,
offerId: payload.offerId,
})
);
};

+ 2
- 3
src/request/index.js Wyświetl plik

// queryString.stringify(params, { arrayFormat: "comma" }), // queryString.stringify(params, { arrayFormat: "comma" }),
}); });


export const getRequest = (url, params = null, options = null) => {
return request.get(url, { params, ...options });
};
export const getRequest = (url, params = null, options = null) =>
request.get(url, { params, ...options });


export const postRequest = (url, data, params = null, options = null) => export const postRequest = (url, data, params = null, options = null) =>
request.post(url, data, { params, ...options }); request.post(url, data, { params, ...options });

+ 5
- 0
src/store/actions/chat/chatActionConstants.js Wyświetl plik

const CHAT_ONE_SCOPE = "CHAT_ONE_SCOPE"; const CHAT_ONE_SCOPE = "CHAT_ONE_SCOPE";
const CHAT_SEND_SCOPE = "CHAT_SEND_SCOPE"; const CHAT_SEND_SCOPE = "CHAT_SEND_SCOPE";
const CHAT_NEW_SCOPE = "CHAT_NEW_SCOPE"; const CHAT_NEW_SCOPE = "CHAT_NEW_SCOPE";
const EXIST_CHAT_SCOPE = "EXIST_CHAT_SCOPE";


export const CHAT_FETCH = createFetchType(CHAT_SCOPE); export const CHAT_FETCH = createFetchType(CHAT_SCOPE);
export const CHAT_FETCH_SUCCESS = createSuccessType(CHAT_SCOPE); export const CHAT_FETCH_SUCCESS = createSuccessType(CHAT_SCOPE);
export const CHAT_ADD_MESSAGE = createSetType("CHAT_ADD_MESSAGE"); export const CHAT_ADD_MESSAGE = createSetType("CHAT_ADD_MESSAGE");
export const CHAT_REMOVE_MESSAGE = createSetType("CHAT_REMOVE_MESSAGE"); export const CHAT_REMOVE_MESSAGE = createSetType("CHAT_REMOVE_MESSAGE");
// export const ADD_ONE_CHAT = "CHAT_ONE_ADD"; // export const ADD_ONE_CHAT = "CHAT_ONE_ADD";

export const GET_EXIST_CHAT = createFetchType(EXIST_CHAT_SCOPE);
export const GET_EXIST_CHAT_SUCCESS = createSetType(EXIST_CHAT_SCOPE);
export const GET_EXIST_CHAT_ERROR = createSetType(EXIST_CHAT_SCOPE);

+ 13
- 0
src/store/actions/chat/chatActions.js Wyświetl plik

CHAT_SEND_SUCCESS, CHAT_SEND_SUCCESS,
CHAT_SET, CHAT_SET,
CHAT_TOTAL_SET, CHAT_TOTAL_SET,
GET_EXIST_CHAT,
GET_EXIST_CHAT_ERROR,
GET_EXIST_CHAT_SUCCESS,
} from "./chatActionConstants"; } from "./chatActionConstants";


export const fetchChats = (payload) => ({ export const fetchChats = (payload) => ({
export const removeLastMessage = () => ({ export const removeLastMessage = () => ({
type: CHAT_REMOVE_MESSAGE, type: CHAT_REMOVE_MESSAGE,
}); });
export const getExistChat = (payload) => ({
type: GET_EXIST_CHAT,
payload,
});
export const getExistChatSuccess = () => ({
type: GET_EXIST_CHAT_SUCCESS,
});
export const getExistChatError = () => ({
type: GET_EXIST_CHAT_ERROR,
});

+ 7
- 4
src/store/middleware/authenticationMiddleware.js Wyświetl plik

import { makeErrorToastMessage } from "../utils/makeToastMessage"; import { makeErrorToastMessage } from "../utils/makeToastMessage";


//Interceptor unique name //Interceptor unique name
export const authenticationMiddlewareInterceptorName = "AUTHENTICATION_MIDDLEWARE";
export const authenticationMiddlewareInterceptorName =
"AUTHENTICATION_MIDDLEWARE";


export default ({ dispatch }) => export default ({ dispatch }) =>
(next) => (next) =>
(action) => { (action) => {
attachPostRequestListener((error) => { attachPostRequestListener((error) => {
if (!error.response) { if (!error.response) {
return makeErrorToastMessage(i18next.t("apiErrors.somethingWentWrong"));
makeErrorToastMessage(i18next.t("apiErrors.somethingWentWrong"));
return Promise.reject(error);
} }
if (error.response.status === 401) { if (error.response.status === 401) {
dispatch(logoutUser()); dispatch(logoutUser());
return makeErrorToastMessage(i18next.t("apiErrors.somethingWentWrong"));
return Promise.reject(error);
} }
return Promise.reject(error);
return Promise.resolve();
// return Promise.resolve(error);
}, authenticationMiddlewareInterceptorName); }, authenticationMiddlewareInterceptorName);


next(action); next(action);

+ 24
- 0
src/store/saga/chatSaga.js Wyświetl plik

attemptFetchChats, attemptFetchChats,
attemptFetchHeaderChats, attemptFetchHeaderChats,
attemptFetchOneChat, attemptFetchOneChat,
attemptGetExistChat,
attemptSendMessage, attemptSendMessage,
} from "../../request/chatRequest"; } from "../../request/chatRequest";
import { import {
CHAT_NEW_FETCH, CHAT_NEW_FETCH,
CHAT_ONE_FETCH, CHAT_ONE_FETCH,
CHAT_SEND_FETCH, CHAT_SEND_FETCH,
GET_EXIST_CHAT,
} from "../actions/chat/chatActionConstants"; } from "../actions/chat/chatActionConstants";
import { import {
addNewMessage, addNewMessage,
fetchHeaderChatsSuccess, fetchHeaderChatsSuccess,
fetchOneChatError, fetchOneChatError,
fetchOneChatSuccess, fetchOneChatSuccess,
getExistChatError,
getExistChatSuccess,
sendMessageError, sendMessageError,
sendMessageSuccess, sendMessageSuccess,
setChats, setChats,
console.dir(e); console.dir(e);
} }
} }

function* fetchOneChat(payload) { function* fetchOneChat(payload) {
try { try {
const userId = yield select(selectUserId); const userId = yield select(selectUserId);
} }
} }


function* getExistChat(payload) {
try {
const data = yield call(attemptGetExistChat, {
userId: payload.payload.userId,
offerId: payload.payload.offerId,
});
console.log(data);
yield put(getExistChatSuccess());

if (payload.payload.handleApiResponseSuccess) {
yield call(payload.payload.handleApiResponseSuccess, data.data);
}
} catch (error) {
yield put(getExistChatError());
console.log(error);
}
}

export default function* chatSaga() { export default function* chatSaga() {
yield all([ yield all([
takeLatest(CHAT_FETCH, fetchChats), takeLatest(CHAT_FETCH, fetchChats),
takeLatest(CHAT_HEADER_FETCH, fetchHeaderChats), takeLatest(CHAT_HEADER_FETCH, fetchHeaderChats),
takeLatest(CHAT_SEND_FETCH, sendMessage), takeLatest(CHAT_SEND_FETCH, sendMessage),
takeLatest(CHAT_NEW_FETCH, startNewChat), takeLatest(CHAT_NEW_FETCH, startNewChat),
takeLatest(GET_EXIST_CHAT, getExistChat),
]); ]);
} }

+ 4
- 2
src/store/saga/loginSaga.js Wyświetl plik

try { try {
const isAdmin = payload.isAdmin; const isAdmin = payload.isAdmin;
// delete payload.isAdmin // delete payload.isAdmin
const { data } = yield call(attemptLogin, payload);
if (data.token) {
const dataFromBe = yield call(attemptLogin, payload);
const data = dataFromBe?.data;
if (data?.token) {
const token = data.token; const token = data.token;
const refresh = data.refresh; const refresh = data.refresh;
const tokenDecoded = jwt.decode(token); const tokenDecoded = jwt.decode(token);
} }
} }
} catch (e) { } catch (e) {
console.dir(e);
if (e.message) { if (e.message) {
yield put(fetchUserError(e.message)); yield put(fetchUserError(e.message));
} }

Ładowanie…
Anuluj
Zapisz