From ed91266981e1662b512baa1856d8c921a8718e68 Mon Sep 17 00:00:00 2001 From: Ashm Walia Date: Fri, 15 Jan 2021 16:20:29 -0800 Subject: fixes --- src/components/profile/Content.tsx | 8 +++++- src/components/profile/ProfileBody.tsx | 45 ++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 6 deletions(-) (limited to 'src/components/profile') diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index 339144d6..f7b4b71c 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -21,7 +21,13 @@ import { UserType, } from '../../types'; import {COVER_HEIGHT, TAGG_TEXT_LIGHT_BLUE} from '../../constants'; -import {fetchUserX, getUserAsProfilePreviewType, moveCategory, SCREEN_HEIGHT, userLogin} from '../../utils'; +import { + fetchUserX, + getUserAsProfilePreviewType, + moveCategory, + SCREEN_HEIGHT, + userLogin, +} from '../../utils'; import TaggsBar from '../taggs/TaggsBar'; import {Moment} from '../moments'; import ProfileBody from './ProfileBody'; diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx index 87c12424..edda5d43 100644 --- a/src/components/profile/ProfileBody.tsx +++ b/src/components/profile/ProfileBody.tsx @@ -8,11 +8,18 @@ import { } from '../../constants'; import ToggleButton from './ToggleButton'; import {RootState} from '../../store/rootReducer'; -import {useSelector} from 'react-redux'; +import {useDispatch, useSelector, useStore} from 'react-redux'; import {FriendshipStatusType, ScreenType} from '../../types'; import {NO_PROFILE} from '../../store/initialStates'; import {getUserAsProfilePreviewType, SCREEN_WIDTH} from '../../utils'; import {AcceptDeclineButtons} from '../common'; +import { + acceptFriendRequest, + declineFriendRequest, + loadUserNotifications, + updateUserXFriends, + updateUserXProfileAllScreens, +} from '../../store/actions'; interface ProfileBodyProps { onLayout: (event: LayoutChangeEvent) => void; @@ -30,10 +37,7 @@ const ProfileBody: React.FC = ({ userXId, screenType, }) => { - const { - profile = NO_PROFILE, - user: {username}, - } = userXId + const {profile = NO_PROFILE, user} = userXId ? useSelector((state: RootState) => state.userX[screenType][userXId]) : useSelector((state: RootState) => state.user); @@ -44,6 +48,31 @@ const ProfileBody: React.FC = ({ friendship_requester_id, } = profile; + const {id, username, first_name, last_name} = getUserAsProfilePreviewType( + user, + profile, + ); + + const state: RootState = useStore().getState(); + const dispatch = useDispatch(); + + const handleAcceptRequest = async () => { + try { + await dispatch( + acceptFriendRequest({id, username, first_name, last_name}), + ); + await dispatch(updateUserXFriends(id, state)); + dispatch(updateUserXProfileAllScreens(id)); + } catch (err) { + console.log(err); + } + }; + + const handleDeclineFriendRequest = async () => { + await dispatch(declineFriendRequest(id)); + dispatch(updateUserXProfileAllScreens(id)); + }; + return ( {`@${username}`} @@ -103,6 +132,9 @@ const ProfileBody: React.FC = ({ {userId: userXId, username}, profile, )} + onAccept={handleAcceptRequest} + onReject={handleDeclineFriendRequest} + externalStyles={{container: styles.acceptRejectContainer}} /> ))} @@ -112,6 +144,9 @@ const ProfileBody: React.FC = ({ }; const styles = StyleSheet.create({ + acceptRejectContainer: { + flexDirection: 'row', + }, buttonsContainer: { flexDirection: 'row', flex: 1, -- cgit v1.2.3-70-g09d2