diff options
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/common.ts | 17 | ||||
| -rw-r--r-- | src/utils/users.ts | 77 |
2 files changed, 94 insertions, 0 deletions
diff --git a/src/utils/common.ts b/src/utils/common.ts index ce4ab7d1..95e77f64 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -180,3 +180,20 @@ const _crestIcon = (university: UniversityType) => { return require('../assets/images/bwbadges.png'); } }; + +export const validateImageLink = async (url: string | undefined) => { + if (!url) { + return false; + } + return fetch(url) + .then((res) => { + if (res.status === 200) { + return true; + } else { + return false; + } + }) + .catch((_) => { + return false; + }); +}; diff --git a/src/utils/users.ts b/src/utils/users.ts index 334cb3c0..bc81bbc6 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -1,3 +1,4 @@ +import {Alert} from 'react-native'; import AsyncStorage from '@react-native-community/async-storage'; import {INTEGRATED_SOCIAL_LIST} from '../constants'; import {isUserBlocked, loadSocialPosts, removeBadgesService} from '../services'; @@ -24,6 +25,8 @@ import { UserType, UniversityBadge, } from './../types/types'; +import ImagePicker from 'react-native-image-crop-picker'; +import {patchEditProfile} from '../services'; const loadData = async (dispatch: AppDispatch, user: UserType) => { await Promise.all([ @@ -240,3 +243,77 @@ export const navigateToProfile = async ( screenType, }); }; + +export const patchProfile = async (title: string, userId: string) => { + let imageSettings = {}; + switch (title) { + case 'Select Header Picture': + imageSettings = { + smartAlbums: [ + 'Favorites', + 'RecentlyAdded', + 'SelfPortraits', + 'Screenshots', + 'UserLibrary', + ], + width: 580, + height: 580, + cropping: true, + cropperToolbarTitle: title, + mediaType: 'photo', + }; + break; + case 'Select Profile Picture': + imageSettings = { + smartAlbums: [ + 'Favorites', + 'RecentlyAdded', + 'SelfPortraits', + 'Screenshots', + 'UserLibrary', + ], + width: 580, + height: 580, + cropping: true, + cropperToolbarTitle: title, + mediaType: 'photo', + cropperCircleOverlay: true, + }; + break; + } + + return await ImagePicker.openPicker(imageSettings) + .then((picture) => { + if ('path' in picture) { + const request = new FormData(); + switch (title) { + case 'Select Header Picture': + request.append('largeProfilePicture', { + uri: picture.path, + name: 'large_profile_pic.jpg', + type: 'image/jpg', + }); + break; + case 'Select Profile Picture': + request.append('smallProfilePicture', { + uri: picture.path, + name: 'small_profile_pic.jpg', + type: 'image/jpg', + }); + break; + } + + return patchEditProfile(request, userId) + .then((_) => { + return true; + }) + .catch((error) => { + Alert.alert(error); + return false; + }); + } + }) + .catch((_) => { + return false; + }); +}; |
