Sfoglia il codice sorgente

Added back button to chat, handled removed offer case, handled socket error

feature/625
Djordje Mitrovic 3 anni fa
parent
commit
53b4df7c2d
24 ha cambiato i file con 274 aggiunte e 124 eliminazioni
  1. 4
    0
      src/components/Buttons/ArrowButton/ArrowButton.styled.js
  2. 0
    1
      src/components/Cards/CreateOfferCard/CreateOffer.js
  3. 0
    4
      src/components/Cards/ItemDetailsCard/ItemDetailsCard.js
  4. 2
    0
      src/components/Cards/OfferCard/CheckButton/CheckButton.js
  5. 7
    3
      src/components/Cards/OfferCard/OfferCard.js
  6. 16
    7
      src/components/ChatColumn/ChatColumn.js
  7. 23
    13
      src/components/DirectChat/DirectChat.js
  8. 9
    9
      src/components/DirectChat/DirectChatContent/DirectChatContent.js
  9. 15
    5
      src/components/DirectChat/DirectChatContent/DirectChatContentHeader/DirectChatContentHeader.js
  10. 2
    0
      src/components/DirectChat/DirectChatContent/DirectChatContentHeader/DirectChatContentHeader.styled.js
  11. 1
    0
      src/components/DirectChat/DirectChatHeader/DirectChatHeader.js
  12. 1
    3
      src/components/DirectChat/DirectChatHeader/DirectChatHeader.styled.js
  13. 15
    0
      src/components/DirectChat/DirectChatHeaderTitle/DirectChatHeaderTitle.js
  14. 19
    2
      src/components/DirectChat/DirectChatHeaderTitle/DirectChatHeaderTitle.styled.js
  15. 24
    18
      src/components/DirectChat/DirectChatNewMessage/DirectChatNewMessage.js
  16. 22
    0
      src/components/DirectChat/DirectChatNewMessage/NotAllowedChat/NotAllowedChat.js
  17. 18
    0
      src/components/DirectChat/DirectChatNewMessage/NotAllowedChat/NotAllowedChat.styled.js
  18. 4
    2
      src/components/Popovers/PhonePopover/PhonePopover.js
  19. 0
    2
      src/components/Profile/ProfileOffers/SelectSortField/SelectSortField.js
  20. 2
    0
      src/i18n/resources/rs.js
  21. 14
    2
      src/socket/socket.js
  22. 1
    0
      src/store/actions/chat/chatActionConstants.js
  23. 71
    47
      src/store/actions/chat/chatActions.js
  24. 4
    6
      src/store/saga/chatSaga.js

+ 4
- 0
src/components/Buttons/ArrowButton/ArrowButton.styled.js Vedi File

@@ -21,6 +21,10 @@ export const ArrowIcon = styled(DownArrow)`
stroke: ${selectedTheme.colors.iconStrokeDisabledColor}
`}
}
@media (max-width: 600px) {
top: -3px;
left: -2px;
}
`;
export const ArrowContainer = styled(IconButton)`
border: 1px solid ${selectedTheme.colors.primaryPurple} !important;

+ 0
- 1
src/components/Cards/CreateOfferCard/CreateOffer.js Vedi File

