Send_Alarm.js
17.1 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import React, { Component } from 'react';
import {Image, View, Text, StyleSheet,ScrollView,TouchableOpacity, Dimensions,TextInput } from 'react-native';
import CouponeItem from '../CouponItem'
import StampItem from '../StampItem'
import Modal from 'react-native-modal'
import DropDownPicker from 'react-native-dropdown-picker';
import Setting from '../../assets/setting.svg'
import Bin from '../../assets/bin.svg'
import AsyncStorage from '@react-native-community/async-storage';
import {get,post, delete as remove} from 'axios'
import { SERVER } from '../../common/servername';
import moment from 'moment'
import Search from '../../assets/search_yellow.svg'
import X from '../../assets/X.svg'
export default class AddTab extends Component {
static navigationOptions = {
headerShown: false
}
state = {
isModalVisible:false,
current:1,
select:'',
select_type:'전체',
dropdownVisible:false,
dropdownVisible_type:false,
store:[],
selectId:0,
selectId_type:0,
menu:[],
user:{},
content:""
}
constructor(props) {
super(props)
}
componentDidMount() {
this.onLoad()
AsyncStorage.getItem("user",(err,res) => {
if(res) {
this.setState({
user:JSON.parse(res)
})
get(`http://${SERVER}/stores/managerRead/${JSON.parse(res).id}`).then(res => {
if(res.data.success) {
this.setState({
store:res.data.data,
select:res.data.data[0].name,
selectId:res.data.data[0].id
})
get(`http://${SERVER}/menu/${res.data.data[0].id}`).then(res => {
if(res.data.success) {
this.setState({
menu:res.data.data,
})
console.log(res.data.data)
}
})
}
})
}
})
}
onLoad = () => {
this.props.navigation.addListener('willFocus', () => {
this.onRefresh();
});
};
onRefresh = () => {
get(`http://${SERVER}/stores/managerRead/${this.state.user.id}`).then(res => {
if(res.data.success) {
this.setState({
store:res.data.data,
select:res.data.data[0].name,
selectId:res.data.data[0].id
})
get(`http://${SERVER}/menu/${res.data.data[0].id}`).then(res => {
if(res.data.success) {
this.setState({
menu:res.data.data,
})
console.log(res.data.data)
}
})
}
})
}
pushAlarm = () => {
post(`http://${SERVER}/fcms`,{StoreId:this.state.selectId,name:this.state.select,content:this.state.content,type:this.state.selectId_type}).then(res => {
if(res.data.success) {
this.props.navigation.goBack(null)
}
else {
alert("서버 오류입니다. 다시 시도해주세요.")
}
})
}
handleDropdown = (e) => {
this.setState({dropdownVisible:false,select:e.name,selectId:e.id})
if(this.state.dropdownVisible_type==true) {
this.setState({
dropdownVisible_type:false
})
}
}
handleDropdown_type = (e,type) => {
this.setState({dropdownVisible_type:false,select_type:e,selectId_type:type})
if(this.state.dropdownVisible==true) {
this.setState({
dropdownVisible:false
})
}
}
render() {
return (
<View>
<View style={{width:"100%",flexDirection:"row",paddingTop:16,paddingBottom:16,paddingLeft:16,backgroundColor:"#615F5F"}}>
<TouchableOpacity onPress={() => this.props.navigation.goBack(null)}>
<Image source={require('../../assets/back.png')}/>
</TouchableOpacity>
<Text style={{color:"white",fontSize:16,marginLeft:16}}>
알림발송
</Text>
</View>
<ScrollView style={{backgroundColor:"white",paddingTop:16,height:"100%"}}>
<View style={{flexDirection:"row"}}>
<View style={{width:"75%",paddingLeft:16,paddingRight:16,}}>
<TouchableOpacity onPress={() => {this.setState({dropdownVisible:true,dropdownVisible_type:false})}} style={{paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1}}>
<Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
{this.state.select}
</Text>
</TouchableOpacity>
</View>
</View>
{this.state.dropdownVisible?
<View style={{width:"75%",height:"100%",position:"absolute",backgroundColor:"transparent",zIndex:10,paddingLeft:16,paddingRight:16}}>
<View>
{this.state.store.map((e,i,arr) => {
return (
<TouchableOpacity onPress={() => this.handleDropdown(e)
}
style={[{position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:0,borderTopWidth:0},i==0?{borderTopWidth:1}:i==arr.length-1?{borderBottomWidth:1}:{}]}>
<Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
{e.name}
</Text>
</TouchableOpacity>
)
})}
</View>
</View>:undefined}
<View style={{marginTop:16}}>
<View style={{flexDirection:"row"}}>
<View style={{width:"75%",paddingLeft:16,paddingRight:16}}>
<TouchableOpacity onPress={() => this.setState({dropdownVisible_type:true,dropdownVisible:false})} style={{paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1}}>
<Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
{this.state.select_type}
</Text>
</TouchableOpacity>
</View>
</View>
{this.state.dropdownVisible_type?
<View style={{width:"75%",height:"100%",position:"absolute",backgroundColor:"transparent",zIndex:10,paddingLeft:16,paddingRight:16}}>
<View>
{//,i==0?{borderTopWidth:1}:i==arr.length-1?{borderBottomWidth:1}:{}}
}
<TouchableOpacity onPress={() => this.handleDropdown_type('전체','all')}
style={[{zIndex:10,position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:0,borderTopWidth:1}]}>
<Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
{'전체'}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.handleDropdown_type(`쿠폰고객 ( ${1}명 )`,'coupon')}
style={[{zIndex:10,position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:0,borderTopWidth:0}]}>
<Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
{`쿠폰고객 ( ${1}명 )`}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.handleDropdown_type(`스탬프고객 ( ${1}명 )`,'stamp')}
style={[{zIndex:10,position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:0,borderTopWidth:0}]}>
<Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
{`스탬프고객 ( ${1}명 )`}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.handleDropdown_type(`찜한고객 ( ${1}명 )`,'like')}
style={[{zIndex:10,position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:0,borderTopWidth:0}]}>
<Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
{`찜한고객 ( ${1}명 )`}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.handleDropdown_type(`리뷰고객 ( ${1}명 )`,'review')}
style={[{zIndex:10,position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:0,borderTopWidth:0}]}>
<Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
{`리뷰고객 ( ${1}명 )`}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.handleDropdown_type('개별선택','ind')}
style={[{zIndex:10,position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:1,borderTopWidth:0}]}>
<Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
{`개별선택`}
</Text>
</TouchableOpacity>
</View>
</View>:undefined}
<View style={{height:"100%",paddingTop:16,paddingBottom:16,zIndex:0}}>
<View>
<Text style={{textAlignVertical:"center",paddingLeft:16,paddingRight:16,color:"#979292",fontSize:12,fontWeight:"200"}}>
5인이상 단체알림 : 월 4회 제한
</Text>
<Text style={{textAlignVertical:"center",paddingLeft:16,paddingRight:16,color:"#979292",fontSize:12,fontWeight:"200"}}>
5인미만 개별알림 : 일 2회 제한
</Text>
</View>
<View style={{width:"100%",marginTop:16.2}}>
<TextInput value={this.state.content} onChangeText={e => this.setState({content:e})} placeholder={`ex ) 단골 고객을 위한 특별한 계약\n\n1월 26일 배곧카페에서 새해 축하 치즈게이크를 무료로 드리니 많이 방문해 주시기 바랍니다.\n\n단, 1월 26일 당일 매장 방문 고객에 한함.`} style={{fontSize:14,paddingTop:23,paddingBottom:23,height:161,textAlignVertical:"top",paddingLeft:37,paddingRight:37,borderColor:"#615F5F",borderWidth:1}} multiline={true}/>
</View>
<View style={{flexDirection:'row',}}>
<TouchableOpacity onPress={() => this.pushAlarm()} style={{width:"50%",backgroundColor:"#FFD63A",paddingTop:16,paddingBottom:16}}>
<Text style={{color:"#000000",fontSize:12,fontWeight:"bold",textAlign:"center"}}>
발송
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.props.navigation.goBack(null)} style={{width:"50%",backgroundColor:"white",paddingTop:16,paddingBottom:16}}>
<Text style={{color:"#615F5F",fontSize:12,fontWeight:"bold",textAlign:"center"}}>
취소
</Text>
</TouchableOpacity>
</View>
<View style={{width:"92%",marginRight:16,flexDirection:"row",marginLeft:16,paddingBottom:16,borderBottomColor:"#BDBCBC",borderBottomWidth:1}}>
<View style={{marginTop:16,borderRightColor:"#BDBCBC",borderRightWidth:1,paddingRight:10}}>
<View style={{flexDirection:"row",justifyContent:"space-between",marginBottom:16}}>
<Text style={{color:"#615F5F",fontSize:14}}>
20.1.23
</Text>
<Text style={{width:"70%"}} numberOfLines={1}>
크리스마스 특별 이벤트 ㄴ어리ㅏㅁㅇ너리ㅏㄴㅇ머라ㅣ
</Text>
</View>
<View style={{flexDirection:"row",justifyContent:"space-between"}}>
<Text style={{color:"#615F5F",fontSize:15,fontWeight:"bold"}}>
발송 {1234}
</Text>
<Text style={{color:"#615F5F",fontSize:15,fontWeight:"bold"}}>
미확인 {990}
</Text>
<Text style={{color:"#615F5F",fontSize:15,fontWeight:"bold"}}>
확인 {345}
</Text>
</View>
</View>
<View style={{justifyContent:"center",marginTop:16,marginLeft:"auto",marginRight:"auto"}}>
<Search onPress={() => this.setState({isModalVisible:true})} width={20} height={20} style={{marginLeft:"auto",marginRight:"auto"}}/>
</View>
</View>
</View>
</View>
</ScrollView>
<Modal onBackButtonPress={() => this.setState({isModalVisible:false})} onBackdropPress={() => this.setState({isModalVisible:false})} isVisible={this.state.isModalVisible}>
<View style={{width:"100%",paddingTop:16,paddingBottom:16,paddingLeft:16,paddingRight:16,backgroundColor:"white"}}>
<X style={{marginLeft:"auto"}}/>
<View style={{flexDirection:"row"}}>
<Text style={{fontSize:16,fontWeight:"bold"}}>
{`${"크리스마스 특별 이벤트 ㄴ어리ㅏㅁㅇ너리ㅏㄴㅇ머라ㅣ"}`}
</Text>
<Text style={{fontSize:12,marginTop:16,fontWeight:"300",marginLeft:"auto",textAlign:"right"}}>
{`${moment(new Date()).format("YYYY.M.DD")}`}
</Text>
</View>
<View>
<Text style={{marginTop:5}}>
{`${"item.content"}`}
</Text>
</View>
</View>
</Modal>
</View>
);
}
}
const style = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});