diff options
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/BlockUserService.ts | 23 | ||||
| -rw-r--r-- | src/services/MomentCategoryService.ts | 7 | ||||
| -rw-r--r-- | src/services/MomentServices.ts | 17 | ||||
| -rw-r--r-- | src/services/ReportingService.ts | 10 | ||||
| -rw-r--r-- | src/services/SocialLinkingService.ts | 12 | ||||
| -rw-r--r-- | src/services/UserFriendsServices.ts | 11 | ||||
| -rw-r--r-- | src/services/UserProfileService.ts | 68 |
7 files changed, 58 insertions, 90 deletions
diff --git a/src/services/BlockUserService.ts b/src/services/BlockUserService.ts index 21e259b6..12ea0184 100644 --- a/src/services/BlockUserService.ts +++ b/src/services/BlockUserService.ts @@ -2,6 +2,7 @@ import {Alert} from 'react-native'; import {BLOCK_USER_ENDPOINT} from '../constants'; +import {ERROR_SOMETHING_WENT_WRONG_REFRESH} from '../constants/strings'; export const loadBlockedUsers = async (userId: string, token: string) => { try { @@ -44,18 +45,12 @@ export const blockOrUnblockUser = async ( return true; } else { console.log(await response.json()); - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); return false; } } catch (error) { console.log(error); - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); return false; } }; @@ -77,18 +72,12 @@ export const isUserBlocked = async ( if (Math.floor(response.status / 100) === 2) { const data = await response.json(); - return data['is_blocked']; + return data.is_blocked; } else { console.log(await response.json()); - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } } catch (error) { - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } }; diff --git a/src/services/MomentCategoryService.ts b/src/services/MomentCategoryService.ts index 57e64830..bb2c5542 100644 --- a/src/services/MomentCategoryService.ts +++ b/src/services/MomentCategoryService.ts @@ -1,5 +1,6 @@ import {Alert} from 'react-native'; import {MOMENT_CATEGORY_ENDPOINT} from '../constants'; +import {ERROR_CATEGORY_CREATION} from '../constants/strings'; export const loadMomentCategories: ( userId: string, @@ -44,10 +45,10 @@ export const postMomentCategories: ( const status = response.status; const data = await response.json(); if (status === 200) { - return data['profile_completion_stage']; + return data.profile_completion_stage; } else { - Alert.alert('There was a problem updating categories!'); - console.log('Unable to update categories'); + Alert.alert(ERROR_CATEGORY_CREATION); + console.log('Could not post categories!'); } } catch (err) { console.log(err); diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts index 91ecf712..76f353ce 100644 --- a/src/services/MomentServices.ts +++ b/src/services/MomentServices.ts @@ -1,6 +1,7 @@ import AsyncStorage from '@react-native-community/async-storage'; import {Alert} from 'react-native'; import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants'; +import {ERROR_FAILED_TO_COMMENT} from '../constants/strings'; import {MomentType} from '../types'; import {checkImageUploadStatus} from '../utils'; @@ -48,20 +49,12 @@ export const postMomentComment = async ( }, body: request, }); - const status = response.status; - if (status === 200) { - const response_data = await response.json(); - return response_data; - } else { - Alert.alert('Something went wrong! ðŸ˜', 'Not able to post a comment'); - return {}; + if (response.status !== 200) { + throw 'server error'; } + return await response.json(); } catch (error) { - Alert.alert( - 'Something went wrong! ðŸ˜', - 'Not able to post a comment', - error, - ); + Alert.alert(ERROR_FAILED_TO_COMMENT); return {}; } }; diff --git a/src/services/ReportingService.ts b/src/services/ReportingService.ts index 1563d086..8c0a4bfb 100644 --- a/src/services/ReportingService.ts +++ b/src/services/ReportingService.ts @@ -3,6 +3,10 @@ import {REPORT_ISSUE_ENDPOINT} from '../constants'; import {Alert} from 'react-native'; import AsyncStorage from '@react-native-community/async-storage'; +import { + ERROR_SOMETHING_WENT_WRONG, + MARKED_AS_MSG, +} from '../constants/strings'; export const sendReport = async ( moment_id: string, @@ -25,15 +29,15 @@ export const sendReport = async ( let statusCode = response.status; if (statusCode === 200) { - Alert.alert('Marked as ' + message.split(' ')[2]); + Alert.alert(MARKED_AS_MSG(message.split(' ')[2])); } else { - Alert.alert('Something went wrong!', 'Please try again.'); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); } if (callback) { callback(); } } catch (error) { - Alert.alert('Something went wrong!', 'Please try again.'); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); console.log( 'Something went wrong! ðŸ˜', 'Unable able to retrieve data', diff --git a/src/services/SocialLinkingService.ts b/src/services/SocialLinkingService.ts index 4a01ee50..1423c8c0 100644 --- a/src/services/SocialLinkingService.ts +++ b/src/services/SocialLinkingService.ts @@ -12,6 +12,8 @@ import { LINK_TWITTER_ENDPOINT, LINK_TWITTER_OAUTH, } from '../constants'; +import {COMING_SOON_MSG, ERROR_LINK, SUCCESS_LINK} from '../constants/strings'; +import {CategorySelection} from '../screens'; // A list of endpoint strings for all the integrated socials export const integratedEndpoints: {[social: string]: [string, string]} = { @@ -124,7 +126,7 @@ export const handlePressForAuthBrowser: ( ) => Promise<boolean> = async (socialType: string) => { try { if (!(socialType in integratedEndpoints)) { - Alert.alert('Coming soon!'); + Alert.alert(COMING_SOON_MSG); return false; } @@ -168,7 +170,7 @@ export const handlePressForAuthBrowser: ( if (!success) { throw 'Unable to register with backend'; } - Alert.alert(`Successfully linked ${socialType} 🎉`); + Alert.alert(SUCCESS_LINK(socialType)); return true; } else if (response.type === 'cancel') { return false; @@ -178,14 +180,12 @@ export const handlePressForAuthBrowser: ( }) .catch((error) => { console.log(error); - Alert.alert( - `Something went wrong, we can't link with ${socialType} 😔`, - ); + Alert.alert(ERROR_LINK(socialType)); return false; }); } catch (error) { console.log(error); - Alert.alert(`Something went wrong, we can't link with ${socialType} 😔`); + Alert.alert(ERROR_LINK(socialType)); } return false; }; diff --git a/src/services/UserFriendsServices.ts b/src/services/UserFriendsServices.ts index 0b138fc3..f7a39abf 100644 --- a/src/services/UserFriendsServices.ts +++ b/src/services/UserFriendsServices.ts @@ -2,6 +2,7 @@ import {Alert} from 'react-native'; import {FRIENDS_ENDPOINT} from '../constants'; +import {ERROR_SOMETHING_WENT_WRONG_REFRESH} from '../constants/strings'; export const loadFriends = async (userId: string, token: string) => { try { @@ -46,18 +47,12 @@ export const friendOrUnfriendUser = async ( return true; } else { console.log(await response.json()); - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); return false; } } catch (error) { console.log(error); - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); return false; } }; diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 793ee44d..830fbbb9 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -17,6 +17,17 @@ import { SEND_OTP_ENDPOINT, PROFILE_PHOTO_THUMBNAIL_ENDPOINT, } from '../constants'; +import { + ERROR_DOUBLE_CHECK_CONNECTION, + ERROR_DUP_OLD_PWD, + ERROR_INVALID_PWD_CODE, + ERROR_PWD_ACCOUNT, + ERROR_SOMETHING_WENT_WRONG, + ERROR_SOMETHING_WENT_WRONG_REFRESH, + ERROR_VERIFICATION_FAILED, + SUCCESS_PWD_RESET, + SUCCESS_VERIFICATION_CODE_SENT, +} from '../constants/strings'; export const loadProfileInfo = async (token: string, userId: string) => { try { @@ -56,10 +67,7 @@ export const loadProfileInfo = async (token: string, userId: string) => { throw 'Unable to load profile data'; } } catch (error) { - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } }; @@ -174,10 +182,7 @@ export const handlePasswordResetRequest = async (value: string) => { `Please make sure that the email / username entered is registered with us. You may contact our customer support at ${TAGG_CUSTOMER_SUPPORT}`, ); } else { - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } console.log(response); @@ -185,7 +190,7 @@ export const handlePasswordResetRequest = async (value: string) => { } } catch (error) { console.log(error); - Alert.alert('Something went wrong! ðŸ˜', 'Looks like our servers are down'); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); return false; } }; @@ -211,16 +216,11 @@ export const handlePasswordCodeVerification = async ( return true; } else { if (status == 404) { - Alert.alert( - `Please make sure that the email / username entered is registered with us. You may contact our customer support at ${TAGG_CUSTOMER_SUPPORT}`, - ); + Alert.alert(ERROR_PWD_ACCOUNT(TAGG_CUSTOMER_SUPPORT)); } else if (status === 401) { - Alert.alert('Looks like you have entered the wrong code'); + Alert.alert(ERROR_INVALID_PWD_CODE); } else { - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); } console.log(response); @@ -228,7 +228,7 @@ export const handlePasswordCodeVerification = async ( } } catch (error) { console.log(error); - Alert.alert('Something went wrong! ðŸ˜', 'Looks like our servers are down'); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); return false; } }; @@ -248,27 +248,22 @@ export const handlePasswordReset = async (value: string, password: string) => { }); const status = response.status; if (status === 200) { - Alert.alert('Your password was reset successfully'); + Alert.alert(SUCCESS_PWD_RESET); return true; } else { if (status == 404) { - Alert.alert( - `Please make sure that the email / username entered is registered with us. You may contact our customer support at ${TAGG_CUSTOMER_SUPPORT}`, - ); + Alert.alert(ERROR_PWD_ACCOUNT(TAGG_CUSTOMER_SUPPORT)); } else if (status == 406) { - Alert.alert('You may not use an already used password'); + Alert.alert(ERROR_DUP_OLD_PWD); } else { - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } console.log(response); return false; } } catch (error) { console.log(error); - Alert.alert('Something went wrong! ðŸ˜', 'Looks like our servers are down'); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); return false; } }; @@ -292,17 +287,11 @@ export const verifyOtp = async (phone: string, otp: string) => { 'Try again. Tap the resend code button if you need a new code.', ); } else { - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } } } catch (error) { - Alert.alert( - 'Verifiation failed 😓', - 'Please double-check your network connection and retry.', - ); + Alert.alert(ERROR_VERIFICATION_FAILED, ERROR_DOUBLE_CHECK_CONNECTION); return { name: 'Verification error', description: error, @@ -322,13 +311,10 @@ export const sendOtp = async (phone: string) => { let status = response.status; if (status === 200) { - Alert.alert( - 'New verification code sent!', - 'Check your phone messages for your code.', - ); + Alert.alert(SUCCESS_VERIFICATION_CODE_SENT); return true; } else { - Alert.alert('Something went wrong!'); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); return false; } } catch (error) { |
