aboutsummaryrefslogtreecommitdiff
path: root/src/utils/users.ts
diff options
context:
space:
mode:
authorBrian Kim <brian@tagg.id>2021-05-12 17:42:47 -0700
committerBrian Kim <brian@tagg.id>2021-05-12 17:42:47 -0700
commit853bd0600e0da87af578c17ce9249e40888017b5 (patch)
treeee52f9d527536c41a040d06179be9f57f6663581 /src/utils/users.ts
parentd930b614bd79bcd7b55359be261f77fa6997f78e (diff)
Modularized as much as possible
Diffstat (limited to 'src/utils/users.ts')
-rw-r--r--src/utils/users.ts77
1 files changed, 77 insertions, 0 deletions
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;
+ });
+};