aboutsummaryrefslogtreecommitdiff
path: root/src/services/ReportingService.ts
blob: 1563d08666024863ac8db293c68f0a358793233c (plain)
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
//Common moments api abstracted out here

import {REPORT_ISSUE_ENDPOINT} from '../constants';
import {Alert} from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';

export const sendReport = async (
  moment_id: string,
  message: string,
  callback?: Function,
) => {
  try {
    let token = await AsyncStorage.getItem('token');
    let response = await fetch(REPORT_ISSUE_ENDPOINT, {
      method: 'POST',
      body: JSON.stringify({
        resource_id: moment_id,
        type: 'content',
        reason: message,
      }),
      headers: {
        Authorization: 'Token ' + token,
      },
    });

    let statusCode = response.status;
    if (statusCode === 200) {
      Alert.alert('Marked as ' + message.split(' ')[2]);
    } else {
      Alert.alert('Something went wrong!', 'Please try again.');
    }
    if (callback) {
      callback();
    }
  } catch (error) {
    Alert.alert('Something went wrong!', 'Please try again.');
    console.log(
      'Something went wrong! 😭',
      'Unable able to retrieve data',
      error,
    );
  }
};