aboutsummaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorAshm Walia <40498934+ashmgarv@users.noreply.github.com>2021-01-12 15:38:21 -0800
committerGitHub <noreply@github.com>2021-01-12 18:38:21 -0500
commitd495bff07b50c47e842dc2c139922d56c87f5c9b (patch)
treec6f592fa72a6158981fef2feba1b3dca5ff6cc2a /src/services
parentc758389ad2ebe98196d4618ec08dbf2b24d95bfa (diff)
[TMA 491 Frontend] Revamp onboarding (#173)
* First commit, arrow excluded * Done from my side * Some small nitpicks * exclude tsconfig * Show profile screen after onboarding * Update string * Small fix * small cosmetic
Diffstat (limited to 'src/services')
-rw-r--r--src/services/MomentCategoryService.ts10
-rw-r--r--src/services/MomentServices.ts52
-rw-r--r--src/services/UserProfileService.ts2
3 files changed, 59 insertions, 5 deletions
diff --git a/src/services/MomentCategoryService.ts b/src/services/MomentCategoryService.ts
index 32c721ae..57e64830 100644
--- a/src/services/MomentCategoryService.ts
+++ b/src/services/MomentCategoryService.ts
@@ -31,8 +31,7 @@ export const loadMomentCategories: (
export const postMomentCategories: (
categories: string[],
token: string,
-) => Promise<boolean> = async (categories, token) => {
- let success = false;
+) => Promise<number | undefined> = async (categories, token) => {
try {
const response = await fetch(MOMENT_CATEGORY_ENDPOINT, {
method: 'POST',
@@ -43,15 +42,16 @@ export const postMomentCategories: (
body: JSON.stringify({categories}),
});
const status = response.status;
+ const data = await response.json();
if (status === 200) {
- success = true;
+ return data['profile_completion_stage'];
} else {
Alert.alert('There was a problem updating categories!');
console.log('Unable to update categories');
}
} catch (err) {
console.log(err);
- return success;
+ return undefined;
}
- return success;
+ return undefined;
};
diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts
index 96643bc3..91ecf712 100644
--- a/src/services/MomentServices.ts
+++ b/src/services/MomentServices.ts
@@ -2,6 +2,7 @@ import AsyncStorage from '@react-native-community/async-storage';
import {Alert} from 'react-native';
import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants';
import {MomentType} from '../types';
+import {checkImageUploadStatus} from '../utils';
//Get all comments for a moment
export const getMomentComments = async (
@@ -97,6 +98,57 @@ export const getMomentCommentsCount = async (
}
};
+export const postMoment: (
+ fileName: string,
+ uri: string,
+ caption: string,
+ category: string,
+ userId: string,
+) => Promise<number | undefined> = async (
+ fileName,
+ uri,
+ caption,
+ category,
+ userId,
+) => {
+ try {
+ const request = new FormData();
+ //Manipulating filename to end with .jpg instead of .heic
+ if (fileName.endsWith('.heic') || fileName.endsWith('.HEIC')) {
+ fileName = fileName.split('.')[0] + '.jpg';
+ }
+ request.append('image', {
+ uri: uri,
+ name: fileName,
+ type: 'image/jpg',
+ });
+ request.append('moment', category);
+ request.append('user_id', userId);
+ request.append('captions', JSON.stringify({image: caption}));
+ const token = await AsyncStorage.getItem('token');
+ let response = await fetch(MOMENTS_ENDPOINT, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'multipart/form-data',
+ Authorization: 'Token ' + token,
+ },
+ body: request,
+ });
+ let statusCode = response.status;
+ let data = await response.json();
+ if (statusCode === 200 && checkImageUploadStatus(data['moments'])) {
+ Alert.alert('The picture was uploaded successfully!');
+ return data['profile_completion_stage'];
+ } else {
+ Alert.alert('An error occured while uploading. Please try again!');
+ }
+ } catch (err) {
+ console.log(err);
+ Alert.alert('An error occured during authenticaion. Please login again!');
+ }
+ return undefined;
+};
+
export const loadMoments: (
userId: string,
token: string,
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts
index 75042830..793ee44d 100644
--- a/src/services/UserProfileService.ts
+++ b/src/services/UserProfileService.ts
@@ -38,6 +38,7 @@ export const loadProfileInfo = async (token: string, userId: string) => {
snapchat,
tiktok,
university_class,
+ profile_completion_stage,
} = info;
birthday = birthday && moment(birthday).format('YYYY-MM-DD');
return {
@@ -49,6 +50,7 @@ export const loadProfileInfo = async (token: string, userId: string) => {
snapchat,
tiktok,
university_class,
+ profile_completion_stage,
};
} else {
throw 'Unable to load profile data';