|
| 1 | +import React, { useState } from 'react'; |
1 | 2 | import { Ionicons } from '@expo/vector-icons';
|
2 | 3 | import { useNavigation } from 'expo-router';
|
3 |
| -import { useState } from 'react'; |
4 | 4 | import {
|
5 |
| - Pressable, |
6 |
| - ScrollView, |
7 |
| - StyleSheet, |
8 |
| - Text, |
9 |
| - TextInput, |
10 |
| - View, |
| 5 | + Pressable, |
| 6 | + ScrollView, |
| 7 | + StyleSheet, |
| 8 | + Text, |
| 9 | + TextInput, |
| 10 | + View, |
11 | 11 | } from 'react-native';
|
| 12 | +import DateTimePicker from '@react-native-community/datetimepicker'; |
12 | 13 |
|
13 | 14 | const AddGiftScreen = () => {
|
14 |
| - const navigation = useNavigation(); |
15 |
| - const [title, setTitle] = useState(''); |
16 |
| - const [description, setDescription] = useState(''); |
17 |
| - const [recipient, setRecipient] = useState(''); |
18 |
| - const [selectedDate, setSelectedDate] = useState(new Date()); |
| 15 | + const navigation = useNavigation(); |
| 16 | + const [title, setTitle] = useState(''); |
| 17 | + const [description, setDescription] = useState(''); |
| 18 | + const [price, setPrice] = useState(0); |
| 19 | + const [recipient, setRecipient] = useState(''); |
| 20 | + const [selectedDate, setSelectedDate] = useState(new Date()); |
| 21 | + const [showPicker, setShowPicker] = useState(false); |
19 | 22 |
|
20 |
| - const handleAddGift = () => { |
21 |
| - console.log({ title, description, recipient, selectedDate }); |
22 |
| - navigation.goBack(); |
23 |
| - }; |
| 23 | + const handleAddGift = () => { |
| 24 | + console.log({ title, description, recipient, selectedDate }); |
| 25 | + navigation.goBack(); |
| 26 | + }; |
24 | 27 |
|
25 |
| - return ( |
26 |
| - <View style={styles.container}> |
27 |
| - <ScrollView style={styles.scrollView}> |
28 |
| - <View style={styles.inputGroup}> |
29 |
| - <Text style={styles.label}>Title</Text> |
30 |
| - <TextInput |
31 |
| - style={styles.input} |
32 |
| - placeholder="Enter title" |
33 |
| - value={title} |
34 |
| - onChangeText={setTitle} |
35 |
| - /> |
36 |
| - </View> |
| 28 | + const onChangeDate = (event: any, selectedDate: any) => { |
| 29 | + setShowPicker(false); |
| 30 | + if (selectedDate) { |
| 31 | + setSelectedDate(selectedDate); |
| 32 | + } |
| 33 | + }; |
37 | 34 |
|
38 |
| - <View style={styles.inputGroup}> |
39 |
| - <Text style={styles.label}>Description</Text> |
40 |
| - <TextInput |
41 |
| - style={[styles.input, styles.textArea]} |
42 |
| - placeholder="Enter description" |
43 |
| - value={description} |
44 |
| - onChangeText={setDescription} |
45 |
| - multiline |
46 |
| - numberOfLines={4} |
47 |
| - /> |
48 |
| - </View> |
| 35 | + return ( |
| 36 | + <View style={styles.container}> |
| 37 | + <ScrollView style={styles.scrollView}> |
| 38 | + <View style={styles.inputGroup}> |
| 39 | + <Text style={styles.label}>Title</Text> |
| 40 | + <TextInput |
| 41 | + style={styles.input} |
| 42 | + placeholder="Enter title" |
| 43 | + value={title} |
| 44 | + onChangeText={setTitle} |
| 45 | + /> |
| 46 | + </View> |
49 | 47 |
|
50 |
| - <View style={styles.inputGroup}> |
51 |
| - <Text style={styles.label}>Image</Text> |
52 |
| - <Pressable style={styles.uploadButton}> |
53 |
| - <Ionicons name="cloud-upload-outline" size={24} color="#666" /> |
54 |
| - <Text style={styles.uploadText}>Upload Image</Text> |
55 |
| - </Pressable> |
56 |
| - </View> |
| 48 | + <View style={styles.inputGroup}> |
| 49 | + <Text style={styles.label}>Description</Text> |
| 50 | + <TextInput |
| 51 | + style={[styles.input, styles.textArea]} |
| 52 | + placeholder="Enter description" |
| 53 | + value={description} |
| 54 | + onChangeText={setDescription} |
| 55 | + multiline |
| 56 | + numberOfLines={4} |
| 57 | + /> |
| 58 | + </View> |
57 | 59 |
|
58 |
| - <View style={styles.inputGroup}> |
59 |
| - <Text style={styles.label}>Choose Recipient</Text> |
60 |
| - <Pressable style={styles.select}> |
61 |
| - <Text style={styles.selectText}>Choose Recipient</Text> |
62 |
| - <Ionicons name="chevron-down" size={24} color="#666" /> |
63 |
| - </Pressable> |
64 |
| - </View> |
| 60 | + <View style={styles.inputGroup}> |
| 61 | + <Text style={styles.label}>Price</Text> |
| 62 | + <TextInput |
| 63 | + style={styles.input} |
| 64 | + placeholder="Enter price" |
| 65 | + value={String(price)} |
| 66 | + onChangeText={(text) => setPrice(Number(text))} |
| 67 | + keyboardType="numeric" |
| 68 | + /> |
| 69 | + </View> |
65 | 70 |
|
66 |
| - <View style={styles.inputGroup}> |
67 |
| - <Text style={styles.label}>Choose Time Event</Text> |
68 |
| - <Pressable style={styles.select}> |
69 |
| - <Text style={styles.selectText}>Choose time</Text> |
70 |
| - <Ionicons name="chevron-down" size={24} color="#666" /> |
71 |
| - </Pressable> |
72 |
| - </View> |
| 71 | + <View style={styles.inputGroup}> |
| 72 | + <Text style={styles.label}>Image</Text> |
| 73 | + <Pressable style={styles.uploadButton}> |
| 74 | + <Ionicons name="cloud-upload-outline" size={24} color="#666" /> |
| 75 | + <Text style={styles.uploadText}>Choose Image</Text> |
| 76 | + </Pressable> |
| 77 | + </View> |
73 | 78 |
|
74 |
| - <Pressable style={styles.addButton} onPress={handleAddGift}> |
75 |
| - <Text style={styles.addButtonText}>Add Gift Idea</Text> |
76 |
| - </Pressable> |
| 79 | + <View style={styles.inputGroup}> |
| 80 | + <Text style={styles.label}>Choose Recipient</Text> |
| 81 | + <Pressable style={styles.select}> |
| 82 | + <Text style={styles.selectText}>Choose Recipient</Text> |
| 83 | + <Ionicons name="chevron-down" size={24} color="#666" /> |
| 84 | + </Pressable> |
| 85 | + </View> |
77 | 86 |
|
78 |
| - <Pressable |
79 |
| - style={styles.cancelButton} |
80 |
| - onPress={() => navigation.goBack()} |
81 |
| - > |
82 |
| - <Text style={styles.cancelButtonText}>Cancel</Text> |
83 |
| - </Pressable> |
84 |
| - </ScrollView> |
85 |
| - </View> |
86 |
| - ); |
| 87 | + <View style={styles.inputGroup}> |
| 88 | + <Text style={styles.label}>Choose Time Event</Text> |
| 89 | + <Pressable |
| 90 | + style={styles.select} |
| 91 | + onPress={() => setShowPicker(true)} |
| 92 | + > |
| 93 | + <Text style={styles.selectText}> |
| 94 | + {selectedDate.toLocaleString()} |
| 95 | + </Text> |
| 96 | + <Ionicons name="chevron-down" size={24} color="#666" /> |
| 97 | + </Pressable> |
| 98 | + |
| 99 | + {showPicker && ( |
| 100 | + <DateTimePicker |
| 101 | + value={selectedDate} |
| 102 | + mode="datetime" |
| 103 | + display="default" |
| 104 | + onChange={onChangeDate} |
| 105 | + /> |
| 106 | + )} |
| 107 | + </View> |
| 108 | + |
| 109 | + <Pressable style={styles.addButton} onPress={handleAddGift}> |
| 110 | + <Text style={styles.addButtonText}>Add Gift Idea</Text> |
| 111 | + </Pressable> |
| 112 | + |
| 113 | + <Pressable |
| 114 | + style={styles.cancelButton} |
| 115 | + onPress={() => navigation.goBack()} |
| 116 | + > |
| 117 | + <Text style={styles.cancelButtonText}>Cancel</Text> |
| 118 | + </Pressable> |
| 119 | + </ScrollView> |
| 120 | + </View> |
| 121 | + ); |
87 | 122 | };
|
88 | 123 |
|
89 | 124 | const styles = StyleSheet.create({
|
90 |
| - container: { |
91 |
| - flex: 1, |
92 |
| - backgroundColor: '#F8F9FA', |
93 |
| - paddingVertical: 16, |
94 |
| - }, |
95 |
| - scrollView: { |
96 |
| - flex: 1, |
97 |
| - padding: 16, |
98 |
| - }, |
99 |
| - header: { |
100 |
| - fontSize: 24, |
101 |
| - fontWeight: '600', |
102 |
| - marginBottom: 24, |
103 |
| - color: '#333333', |
104 |
| - }, |
105 |
| - inputGroup: { |
106 |
| - marginBottom: 20, |
107 |
| - }, |
108 |
| - label: { |
109 |
| - fontSize: 16, |
110 |
| - color: '#666666', |
111 |
| - marginBottom: 8, |
112 |
| - }, |
113 |
| - input: { |
114 |
| - backgroundColor: 'white', |
115 |
| - borderRadius: 8, |
116 |
| - padding: 12, |
117 |
| - fontSize: 16, |
118 |
| - borderWidth: 1, |
119 |
| - borderColor: '#DDDDDD', |
120 |
| - }, |
121 |
| - textArea: { |
122 |
| - height: 100, |
123 |
| - textAlignVertical: 'top', |
124 |
| - }, |
125 |
| - uploadButton: { |
126 |
| - backgroundColor: 'white', |
127 |
| - borderRadius: 8, |
128 |
| - padding: 12, |
129 |
| - flexDirection: 'row', |
130 |
| - alignItems: 'center', |
131 |
| - justifyContent: 'center', |
132 |
| - borderWidth: 1, |
133 |
| - borderColor: '#DDDDDD', |
134 |
| - }, |
135 |
| - uploadText: { |
136 |
| - marginLeft: 8, |
137 |
| - fontSize: 16, |
138 |
| - color: '#666666', |
139 |
| - }, |
140 |
| - select: { |
141 |
| - backgroundColor: 'white', |
142 |
| - borderRadius: 8, |
143 |
| - padding: 12, |
144 |
| - flexDirection: 'row', |
145 |
| - alignItems: 'center', |
146 |
| - justifyContent: 'space-between', |
147 |
| - borderWidth: 1, |
148 |
| - borderColor: '#DDDDDD', |
149 |
| - }, |
150 |
| - selectText: { |
151 |
| - fontSize: 16, |
152 |
| - color: '#666666', |
153 |
| - }, |
154 |
| - addButton: { |
155 |
| - backgroundColor: '#4B6BFB', |
156 |
| - borderRadius: 8, |
157 |
| - padding: 16, |
158 |
| - alignItems: 'center', |
159 |
| - marginTop: 24, |
160 |
| - }, |
161 |
| - addButtonText: { |
162 |
| - color: 'white', |
163 |
| - fontSize: 16, |
164 |
| - fontWeight: '600', |
165 |
| - }, |
166 |
| - cancelButton: { |
167 |
| - backgroundColor: '#F8F9FA', |
168 |
| - borderRadius: 8, |
169 |
| - padding: 16, |
170 |
| - alignItems: 'center', |
171 |
| - marginTop: 12, |
172 |
| - }, |
173 |
| - cancelButtonText: { |
174 |
| - color: '#666666', |
175 |
| - fontSize: 16, |
176 |
| - }, |
| 125 | + container: { |
| 126 | + flex: 1, |
| 127 | + backgroundColor: '#F8F9FA', |
| 128 | + paddingVertical: 16, |
| 129 | + }, |
| 130 | + scrollView: { |
| 131 | + flex: 1, |
| 132 | + padding: 16, |
| 133 | + }, |
| 134 | + inputGroup: { |
| 135 | + marginBottom: 20, |
| 136 | + }, |
| 137 | + label: { |
| 138 | + fontSize: 16, |
| 139 | + color: '#666666', |
| 140 | + marginBottom: 8, |
| 141 | + }, |
| 142 | + input: { |
| 143 | + backgroundColor: 'white', |
| 144 | + borderRadius: 8, |
| 145 | + padding: 12, |
| 146 | + fontSize: 16, |
| 147 | + borderWidth: 1, |
| 148 | + borderColor: '#DDDDDD', |
| 149 | + }, |
| 150 | + textArea: { |
| 151 | + height: 100, |
| 152 | + textAlignVertical: 'top', |
| 153 | + }, |
| 154 | + uploadButton: { |
| 155 | + backgroundColor: 'white', |
| 156 | + borderRadius: 8, |
| 157 | + padding: 12, |
| 158 | + flexDirection: 'row', |
| 159 | + alignItems: 'center', |
| 160 | + justifyContent: 'center', |
| 161 | + borderWidth: 1, |
| 162 | + borderColor: '#DDDDDD', |
| 163 | + }, |
| 164 | + uploadText: { |
| 165 | + marginLeft: 8, |
| 166 | + fontSize: 16, |
| 167 | + color: '#666666', |
| 168 | + }, |
| 169 | + select: { |
| 170 | + backgroundColor: 'white', |
| 171 | + borderRadius: 8, |
| 172 | + padding: 12, |
| 173 | + flexDirection: 'row', |
| 174 | + alignItems: 'center', |
| 175 | + justifyContent: 'space-between', |
| 176 | + borderWidth: 1, |
| 177 | + borderColor: '#DDDDDD', |
| 178 | + }, |
| 179 | + selectText: { |
| 180 | + fontSize: 16, |
| 181 | + color: '#666666', |
| 182 | + }, |
| 183 | + addButton: { |
| 184 | + backgroundColor: '#4B6BFB', |
| 185 | + borderRadius: 8, |
| 186 | + padding: 16, |
| 187 | + alignItems: 'center', |
| 188 | + marginTop: 24, |
| 189 | + }, |
| 190 | + addButtonText: { |
| 191 | + color: 'white', |
| 192 | + fontSize: 16, |
| 193 | + fontWeight: '600', |
| 194 | + }, |
| 195 | + cancelButton: { |
| 196 | + backgroundColor: '#F8F9FA', |
| 197 | + borderRadius: 8, |
| 198 | + padding: 16, |
| 199 | + alignItems: 'center', |
| 200 | + marginTop: 12, |
| 201 | + }, |
| 202 | + cancelButtonText: { |
| 203 | + color: '#666666', |
| 204 | + fontSize: 16, |
| 205 | + }, |
177 | 206 | });
|
178 | 207 |
|
179 | 208 | export default AddGiftScreen;
|
0 commit comments