diff options
Diffstat (limited to 'src/components/profile/ProfileBody.tsx')
-rw-r--r-- | src/components/profile/ProfileBody.tsx | 45 |
1 files changed, 40 insertions, 5 deletions
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<ProfileBodyProps> = ({ 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<ProfileBodyProps> = ({ 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 ( <View onLayout={onLayout} style={styles.container}> <Text style={styles.username}>{`@${username}`}</Text> @@ -103,6 +132,9 @@ const ProfileBody: React.FC<ProfileBodyProps> = ({ {userId: userXId, username}, profile, )} + onAccept={handleAcceptRequest} + onReject={handleDeclineFriendRequest} + externalStyles={{container: styles.acceptRejectContainer}} /> ))} </View> @@ -112,6 +144,9 @@ const ProfileBody: React.FC<ProfileBodyProps> = ({ }; const styles = StyleSheet.create({ + acceptRejectContainer: { + flexDirection: 'row', + }, buttonsContainer: { flexDirection: 'row', flex: 1, |