From c758389ad2ebe98196d4618ec08dbf2b24d95bfa Mon Sep 17 00:00:00 2001 From: Ashm Walia <40498934+ashmgarv@users.noreply.github.com> Date: Tue, 12 Jan 2021 13:35:33 -0800 Subject: [TMA 472] Added option to be added to Taggs wait list (#168) * Added screens to add to waitlist and a page to display on success of the same * Incorporated small comment --- src/services/WaitlistUserService.tsx | 45 ++++++++++++++++++++++++++++++++++++ src/services/index.ts | 1 + 2 files changed, 46 insertions(+) create mode 100644 src/services/WaitlistUserService.tsx (limited to 'src/services') diff --git a/src/services/WaitlistUserService.tsx b/src/services/WaitlistUserService.tsx new file mode 100644 index 00000000..516affe3 --- /dev/null +++ b/src/services/WaitlistUserService.tsx @@ -0,0 +1,45 @@ +import {Alert} from 'react-native'; +import {WAITLIST_USER_ENDPOINT} from '../constants'; + +export const adduserToWaitlist: ( + phone_number: string, + first_name: string, + last_name: string, +) => Promise = async (phone_number, first_name, last_name) => { + try { + console.log(phone_number, first_name, last_name); + const response = await fetch(WAITLIST_USER_ENDPOINT, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + phone_number, + first_name, + last_name, + }), + }); + const status = response.status; + const message = await response.json(); + if (status === 200) { + return true; + } else { + if (status === 409) { + Alert.alert('You are already on our waitlist / on our app'); + } else if (status === 400) { + Alert.alert('Some information needed was missing / ill-formatted'); + } else if (status === 500) { + Alert.alert( + 'Something went wrong. Sorry unable to add you to the waitlist 😔', + ); + } + console.log(message); + } + } catch (err) { + Alert.alert( + 'Something went wrong. Sorry unable to add you to the waitlist 😔', + ); + console.log(err); + } + return false; +}; diff --git a/src/services/index.ts b/src/services/index.ts index 7ea5bf5d..56cefddd 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -8,3 +8,4 @@ export * from './BlockUserService'; export * from './MomentCategoryService'; export * from './NotificationService'; export * from './FCMService'; +export * from './WaitlistUserService'; -- cgit v1.2.3-70-g09d2