-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathowner_inquiry.js
221 lines (195 loc) · 4.93 KB
/
owner_inquiry.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
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
import React, { useState, useEffect } from "react";
import {
View,
Text,
StyleSheet,
TouchableOpacity,
Image,
SafeAreaView,
ScrollView,
Modal,
Button,
TextInput,
} from "react-native";
import Icon from "react-native-vector-icons/FontAwesome";
import {
Ionicons,
Entypo,
FontAwesome5,
FontAwesome6,
} from "@expo/vector-icons";
import { useNavigation } from '@react-navigation/native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import axios from 'axios';
// Header 컴포넌트
const Header = ({ navigation }) => {
return (
<View>
<View style={styles.headerContainer}>
<TouchableOpacity onPress={() => navigation.navigate('admin_main')}>
<Ionicons name="arrow-back" size={24} color="#ff3b30" />
</TouchableOpacity>
<Text style={styles.headerText}>문의 하기</Text>
</View>
<View style={styles.headerDivider} />
</View>
);
};
// InquiryForm 컴포넌트
const InquiryForm = ({ userInfo, onInquiry }) => {
const [title, setTitle] = useState("");
const [content, setContent] = useState("");
const handleSubmit = async () => {
console.log("문의 등록:", title, content);
// inquiry 함수를 호출하여 서버에 문의 내용을 전송
onInquiry(title, content, userInfo);
// 데이터 전송 후 상태 초기화
setTitle("");
setContent("");
};
return (
<View style={styles.inquiryContainer}>
<TextInput
style={styles.input}
value={title}
onChangeText={setTitle}
placeholder="제목"
/>
<TextInput
style={[styles.input, styles.multiline]}
value={content}
onChangeText={setContent}
placeholder="문의 내용"
multiline
numberOfLines={4}
/>
<TouchableOpacity style={styles.button} onPress={handleSubmit}>
<Text style={styles.buttonText}>등록</Text>
</TouchableOpacity>
</View>
);
};
const App = () => {
const navigation = useNavigation();
const [userInfo, setUserInfo] = useState();
const [title, setTitle] = useState("");
const [content, setContent] = useState("");
useEffect(() => {
const fetchStores = async () => {
try {
// userInfo에서 userId 추출
const userInfoString = await AsyncStorage.getItem('userInfo');
const userInfo = userInfoString ? JSON.parse(userInfoString) : null;
console.log("유저",userInfo)
setUserInfo(userInfo);
} catch (error) {
console.error('Error fetching stores:', error);
}
};
fetchStores();
}, []);
const inquiry = async( ) => {
console.log("호출", title, content)
try{
// 서버에 요청 보내기
const response = await axios.post(`http://61.80.80.153:8090/botbuddies/inquiry`, {
userId: userInfo.user_id,
title: title,
details: content,
});
console.log(response.data)
// 응답 데이터 처리
if (response.data) {
setStores(response.data);
// 서버로부터 받은 데이터를 images 배열 형태로 변환하여 저장
console.log("말",response.data)
}
}catch(error){
console.error(error)
}
};
return (
<SafeAreaView style={styles.safeArea}>
<Header navigation={navigation} />
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
<InquiryForm />
</ScrollView>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
safeArea: {
flex: 1,
backgroundColor: "#fff", // SafeAreaView 색상을 배경색과 일치시키기
},
headerContainer: {
flexDirection: "row",
alignItems: "center",
padding: 10,
},
headerText: {
fontSize: 18,
fontWeight: "bold",
marginLeft: 129,
},
tabBar: {
height: 60,
flexDirection: "row",
borderTopColor: "#ccc",
borderTopWidth: 1,
},
tabItem: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
icon: {
width: 250,
height: 250,
resizeMode: "contain",
alignItems: "center",
justifyContent: "center",
flex: 1,
},
inquiryContainer: {
padding: 20,
backgroundColor: "#fff",
},
inquiryTitle: {
fontSize: 18,
fontWeight: "bold",
marginBottom: 10,
},
input: {
borderRadius: 10,
borderColor: "gray",
borderWidth: 1,
padding: 10,
marginBottom: 10,
},
multiline: {
height: 100,
textAlignVertical: "top",
},
button: {
backgroundColor: "red", // 버튼 배경색
padding: 15,
borderRadius: 5,
margin: 10,
justifyContent: "center",
alignSelf: "center",
width : 100,
height : 45,
},
buttonText : {
color : 'white',
alignSelf : 'center',
fontWeight : 'bold',
},
headerDivider: {
height: 1, // 구분선의 두께
backgroundColor: "#e0e0e0", // 구분선 색상
marginVertical: 10, // 위 아래 마진
},
});
export default App;