From 96fda980905d0c7a30813c364c6623dda695012f Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 29 Jan 2021 15:14:26 -0800 Subject: full screen; with button; needs refresh&alignment; --- src/store/actions/userFriends.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/store') diff --git a/src/store/actions/userFriends.ts b/src/store/actions/userFriends.ts index 18ad247c..ae808e9a 100644 --- a/src/store/actions/userFriends.ts +++ b/src/store/actions/userFriends.ts @@ -11,6 +11,7 @@ import { declineFriendRequestService, friendOrUnfriendUser, loadFriends, + unfriendService, } from '../../services'; import {Action, ThunkAction} from '@reduxjs/toolkit'; import { @@ -85,6 +86,39 @@ export const friendUnfriendUser = ( } }; +export const unfriendUser = ( + friend: ProfilePreviewType, // userX's profile preview + screenType: ScreenType, //screentype from content +): ThunkAction, RootState, unknown, Action> => async ( + dispatch, +) => { + try { + const token = await getTokenOrLogout(dispatch); + // Calls method to send post or delete request + const success = await unfriendService(friend.id, token); + if (success) { + let data = 'no_record'; + await dispatch({ + type: updateFriends.type, + payload: { + friend, + isFriend: true, + }, + }); + await dispatch({ + type: userXFriendshipEdited.type, + payload: { + userId: friend.id, + screenType, + data, + }, + }); + } + } catch (error) { + console.log(error); + } +}; + export const acceptFriendRequest = ( requester: ProfilePreviewType, ): ThunkAction, RootState, unknown, Action> => async ( -- cgit v1.2.3-70-g09d2