diff options
author | Shravya Ramesh <shravs1208@gmail.com> | 2021-04-27 17:56:21 -0700 |
---|---|---|
committer | Shravya Ramesh <shravs1208@gmail.com> | 2021-04-27 17:56:21 -0700 |
commit | 9d3108e29838474372e5242a040dd80c593aae4e (patch) | |
tree | 6e85f102d5f2ee1326041d8aaa69e815162e90fc /src | |
parent | bf126bc7618278f3300d45897fd3e196a551445f (diff) |
func to call remove badge serv, dispatch action
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/users.ts | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/utils/users.ts b/src/utils/users.ts index 7148eb79..87bcbdfc 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -1,6 +1,6 @@ import AsyncStorage from '@react-native-community/async-storage'; import {INTEGRATED_SOCIAL_LIST} from '../constants'; -import {isUserBlocked, loadSocialPosts} from '../services'; +import {isUserBlocked, loadSocialPosts, removeBadgesService} from '../services'; import { loadAllSocials, loadBlockedList, @@ -10,6 +10,7 @@ import { loadUserMoments, loadUserNotifications, logout, + updateUserBadges, } from '../store/actions'; import {NO_SOCIAL_ACCOUNTS} from '../store/initialStates'; import {loadUserMomentCategories} from './../store/actions/momentCategories'; @@ -21,6 +22,7 @@ import { ProfileInfoType, ScreenType, UserType, + UniversityBadge, } from './../types/types'; const loadData = async (dispatch: AppDispatch, user: UserType) => { @@ -204,3 +206,20 @@ export const canViewProfile = ( } return false; }; + +/* Function to call remove badge service, + * remove selected badge from list passed in and + * dispatch thunk action to update store + */ +export const removeUserBadge = async ( + badges: UniversityBadge[], + badgeName: string, + userId: string, + dispatch: AppDispatch, +) => { + const success = await removeBadgesService([badgeName], userId); + if (success === true) { + badges = badges.filter((badge) => badge.name !== badgeName); + dispatch(updateUserBadges(badges)); + } +}; |