Inquiry.js
10.6 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
import React, { Component } from 'react';
import { View, Text, StyleSheet,TouchableOpacity,Image, TextInput, Dimensions } from 'react-native';
import CheckBox from '@react-native-community/checkbox'
import X from '../../assets/X.svg'
import { ScrollView } from 'react-native-gesture-handler';
import Heart from '../../assets/heart_.svg'
import Chat from '../../assets/chat_.svg'
import Home from '../../assets/home.svg'
import QR from '../../assets/qr.svg'
import Alarm from '../../assets/alarm.svg'
import Modal from 'react-native-modal'
import {post, get} from 'axios'
import Notice from '../Notice'
import { SERVER } from '../../common/servername';
import AsyncStorage from '@react-native-community/async-storage';
import moment from 'moment';
export default class AddTab extends Component {
static navigationOptions = {
headerShown: false
}
constructor(props) {
super(props)
}
state = {
currentState:0,
faqTitle:"",
faqAnswer:"",
title:"",
content:"",
user:{},
inquiry:[],
isModalVisible:false,
}
setIsModalVisigle= (e) => {
this.setState({
isModalVisible:e
})
}
componentDidMount() {
if(this.props.navigation.state.params &&this.props.navigation.state.params.currentState ) {
this.setState({
currentState:this.props.navigation.state.params.currentState
})
}
AsyncStorage.getItem('user',(err,res) => {
if(res) {
this.setState({
user:JSON.parse(res)
})
get(`http://${SERVER}/inquirys/readAll/${JSON.parse(res).id}`,{title:this.state.title,content:this.state.content}).then(e => {
if(e.data.success) {
this.setState({
inquiry:e.data.data
})
}
})
}
})
}
onSubmitFAQ = () => {
post(`http://${SERVER}/faqs`,{faqTitle:this.state.faqTitle,faqAnswer:this.state.faqAnswer}).then(e => {
if(e.data.success) {
alert("문의가 성공적으로 등록되었습니다.")
}
})
}
onSubmitInquiry = () => {
if(!this.state.user) return alert("로그인 후 이용해주세요.")
if(!this.state.title) return alert("제목을 입력해주세요.")
if(!this.state.content) return alert("내용을 입력해주세요.")
post(`http://${SERVER}/inquirys/${this.state.user.id}`,{title:this.state.title,content:this.state.content}).then(e => {
if(e.data.success) {
this.setState({
content:"",
title:""
})
this.setState(prev => ({
inquiry: [
...prev.inquiry,
e.data.data
]
}))
alert("문의가 성공적으로 등록되었습니다.")
}
})
}
render() {
return (
<View style={{height:"100%"}}>
<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>
<View style={{
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 6,
},
shadowOpacity: 0.39,
shadowRadius: 8.30,
elevation: 13,
flexDirection:"row",justifyContent:"space-between",paddingLeft:24,paddingRight:24,paddingTop:8,paddingBottom:12,width:"100%",backgroundColor:"white"}}>
<TouchableOpacity onPress={() => this.setState({currentState:0})}>
<Text style={[{fontSize:15},this.state.currentState==0?{"color":"#615F5F"}:{color:"#BDBCBC"}]}>
이용약관
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.setState({currentState:1})}>
<Text style={[{fontSize:15},this.state.currentState==1?{"color":"#615F5F"}:{color:"#BDBCBC"}]}>
Q & A
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.setState({currentState:2})}>
<Text style={[{fontSize:15},this.state.currentState==2?{"color":"#615F5F"}:{color:"#BDBCBC"}]}>
1:1문의
</Text>
</TouchableOpacity>
</View>
<ScrollView style={{width:"100%",backgroundColor:"white"}}>
{this.state.currentState===2?
<View style={{padding:16}}>
<View style={{height:180}}>
<Text style={{color:"#615F5F",fontWeight:"bold",fontSize:13}}>
이전글
</Text>
{this.state.inquiry.map((e,i) =>
<TouchableOpacity onPress={() => {this.setIsModalVisigle(true)}} style={{paddingTop:8,flexDirection:"row"}}>
<Text style={{color:"#615F5F",fontSize:13,marginRight:16}}>
{moment(e.updatedAt).format("YY/MM/DD")}
</Text>
<Text style={{color:"#615F5F",fontSize:13}}>
{e.title}
</Text>
<Text style={{color:"black",fontWeight:"bold",marginLeft:"auto",fontSize:13}}>
{e.isAnswer?"[답변완료]":"[확인중]"}
</Text>
<Modal isVisible={this.state.isModalVisible} onBackButtonPress={() => this.setIsModalVisigle(false)} onBackdropPress={() => this.setIsModalVisigle(false)}>
<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"}}>
{`${e.title}`}
</Text>
<Text style={{fontSize:12,marginTop:16,fontWeight:"300",marginLeft:"auto",textAlign:"right"}}>
{`${moment(e.updatedAt).format("YYYY.M.DD")}`}
</Text>
</View>
<View>
<Text style={{marginTop:5}}>
{`${e.content}`}
</Text>
</View>
<View style={{paddingTop:20,marginTop:20,borderTopWidth:1,borderTopColor:"#615F5F"}}>
<Text style={{fontSize:16,fontWeight:"bold"}}>
답변
</Text>
<Text style={{marginTop:5}}>
확인중입니다.
</Text>
</View>
</View>
</Modal>
</TouchableOpacity>
)}
</View>
<View>
<TextInput value={this.state.title} onChangeText={e => this.setState({title:e})} placeholder="제목을 입력하세요." style={{marginBottom:16,paddingTop:6,paddingBottom:9,paddingLeft:16,borderColor:"#FFD63A",borderWidth:1}}/>
<TextInput value={this.state.content} onChangeText={e => this.setState({content:e})} placeholder="내용을 입력하세요." style={{textAlignVertical:"top",paddingTop:6,paddingBottom:9,paddingLeft:16,borderColor:"#FFD63A",borderWidth:1,height:Dimensions.get("screen").height*0.3}}/>
</View>
</View>
:undefined}
</ScrollView>
{this.state.currentState==2?
<View style={{flexDirection:"row",width:"100%",position:"absolute",backgroundColor:"white",bottom:0}}>
<TouchableOpacity onPress={() => this.onSubmitInquiry()} style={{backgroundColor:"#FFD63A",width:"50%",paddingTop:21,paddingBottom:19}}>
<Text style={{textAlign:"center",fontWeight:"bold",fontSize:15}}>
등록
</Text>
</TouchableOpacity><TouchableOpacity onPress={() => this.setState({title:"",content:""})} style={{backgroundColor:"white",width:"50%",paddingTop:21,paddingBottom:19}}>
<Text style={{textAlign:"center",fontWeight:"bold",fontSize:15}}>
취소
</Text>
</TouchableOpacity>
</View>:<View style={{
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 6,
},
shadowOpacity: 0.39,
shadowRadius: 8.30,
elevation: 13,
flexDirection:"row",justifyContent:"space-between",paddingLeft:24,paddingRight:24,paddingTop:19,paddingBottom:19,width:"100%",position:"absolute",backgroundColor:"white",bottom:0}}>
<Home onPress={() => this.props.navigation.navigate("Main_")}/>
<Chat onPress={() => this.props.navigation.navigate("ChatTab")}/>
<QR onPress={() => this.props.navigation.navigate("QRTab")}/>
<Heart onPress={() => this.props.navigation.navigate("LikeTab")}/>
<Alarm onPress={() => this.props.navigation.navigate("AlarmTab")}/>
</View> }
</View>
);
}
}
const style = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});