1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
import {Alert} from 'react-native';
import {WAITLIST_USER_ENDPOINT} from '../constants';
export const adduserToWaitlist: (
phone_number: string,
first_name: string,
last_name: string,
) => Promise<boolean> = async (phone_number, first_name, last_name) => {
try {
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;
};
|