/
Page.tsx
147 lines (135 loc) · 3.51 KB
/
Page.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
143
144
145
146
147
import React, { FC, memo } from 'react';
import { SafeAreaView, Alert, StatusBar, TouchableOpacity } from 'react-native';
import EStyleSheet from 'react-native-extended-stylesheet';
import {
useActionSheet,
ActionSheetOptions,
} from '@expo/react-native-action-sheet';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import Color from 'color';
import GlobalStyles from '../../../GlobalStyles';
import { SelectItemDetail } from '../../../domain/itemDetail';
import { KINDS } from '../../../lib/getKind';
import s from '../../../config/style';
import theme from '../../../config/theme';
import Card from '../../molecules/ScheduleDetail/Card';
import Header from '../../molecules/Header';
import Loading from '../../molecules/ScheduleDetail/Loading';
type ConnectedProps = SelectItemDetail & {
loading: boolean;
onDismiss: () => void;
onDelete: () => void;
onCreateScheduleDetail: () => void;
};
type Props = ConnectedProps & {
showActionSheetWithOptions: (
options: ActionSheetOptions,
callback: (i: number) => void
) => void;
};
export type ScheduleDetailType = {
onOpenActionSheet: () => void;
};
const Connected: FC<ConnectedProps> = props => {
const { showActionSheetWithOptions } = useActionSheet();
return (
<ScheduleDetailPage
{...props}
showActionSheetWithOptions={showActionSheetWithOptions}
/>
);
};
export const ScheduleDetailPage: FC<Props> = memo(props => {
const onOpenActionSheet = () => {
props.showActionSheetWithOptions(
{
options: ['編集', '削除', 'キャンセル'],
destructiveButtonIndex: 1,
cancelButtonIndex: 2,
},
buttonIndex => {
if (buttonIndex === 0) {
props.onCreateScheduleDetail();
}
if (buttonIndex === 1) {
Alert.alert(
'削除しますか?',
'',
[
{
text: 'キャンセル',
style: 'cancel',
},
{
text: '削除する',
onPress: () => {
props.onDelete();
},
},
],
{ cancelable: false }
);
}
}
);
};
const kind = props.kind;
const config = KINDS[kind];
const ss = s.schedule;
const bc = Color(config.backgroundColor)
.lighten(ss.backgroundColorAlpha)
.toString();
if (props.loading) {
return <Loading />;
}
return (
<>
<Header
title=""
color={'none'}
right={
<TouchableOpacity
onPress={onOpenActionSheet}
testID="ScheduleDetailMenu"
>
<MaterialCommunityIcons
name="dots-horizontal"
size={30}
color={theme().color.main}
style={styles.icon}
/>
</TouchableOpacity>
}
onClose={props.onDismiss}
/>
<StatusBar
backgroundColor={theme().color.white}
barStyle="dark-content"
/>
<SafeAreaView
style={[
GlobalStyles.droidSafeArea,
styles.header,
{ backgroundColor: bc },
]}
/>
<SafeAreaView style={styles.contents}>
<Card {...props} onOpenActionSheet={onOpenActionSheet} />
</SafeAreaView>
</>
);
});
export default Connected;
const styles = EStyleSheet.create({
contents: {
flex: 1,
backgroundColor: '$background',
},
icon: {
marginRight: 0,
marginLeft: 'auto',
},
header: {
flex: 0,
},
});