-
Notifications
You must be signed in to change notification settings - Fork 5
/
RemoveLeagueMutation.js
47 lines (44 loc) · 1.36 KB
/
RemoveLeagueMutation.js
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
45
46
47
import React from "react";
import { Alert } from "react-native";
import { Mutation } from "react-apollo";
import * as Amplitude from 'expo-analytics-amplitude';
import gql from "graphql-tag";
const REMOVE_LEAGUE_ID = gql`
mutation removeLeagueId($leagueId: String) {
removeLeagueId(leagueId: $leagueId) @client
}
`;
const RemoveLeagueMutation = ({ children, leagueId }) => {
return (
<Mutation mutation={REMOVE_LEAGUE_ID}>
{(removeLeagueId, { loading }) => {
const removeLeagueHandler = () =>
new Promise(resolve => {
Alert.alert(
"Remove League?",
"Do you really want to remove this league from your device?",
[
{
text: "Cancel",
style: "cancel",
onPress: () => resolve(false)
},
{
text: "OK",
onPress: async () => {
await removeLeagueId({ variables: { leagueId } });
Amplitude.logEventWithProperties("RemoveLeague", {
leagueId
});
resolve(true);
}
}
]
);
});
return children({ removeLeagueHandler, loading });
}}
</Mutation>
);
};
export default RemoveLeagueMutation;