@@ -50,7 +50,6 @@ const CreateOffer = ({ closeCreateOfferModal, editOffer, offer }) => {
const handleNext = (values) => {
setInformations({ ...informations, ...values });
setCurrentStep((prevState) => prevState + 1);
console.log({ ...informations, ...values });
};

// Get new images from 2nd step

+ 0
- 4
src/components/Cards/ItemDetailsCard/ItemDetailsCard.js Vedi File

@@ -26,7 +26,6 @@ import _ from "lodash";
import { selectUserId } from "../../../store/selectors/loginSelectors";
import {
formatDateLocale,
formatDateTimeLocale,
} from "../../../util/helpers/dateHelpers";
import { startChat } from "../../../util/helpers/chatHelper";
import Information from "./Information/Information";
@@ -46,8 +45,6 @@ const ItemDetailsCard = (props) => {
const userId = useSelector(selectUserId);
const { t } = useTranslation();
const dispatch = useDispatch();
console.log(props.offer);
console.log(formatDateTimeLocale(new Date()));
const offer = useMemo(() => {
if (props.offer) {
if (
@@ -85,7 +82,6 @@ const ItemDetailsCard = (props) => {
const closeRemoveModalHandler = () => {
setShowModalRemove(false);
};
console.log(props.previewCard);
return (
<>
<ItemDetailsCardContainer

+ 2
- 0
src/components/Cards/OfferCard/CheckButton/CheckButton.js Vedi File

@@ -22,6 +22,7 @@ const CheckButton = (props) => {
textcolor={props.sponsored ? "white" : selectedTheme.colors.primaryPurple}
style={{ fontWeight: "600" }}
onClick={() => routeToItem(props.offerId)}
disabled={props.disabled}
>
{t("offer.checkButtonLabel")}
</CheckButtonContainer>
@@ -31,6 +32,7 @@ const CheckButton = (props) => {
CheckButton.propTypes = {
sponsored: PropTypes.bool,
offerId: PropTypes.string,
disabled: PropTypes.bool,
};

export default CheckButton;

+ 7
- 3
src/components/Cards/OfferCard/OfferCard.js Vedi File

@@ -47,7 +47,9 @@ const OfferCard = (props) => {
const { isMobile } = useIsMobile();

const routeToItem = (itemId) => {
history.push(`/proizvodi/${itemId}`);
if (!props.disabledCheckButton) {
history.push(`/proizvodi/${itemId}`);
}
};
const messageUser = () => {
props.messageUser(props.offer);
@@ -90,7 +92,7 @@ const OfferCard = (props) => {
}
halfwidth={props.halfwidth ? 1 : 0}
>
{/* This only shows on vertical offer card */}
{/* This only shows on vertical offer card */}
<OfferTitleAboveImage
vertical={props.vertical}
onClick={() => routeToItem(props?.offer?._id)}
@@ -98,7 +100,7 @@ const OfferCard = (props) => {
{props?.offer?.name}
</OfferTitleAboveImage>
{/* ^^^^^^^ */}
<OfferFlexContainer vertical={props.vertical}>
<OfferImageContainer vertical={props.vertical}>
<OfferImage
@@ -153,6 +155,7 @@ const OfferCard = (props) => {
<Line />
<OfferDescription description={props?.offer?.description} />
<CheckButton
disabled={props.disabledCheckButton}
offerId={props?.offer?._id}
sponsored={props.sponsored}
/>
@@ -236,6 +239,7 @@ OfferCard.propTypes = {
makeReview: PropTypes.func,
dontShowViews: PropTypes.bool,
skeleton: PropTypes.bool,
disabledCheckButton: PropTypes.bool,
};
OfferCard.defaultProps = {
halfwidth: false,

+ 16
- 7
src/components/ChatColumn/ChatColumn.js Vedi File

@@ -18,7 +18,10 @@ import { HeaderTitle } from "../Cards/ProfileCard/ProfileCard.styled";
import { useTranslation } from "react-i18next";
import { useDispatch, useSelector } from "react-redux";
import { selectLatestChats } from "../../store/selectors/chatSelectors";
import { addNewMessage, fetchChats } from "../../store/actions/chat/chatActions";
import {
addNewMessage,
fetchChats,
} from "../../store/actions/chat/chatActions";
import useSorting from "../../hooks/useOffers/useSorting";
import { addMesageListener, removeMessageListener } from "../../socket/socket";

@@ -40,14 +43,20 @@ export const ChatColumn = () => {
}, []);

useEffect(() => {
addMesageListener((data) => {
dispatch(addNewMessage({
_id: data.chatId,
message: data.message
}))
addMesageListener(({ succeed, data }) => {
if (succeed) {
dispatch(
addNewMessage({
_id: data.chatId,
message: data.message,
})
);
} else {
dispatch(fetchChats());
}
});
return () => removeMessageListener();
}, [])
}, []);

useEffect(() => {
setSortOption(sorting.selectedSortOption);

+ 23
- 13
src/components/DirectChat/DirectChat.js Vedi File

@@ -23,6 +23,8 @@ import { selectIsLoadingByActionType } from "../../store/selectors/loadingSelect
import { CHAT_SCOPE } from "../../store/actions/chat/chatActionConstants";
import { selectUserId } from "../../store/selectors/loginSelectors";
import { addMesageListener, removeMessageListener } from "../../socket/socket";
import { makeErrorToastMessage } from "../../store/utils/makeToastMessage";
import { useTranslation } from "react-i18next";

const DirectChat = () => {
const chat = useSelector(selectSelectedChat);
@@ -31,6 +33,7 @@ const DirectChat = () => {
const routeMatch = useRouteMatch();
const location = useLocation();
const dispatch = useDispatch();
const { t } = useTranslation();

const userId = useSelector(selectUserId);
const isLoadingDirectChat = useSelector(
@@ -69,7 +72,7 @@ const DirectChat = () => {
};
}, [chat, location.state, offer]);

// Fetch chat after it is created
// Fetch chat after it is created
// (renders after state of location changes)
useEffect(() => {
if (routeMatch.params.idChat) {
@@ -79,24 +82,31 @@ const DirectChat = () => {

// Listener to socket.IO chat
useEffect(() => {
addMesageListener((data) => {
if (
[...allChats].find((item) => {
return item.chat._id === data.chatId;
})
) {
dispatch(
addNewMessage({
_id: data.chatId,
message: data.message,
addMesageListener(({ succeed, data }) => {
console.log(succeed);
if (succeed) {
if (
[...allChats].find((item) => {
return item.chat._id === data.chatId;
})
);
) {
dispatch(
addNewMessage({
_id: data.chatId,
message: data.message,
})
);
} else {
dispatch(fetchChats());
}
} else {
dispatch(fetchChats());
dispatch(fetchOneChat(routeMatch.params.idChat));
makeErrorToastMessage(t("apiErrors.somethingWentWrong"));
}
});
return () => removeMessageListener();
}, [allChats]);
}, [allChats, routeMatch]);

const refreshChat = () => {
if (routeMatch.params.idChat === "newMessage") {

+ 9
- 9
src/components/DirectChat/DirectChatContent/DirectChatContent.js Vedi File

@@ -29,19 +29,19 @@ const DirectChatContent = (props) => {
top: messagesRef.current.scrollHeight,
behaviour: "smooth",
});
}, [messages]);
}, [props?.chat?.chat?.messages, messagesRef, isLoadingChatContent]);

const handleRefresh = () => {
props.refreshChat();
};
useEffect(() => {
// const offsetBottom =
// messagesRef.current?.offsetTop + messagesRef.current?.offsetHeight;
messagesRef.current?.scrollTo({
top: messagesRef.current.scrollHeight,
behaviour: "smooth",
});
}, [messages]);
// useEffect(() => {
// // const offsetBottom =
// // messagesRef.current?.offsetTop + messagesRef.current?.offsetHeight;
// messagesRef.current?.scrollTo({
// top: messagesRef.current.scrollHeight,
// behaviour: "smooth",
// });
// }, [messages, messagesRef]);
return (
<>
{isLoadingChatContent || isLoadingChatContent === undefined ? (

+ 15
- 5
src/components/DirectChat/DirectChatContent/DirectChatContentHeader/DirectChatContentHeader.js Vedi File

@@ -16,6 +16,9 @@ import PopoverComponent from "../../../Popovers/PopoverComponent";
import PhonePopover from "../../../Popovers/PhonePopover/PhonePopover";
import { getImageUrl, variants } from "../../../../util/helpers/imageUrlGetter";
import useIsMobile from "../../../../hooks/useIsMobile";
import history from "../../../../store/utils/history";
import { replaceInRoute } from "../../../../util/helpers/routeHelpers";
import { PROFILE_PAGE } from "../../../../constants/pages";

const DirectChatContentHeader = (props) => {
const [showPhonePopover, setShowPhonePopover] = useState(false);
@@ -23,19 +26,24 @@ const DirectChatContentHeader = (props) => {
const { isMobile } = useIsMobile();

const togglePhonePopover = (event) => {
console.log(phonePopoverAnchorEl);
console.log(event);
setShowPhonePopover((prevState) => !prevState);
setPhonePopoverAnchorEl((prevState) => {
if (prevState) return null;
return event.target;
});
};

const routeToUser = () => {
history.push(
replaceInRoute(PROFILE_PAGE, {
idProfile: props?.interlucator?.userId,
})
);
};
return (
<DirectChatContentHeaderContainer>
<DirectChatContentHeaderFlexContainer>
<ProfileImage
onClick={routeToUser}
src={getImageUrl(
props?.interlucator?.image,
variants.chatHeader,
@@ -43,7 +51,9 @@ const DirectChatContentHeader = (props) => {
)}
/>
<ProfileDetails>
<ProfileName>{props?.interlucator?.name}</ProfileName>
<ProfileName onClick={routeToUser}>
{props?.interlucator?.name}
</ProfileName>
<ProfileLocation>
<ProfileLocationIcon />
<ProfileLocationText>
@@ -62,7 +72,7 @@ const DirectChatContentHeader = (props) => {
open={showPhonePopover}
anchorRight
onClose={togglePhonePopover}
content={<PhonePopover />}
content={<PhonePopover phoneNumber={props.interlucator?.telephone} />}
/>
</DirectChatContentHeaderContainer>
);

+ 2
- 0
src/components/DirectChat/DirectChatContent/DirectChatContentHeader/DirectChatContentHeader.styled.js Vedi File

@@ -25,6 +25,7 @@ export const ProfileImage = styled.img`
height: 54px;
border-radius: 100%;
overflow: hidden;
cursor: pointer;
`
export const ProfileDetails = styled(Box)`
display: flex;
@@ -36,6 +37,7 @@ export const ProfileName = styled(Box)`
font-family: ${selectedTheme.fonts.textFont};
font-size: 16px;
color: ${selectedTheme.colors.primaryPurple};
cursor: pointer;
`
export const ProfileLocation = styled(Box)`
display: flex;

+ 1
- 0
src/components/DirectChat/DirectChatHeader/DirectChatHeader.js Vedi File

@@ -69,6 +69,7 @@ const DirectChatHeader = (props) => {
disabledReviews={isDisabledReviews}
makeReview={makeReview}
dontShowViews
disabledCheckButton={props?.offer?._deleted}
/>
</DirectChatHeaderContainer>
);

+ 1
- 3
src/components/DirectChat/DirectChatHeader/DirectChatHeader.styled.js Vedi File

@@ -1,6 +1,4 @@
import { Box } from "@mui/material";
import styled from "styled-components";

export const DirectChatHeaderContainer = styled(Box)`

`
export const DirectChatHeaderContainer = styled(Box)``;

+ 15
- 0
src/components/DirectChat/DirectChatHeaderTitle/DirectChatHeaderTitle.js Vedi File

@@ -1,16 +1,31 @@
import React from "react";
import PropTypes from "prop-types";
import {
ButtonContainer,
DirectChatHeaderTitleContainer,
HeaderText,
HeaderTitleContent,
MessageIcon,
} from "./DirectChatHeaderTitle.styled";
import { useTranslation } from "react-i18next";
import { ArrowButton } from "../../Buttons/ArrowButton/ArrowButton";
import useIsMobile from "../../../hooks/useIsMobile";
import history from "../../../store/utils/history";

const DirectChatHeaderTitle = () => {
const { t } = useTranslation();
const { isMobile } = useIsMobile();
const goBackToMessages = () => {
history.goBack();
};
return (
<DirectChatHeaderTitleContainer>
{isMobile && (
<ButtonContainer onClick={goBackToMessages}>
<ArrowButton side={"left"}></ArrowButton>
<HeaderText>{t("messages.goBack")}</HeaderText>
</ButtonContainer>
)}
<MessageIcon />
<HeaderTitleContent>{t("messages.headerTitle")}</HeaderTitleContent>
</DirectChatHeaderTitleContainer>

+ 19
- 2
src/components/DirectChat/DirectChatHeaderTitle/DirectChatHeaderTitle.styled.js Vedi File

@@ -1,4 +1,4 @@
import { Box, Typography } from "@mui/material";
import { Box, Link, Typography } from "@mui/material";
import styled from "styled-components";
import {ReactComponent as Message} from "../../../assets/images/svg/message.svg";
import selectedTheme from "../../../themes";
@@ -15,4 +15,21 @@ export const HeaderTitleContent = styled(Typography)`
position: relative;
left: 9px;
bottom: 7px;
`
`
export const ButtonContainer = styled(Link)`
width: fit-content;
cursor: pointer;
display: flex;
justify-content: start;
align-items: center;
gap: 12px;
text-decoration: none;
margin-bottom: 36px;
`;
export const HeaderText = styled(Typography)`
font-family: ${selectedTheme.fonts.textFont};
line-height: 22px;
font-size: 16px;
color: ${selectedTheme.colors.primaryPurple};
border-bottom: 1px dotted ${selectedTheme.colors.primaryPurple};
`;

+ 24
- 18
src/components/DirectChat/DirectChatNewMessage/DirectChatNewMessage.js Vedi File

@@ -18,6 +18,7 @@ import {
import { useHistory, useLocation } from "react-router-dom";
import { selectExchange } from "../../../store/selectors/exchangeSelector";
import { validateExchange } from "../../../store/actions/exchange/exchangeActions";
import NotAllowedChat from "./NotAllowedChat/NotAllowedChat";

const DirectChatNewMessage = (props) => {
const [typedValue, setTypedValue] = useState("");
@@ -83,25 +84,30 @@ const DirectChatNewMessage = (props) => {
})
);
};
if (props?.chat?.offer?.offer?._deleted) {
return <NotAllowedChat />;
}
return (
<DirectChatNewMessageContainer>
<NewMessageField
placeholder={t("messages.sendPlaceholder")}
fullWidth
onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
italicPlaceholder
value={typedValue}
onChange={(typed) => setTypedValue(typed.target.value)}
/>
<SendButton
onClick={handleSend}
buttoncolor={selectedTheme.colors.primaryPurple}
variant="contained"
>
{t("messages.send")}
</SendButton>
</DirectChatNewMessageContainer>
<>
<DirectChatNewMessageContainer>
<NewMessageField
placeholder={t("messages.sendPlaceholder")}
fullWidth
onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
italicPlaceholder
value={typedValue}
onChange={(typed) => setTypedValue(typed.target.value)}
/>
<SendButton
onClick={handleSend}
buttoncolor={selectedTheme.colors.primaryPurple}
variant="contained"
>
{t("messages.send")}
</SendButton>
</DirectChatNewMessageContainer>
</>
);
};


+ 22
- 0
src/components/DirectChat/DirectChatNewMessage/NotAllowedChat/NotAllowedChat.js Vedi File

@@ -0,0 +1,22 @@
import React from "react";
import PropTypes from "prop-types";
import {
NotAllowedChatContainer,
NotAllowedChatText,
} from "./NotAllowedChat.styled";
import { useTranslation } from "react-i18next";

const NotAllowedChat = () => {
const { t } = useTranslation();
return (
<NotAllowedChatContainer>
<NotAllowedChatText>{t("messages.notAllowedChat")}</NotAllowedChatText>
</NotAllowedChatContainer>
);
};

NotAllowedChat.propTypes = {
children: PropTypes.node,
};

export default NotAllowedChat;

+ 18
- 0
src/components/DirectChat/DirectChatNewMessage/NotAllowedChat/NotAllowedChat.styled.js Vedi File

@@ -0,0 +1,18 @@
import { Box, Typography } from "@mui/material";
import styled from "styled-components";
import selectedTheme from "../../../../themes";

export const NotAllowedChatText = styled(Typography)`
font-family: ${selectedTheme.fonts.textFont};
font-weight: 700;
font-size: 16px;
line-height: 21px;
text-align: center;
color: ${selectedTheme.colors.primaryPurple};
`;
export const NotAllowedChatContainer = styled(Box)`
text-align: center;
border-top: 1px solid ${selectedTheme.colors.messageBackground};
margin: 0 36px;
padding-top: 30px;
`

+ 4
- 2
src/components/Popovers/PhonePopover/PhonePopover.js Vedi File

@@ -8,19 +8,21 @@ import {
} from "./PhonePopover.styled";
import { useTranslation } from "react-i18next";

const PhonePopover = () => {
const PhonePopover = (props) => {
const {t} = useTranslation();
console.log(props);
return (
<PhonePopoverContainer>
<Arrow />
<PhoneLabel>{t("common.labelPhoneNumber")}</PhoneLabel>
<PhoneNumber>065/000-018</PhoneNumber>
<PhoneNumber>{props.phoneNumber}</PhoneNumber>
</PhonePopoverContainer>
);
};

PhonePopover.propTypes = {
children: PropTypes.node,
phoneNumber: PropTypes.string,
};

export default PhonePopover;

+ 0
- 2
src/components/Profile/ProfileOffers/SelectSortField/SelectSortField.js Vedi File

@@ -31,11 +31,9 @@ const SelectSortField = (props) => {
}, [sortOption]);
const handleChangeSelect = (event) => {
let chosenOption;
console.log(sortOption);
for (const sortOption in sortEnum) {
if (sortEnum[sortOption].value === event.target.value) {
chosenOption = sortEnum[sortOption];
console.log(chosenOption);
setSortOption(chosenOption);
}
}

+ 2
- 0
src/i18n/resources/rs.js Vedi File

@@ -216,6 +216,8 @@ export default {
sendPlaceholder: "Poruka...",
seeChats: "Pogledaj ćaskanje",
noMessagesToast: "Nemate ni jednu poruku!",
notAllowedChat: "Trampa za ovaj proizvod je završena.",
goBack: "Nazad na sve poruke"
},
editProfile: {
website: "Web Sajt*",

+ 14
- 2
src/socket/socket.js Vedi File

@@ -27,8 +27,20 @@ export const sendMessage = (chatId, userId, text, receiverUserId) => {
};

export const addMesageListener = (listener) => {
return socket.on("private_message", listener);
socket.on("private_message", (data) =>
listener({
succeed: true,
data,
})
);
socket.on("sending_message_failed", (data) =>
listener({
succeed: false,
data,
})
);
};
export const removeMessageListener = () => {
return socket.off("private_message");
socket.off("private_message");
socket.off("sending_message_failed");
};

+ 1
- 0
src/store/actions/chat/chatActionConstants.js Vedi File

@@ -35,4 +35,5 @@ export const CHAT_SET = createSetType("CHAT_SET");
export const CHAT_ONE_SET = createSetType("CHAT_ONE_SET");
export const CHAT_CLEAR = createSetType("CHAT_CLEAR");
export const CHAT_ADD_MESSAGE = createSetType("CHAT_ADD_MESSAGE");
export const CHAT_REMOVE_MESSAGE = createSetType("CHAT_REMOVE_MESSAGE");
// export const ADD_ONE_CHAT = "CHAT_ONE_ADD";

+ 71
- 47
src/store/actions/chat/chatActions.js Vedi File

@@ -1,67 +1,91 @@
import { CHAT_ADD_MESSAGE, CHAT_CLEAR, CHAT_FETCH, CHAT_FETCH_ERROR, CHAT_FETCH_SUCCESS, CHAT_HEADER_FETCH, CHAT_HEADER_FETCH_ERROR, CHAT_HEADER_FETCH_SUCCESS, CHAT_NEW_FETCH, CHAT_NEW_FETCH_ERROR, CHAT_NEW_FETCH_SUCCESS, CHAT_ONE_FETCH, CHAT_ONE_FETCH_ERROR, CHAT_ONE_FETCH_SUCCESS, CHAT_ONE_SET, CHAT_SEND_ERROR, CHAT_SEND_FETCH, CHAT_SEND_SUCCESS, CHAT_SET } from "./chatActionConstants";
import {
CHAT_ADD_MESSAGE,
CHAT_CLEAR,
CHAT_FETCH,
CHAT_FETCH_ERROR,
CHAT_FETCH_SUCCESS,
CHAT_HEADER_FETCH,
CHAT_HEADER_FETCH_ERROR,
CHAT_HEADER_FETCH_SUCCESS,
CHAT_NEW_FETCH,
CHAT_NEW_FETCH_ERROR,
CHAT_NEW_FETCH_SUCCESS,
CHAT_ONE_FETCH,
CHAT_ONE_FETCH_ERROR,
CHAT_ONE_FETCH_SUCCESS,
CHAT_ONE_SET,
CHAT_REMOVE_MESSAGE,
CHAT_SEND_ERROR,
CHAT_SEND_FETCH,
CHAT_SEND_SUCCESS,
CHAT_SET,
} from "./chatActionConstants";

export const fetchChats = (payload) => ({
type: CHAT_FETCH,
payload,
})
type: CHAT_FETCH,
payload,
});
export const fetchHeaderChats = (payload) => ({
type: CHAT_HEADER_FETCH,
payload,
})
type: CHAT_HEADER_FETCH,
payload,
});
export const setChats = (payload) => ({
type: CHAT_SET,
payload,
})
type: CHAT_SET,
payload,
});
export const fetchOneChat = (payload) => ({
type: CHAT_ONE_FETCH,
payload,
})
type: CHAT_ONE_FETCH,
payload,
});
export const setOneChat = (payload) => ({
type: CHAT_ONE_SET,
payload,
})
type: CHAT_ONE_SET,
payload,
});
export const sendMessage = (payload) => ({
type: CHAT_SEND_FETCH,
payload,
})
type: CHAT_SEND_FETCH,
payload,
});
export const clearChat = () => ({
type: CHAT_CLEAR
})
type: CHAT_CLEAR,
});
export const startNewChat = (payload) => ({
type: CHAT_NEW_FETCH,
payload
})
type: CHAT_NEW_FETCH,
payload,
});
export const fetchChatsSuccess = () => ({
type: CHAT_FETCH_SUCCESS
})
type: CHAT_FETCH_SUCCESS,
});
export const fetchHeaderChatsSuccess = () => ({
type: CHAT_HEADER_FETCH_SUCCESS
})
type: CHAT_HEADER_FETCH_SUCCESS,
});
export const fetchOneChatSuccess = () => ({
type: CHAT_ONE_FETCH_SUCCESS
})
type: CHAT_ONE_FETCH_SUCCESS,
});
export const sendMessageSuccess = () => ({
type: CHAT_SEND_SUCCESS
})
type: CHAT_SEND_SUCCESS,
});
export const startNewChatSuccess = () => ({
type: CHAT_NEW_FETCH_SUCCESS
})
type: CHAT_NEW_FETCH_SUCCESS,
});
export const fetchChatsError = () => ({
type: CHAT_FETCH_ERROR
})
type: CHAT_FETCH_ERROR,
});
export const fetchHeaderChatsError = () => ({
type: CHAT_HEADER_FETCH_ERROR
})
type: CHAT_HEADER_FETCH_ERROR,
});
export const fetchOneChatError = () => ({
type: CHAT_ONE_FETCH_ERROR
})
type: CHAT_ONE_FETCH_ERROR,
});
export const sendMessageError = () => ({
type: CHAT_SEND_ERROR
})
type: CHAT_SEND_ERROR,
});
export const startNewChatError = () => ({
type: CHAT_NEW_FETCH_ERROR
})
type: CHAT_NEW_FETCH_ERROR,
});
export const addNewMessage = (payload) => ({
type: CHAT_ADD_MESSAGE,
payload
})
type: CHAT_ADD_MESSAGE,
payload,
});
export const removeLastMessage = () => ({
type: CHAT_REMOVE_MESSAGE,
});

+ 4
- 6
src/store/saga/chatSaga.js Vedi File

@@ -6,7 +6,6 @@ import {
attemptFetchOneChat,
attemptSendMessage,
} from "../../request/chatRequest";
import { attemptFetchOneOffer } from "../../request/offersRequest";
import {
CHAT_FETCH,
CHAT_HEADER_FETCH,
@@ -61,15 +60,14 @@ function* fetchHeaderChats() {
function* fetchOneChat(payload) {
try {
const chatData = yield call(attemptFetchOneChat, payload.payload);
const offerData = yield call(
attemptFetchOneOffer,
chatData.data.chat.offerId
);
const chat = {
chat: chatData.data.chat,
offer: offerData.data,
offer: {
offer: { ...chatData.data.offer, images: [chatData.data.offer.image] },
},
interlocutor: chatData.data.interlocutorData,
};
(chatData);
yield put(setOneChat(chat));
yield put(fetchOneChatSuccess());
} catch (e) {

Loading…
Annulla
Salva