/
SettingModal.tsx
142 lines (123 loc) · 4.17 KB
/
SettingModal.tsx
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import React, { memo, useCallback } from 'react';
import { StyleSheet, TouchableOpacity, Linking, Platform } from 'react-native';
import { useSetRecoilState, useRecoilValue } from 'recoil';
import { useNavigation } from '@react-navigation/native';
import View from 'components/atoms/View';
import Text from 'components/atoms/Text';
import Modal from 'components/organisms/Modal';
import Divider from 'components/atoms/Divider';
import Constants from 'expo-constants';
import * as IntentLauncher from 'expo-intent-launcher';
import theme from 'config/theme';
import Debug from 'components/organisms/Debug/Debug';
import { useNotification } from 'containers/Notification';
import { authUserState, userState } from 'store/atoms';
import { storageKey, removeItem } from 'lib/storage';
import { ScreenNavigationProp as HomeScreenNavigationProp } from 'components/pages/Home';
type Props = {
isVisible: boolean;
onClose: () => void;
};
const SettingModal: React.FC<Props> = (props) => {
const navigation = useNavigation<HomeScreenNavigationProp>();
const { onPermissionRequest } = useNotification();
const authUser = useRecoilValue(authUserState);
const setUser = useSetRecoilState(userState);
const onLicence = useCallback(() => {
props.onClose();
navigation.navigate('SettingLicence');
}, [navigation, props]);
const onMyPage = useCallback(() => {
props.onClose();
navigation.navigate('MyPage');
}, [navigation, props]);
const onSettingMemoir = useCallback(() => {
props.onClose();
navigation.navigate('SettingMemoir');
}, [navigation, props]);
const onLogout = useCallback(async () => {
await removeItem(storageKey.USER_ID_KEY);
await removeItem(storageKey.AUTH_UID_KEY);
setUser({ id: null, userID: '', displayName: '', image: '' });
}, [setUser]);
const onPushNotificationSetting = useCallback(() => {
if (Platform.OS === 'ios') {
Linking.canOpenURL('app-settings:')
.then((supported) => {
if (supported) {
return Linking.openURL('app-settings:');
}
console.log('move to app-settings: not supported');
return;
})
.catch((err) => console.log(err));
} else {
IntentLauncher.startActivityAsync(
IntentLauncher.ACTION_NOTIFICATION_SETTINGS
);
}
}, []);
const onNotificationSetting = useCallback(async () => {
if (!onPermissionRequest) {
return;
}
onPermissionRequest(onPushNotificationSetting);
}, [onPermissionRequest, onPushNotificationSetting]);
return (
<Modal isVisible={props.isVisible} title="設定" onClose={props.onClose}>
<View style={styles.root} p={3} pt={4}>
<TouchableOpacity style={styles.menuText} onPress={onMyPage}>
<View>
<Text>アカウント設定</Text>
</View>
</TouchableOpacity>
<Divider my={3} />
<TouchableOpacity onPress={onSettingMemoir} style={styles.menuText}>
<View>
<Text>ふりかえり日時を変更する</Text>
</View>
</TouchableOpacity>
<Divider my={3} />
<TouchableOpacity
style={styles.menuText}
onPress={onNotificationSetting}
>
<View>
<Text>通知設定</Text>
</View>
</TouchableOpacity>
<Divider my={3} />
<TouchableOpacity style={styles.menuText}>
<View>
<Text>規約</Text>
</View>
</TouchableOpacity>
<Divider my={3} />
<TouchableOpacity style={styles.menuText} onPress={onLicence}>
<View>
<Text>著作権</Text>
</View>
</TouchableOpacity>
<Divider my={3} />
{!authUser.uid && (
<>
<TouchableOpacity style={styles.menuText} onPress={onLogout}>
<View>
<Text color="error">ログアウト</Text>
</View>
</TouchableOpacity>
<Divider my={3} />
</>
)}
{!Constants.isDevice && <Debug />}
</View>
</Modal>
);
};
export default memo(SettingModal);
const styles = StyleSheet.create({
root: {},
menuText: {
paddingLeft: theme().space(2),
},
});