Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 0dd1301

Browse files
committed
feat: implement AddRecipientScreen with image upload, name, description, budget, and spent fields
1 parent 216d86a commit 0dd1301

File tree

1 file changed

+165
-6
lines changed

1 file changed

+165
-6
lines changed
Lines changed: 165 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,170 @@
1-
import { Text, View } from 'react-native';
1+
import React, { useState } from 'react';
2+
import { View, Text, TextInput, TouchableOpacity, StyleSheet, ScrollView, Image } from 'react-native';
3+
import * as ImagePicker from 'expo-image-picker';
4+
import { MaterialIcons } from '@expo/vector-icons';
25

36
const AddRecipientScreen = () => {
4-
return (
5-
<View>
6-
<Text>Add Recipient Screen</Text>
7-
</View>
8-
);
7+
const [image, setImage] = useState<string | null>(null);
8+
const [name, setName] = useState('');
9+
const [description, setDescription] = useState('');
10+
const [budget, setBudget] = useState('');
11+
const [spent, setSpent] = useState('');
12+
13+
const pickImage = async () => {
14+
// Request permission
15+
const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
16+
if (status !== 'granted') {
17+
alert('Sorry, we need camera roll permissions!');
18+
return;
19+
}
20+
21+
const result = await ImagePicker.launchImageLibraryAsync({
22+
mediaTypes: ImagePicker.MediaTypeOptions.Images,
23+
allowsEditing: true,
24+
aspect: [4, 3],
25+
quality: 1,
26+
});
27+
28+
if (!result.canceled) {
29+
setImage(result.assets[0].uri);
30+
}
31+
};
32+
33+
const handleSaveRecipient = () => {
34+
const recipientData = {
35+
image: image || '',
36+
name,
37+
description,
38+
budget: parseFloat(budget),
39+
spent: parseFloat(spent),
40+
};
41+
console.log(recipientData);
42+
// TODO: gửi recipientData lên server hoặc lưu local
43+
};
44+
45+
return (
46+
<ScrollView contentContainerStyle={styles.container}>
47+
{/* Upload Image */}
48+
<View style={styles.inputGroup}>
49+
<Text style={styles.label}>Profile Image</Text>
50+
<TouchableOpacity style={styles.imagePicker} onPress={pickImage}>
51+
{image ? (
52+
<Image source={{ uri: image }} style={styles.previewImage} />
53+
) : (
54+
<Text style={styles.pickImageText}>Pick an Image</Text>
55+
)}
56+
</TouchableOpacity>
57+
</View>
58+
59+
{/* Name */}
60+
<View style={styles.inputGroup}>
61+
<Text style={styles.label}>Name</Text>
62+
<TextInput
63+
style={styles.input}
64+
placeholder="Enter recipient's name"
65+
value={name}
66+
onChangeText={setName}
67+
/>
68+
</View>
69+
70+
{/* Description */}
71+
<View style={styles.inputGroup}>
72+
<Text style={styles.label}>Description (optional)</Text>
73+
<TextInput
74+
style={[styles.input, { height: 100 }]}
75+
placeholder="Enter description"
76+
value={description}
77+
onChangeText={setDescription}
78+
multiline
79+
/>
80+
</View>
81+
82+
{/* Budget */}
83+
<View style={styles.inputGroup}>
84+
<Text style={styles.label}>Budget</Text>
85+
<TextInput
86+
style={styles.input}
87+
placeholder="Enter budget"
88+
value={budget}
89+
onChangeText={setBudget}
90+
keyboardType="numeric"
91+
/>
92+
</View>
93+
94+
{/* Spent */}
95+
<View style={styles.inputGroup}>
96+
<Text style={styles.label}>Spent</Text>
97+
<TextInput
98+
style={styles.input}
99+
placeholder="Enter spent amount"
100+
value={spent}
101+
onChangeText={setSpent}
102+
keyboardType="numeric"
103+
/>
104+
</View>
105+
106+
{/* Save Button */}
107+
<TouchableOpacity style={styles.saveButton} onPress={handleSaveRecipient}>
108+
<Text style={styles.saveButtonText}>Save Recipient</Text>
109+
</TouchableOpacity>
110+
</ScrollView>
111+
);
9112
};
10113

114+
const styles = StyleSheet.create({
115+
container: {
116+
padding: 16,
117+
backgroundColor: '#F5F5F5',
118+
flexGrow: 1,
119+
},
120+
inputGroup: {
121+
marginBottom: 16,
122+
},
123+
label: {
124+
fontSize: 14,
125+
color: '#666',
126+
marginBottom: 8,
127+
},
128+
input: {
129+
borderWidth: 1,
130+
borderColor: '#E0E0E0',
131+
borderRadius: 8,
132+
paddingHorizontal: 12,
133+
paddingVertical: 10,
134+
fontSize: 15,
135+
backgroundColor: 'white',
136+
color: '#333',
137+
},
138+
imagePicker: {
139+
borderWidth: 1,
140+
borderColor: '#E0E0E0',
141+
borderRadius: 8,
142+
height: 180,
143+
alignItems: 'center',
144+
justifyContent: 'center',
145+
backgroundColor: 'white',
146+
},
147+
pickImageText: {
148+
color: '#666',
149+
fontSize: 16,
150+
},
151+
previewImage: {
152+
width: '100%',
153+
height: '100%',
154+
borderRadius: 8,
155+
},
156+
saveButton: {
157+
backgroundColor: '#007AFF',
158+
padding: 16,
159+
borderRadius: 8,
160+
alignItems: 'center',
161+
marginTop: 24,
162+
},
163+
saveButtonText: {
164+
color: 'white',
165+
fontSize: 16,
166+
fontWeight: '600',
167+
},
168+
});
169+
11170
export default AddRecipientScreen;

0 commit comments

Comments
 (0)