Skip to content

Commit 451bf03

Browse files
committed
receipt file type issue fixed
1 parent 34eeb6d commit 451bf03

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

src/components/AddTransactionModal.js

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef, useState } from 'react';
1+
import React, { useEffect, useRef, useState } from "react";
22
import {
33
View,
44
Text,
@@ -7,10 +7,10 @@ import {
77
// Button,
88
Alert,
99
TouchableOpacity,
10-
} from 'react-native';
11-
import { Icon, Button } from 'react-native-elements';
12-
import tw from 'tailwind-react-native-classnames';
13-
import * as ImagePicker from 'expo-image-picker';
10+
} from "react-native";
11+
import { Icon, Button } from "react-native-elements";
12+
import tw from "tailwind-react-native-classnames";
13+
import * as ImagePicker from "expo-image-picker";
1414

1515
const AddTransactionModal = ({
1616
visible,
@@ -29,7 +29,8 @@ const AddTransactionModal = ({
2929
ref2 = useRef(null),
3030
// [desc, setDesc] = useState(""),
3131
// [amt, setAmt] = useState(null),
32-
[image, setImage] = useState('');
32+
[fileType, setFileType] = useState(""),
33+
[image, setImage] = useState("");
3334

3435
useEffect(() => {
3536
setLoading(true);
@@ -38,38 +39,44 @@ const AddTransactionModal = ({
3839

3940
const submitHandler = (isGiving) => {
4041
if (!amt || !desc) {
41-
return Alert.alert('All the fields are required');
42+
return Alert.alert("All the fields are required");
4243
}
43-
if(isNaN(amt)) return Alert.alert('Amount should be a number');
44+
if (isNaN(amt)) return Alert.alert("Amount should be a number");
4445
if (amt < 1) {
45-
return Alert.alert('Amount must be grater than 0');
46+
return Alert.alert("Amount must be grater than 0");
4647
}
47-
fun(isGiving, Number(amt), desc, image);
48+
fun(isGiving, Number(amt), desc, image, fileType);
4849
};
4950

5051
const pickImage = async () => {
5152
const permission = await ImagePicker.requestMediaLibraryPermissionsAsync();
5253

5354
if (!permission.granted) {
54-
return Alert.alert('Permission to access camera roll is required');
55+
return Alert.alert("Permission to access camera roll is required");
5556
}
5657
const res = await ImagePicker.launchImageLibraryAsync({
5758
base64: true,
5859
quality: 0.5,
5960
allowsEditing: true,
6061
mediaTypes: ImagePicker.MediaTypeOptions.Images,
6162
});
62-
setImage('data:image/jpg;base64,' + res?.base64 || null);
63+
if (res.cancelled) {
64+
setFileType("");
65+
setImage("");
66+
}else{
67+
setFileType(res?.uri?.split(".")[res?.uri?.split(".").length - 1]);
68+
setImage("data:image/jpg;base64," + res?.base64 || null);
69+
}
6370
};
6471

6572
return (
6673
<Modal
67-
animationType='fade'
74+
animationType="fade"
6875
transparent={true}
6976
visible={visible}
7077
onRequestClose={() => {
7178
setAmt(null);
72-
setDesc('');
79+
setDesc("");
7380
setSettling(0);
7481
setVisible(false);
7582
}}
@@ -78,13 +85,13 @@ const AddTransactionModal = ({
7885
activeOpacity={1}
7986
onPress={() => {
8087
setAmt(null);
81-
setDesc('');
88+
setDesc("");
8289
setSettling(0);
8390
setVisible(false);
8491
}}
8592
style={[
8693
tw`h-full w-full absolute justify-center items-center`,
87-
{ backgroundColor: 'rgba(0,0,0,0.6)' },
94+
{ backgroundColor: "rgba(0,0,0,0.6)" },
8895
]}
8996
>
9097
<TouchableOpacity
@@ -96,13 +103,13 @@ const AddTransactionModal = ({
96103
style={tw`absolute right-4 top-4 z-10`}
97104
onPress={() => {
98105
setAmt(null);
99-
setDesc('');
106+
setDesc("");
100107
setSettling(0);
101108
setVisible(false);
102109
}}
103110
>
104111
<Text style={tw`text-black`}>
105-
<Icon type='feather' name='x' />
112+
<Icon type="feather" name="x" />
106113
</Text>
107114
</TouchableOpacity>
108115
<Text
@@ -113,10 +120,10 @@ const AddTransactionModal = ({
113120
<TextInput
114121
style={tw`border border-gray-400 rounded p-2 m-2 mx-4`}
115122
ref={ref1}
116-
placeholder='Amount'
117-
keyboardType='numeric'
118-
returnKeyType='next'
119-
value={amt?.toString() || ''}
123+
placeholder="Amount"
124+
keyboardType="numeric"
125+
returnKeyType="next"
126+
value={amt?.toString() || ""}
120127
onChangeText={(text) => setAmt(text)}
121128
onSubmitEditing={() => {
122129
ref2.current.focus();
@@ -126,14 +133,14 @@ const AddTransactionModal = ({
126133
<TextInput
127134
style={tw`border border-gray-400 rounded p-2 m-2 mx-4`}
128135
ref={ref2}
129-
placeholder='Description'
136+
placeholder="Description"
130137
value={desc}
131138
onChangeText={(text) => setDesc(text)}
132139
/>
133140
<View style={tw`mx-4 my-2`}>
134141
<Button
135142
onPress={pickImage}
136-
title='Add Receipt'
143+
title="Add Receipt"
137144
containerStyle={tw`rounded-full`}
138145
/>
139146
</View>
@@ -143,10 +150,10 @@ const AddTransactionModal = ({
143150
<Button
144151
loading={loading}
145152
onPress={() => submitHandler(settling === 2)}
146-
title='Settle Up'
153+
title="Settle Up"
147154
titleStyle={tw`text-green-700`}
148155
containerStyle={tw`border border-gray-400 rounded-full`}
149-
type='clear'
156+
type="clear"
150157
/>
151158
</View>
152159
) : (
@@ -155,20 +162,20 @@ const AddTransactionModal = ({
155162
<Button
156163
loading={loading}
157164
onPress={() => submitHandler(true)}
158-
title='You Gave'
165+
title="You Gave"
159166
titleStyle={tw`text-red-700`}
160167
containerStyle={tw`border border-gray-400 rounded-full`}
161-
type='clear'
168+
type="clear"
162169
/>
163170
</View>
164171
<View style={tw`p-2 w-1/2`}>
165172
<Button
166173
loading={loading}
167174
onPress={() => submitHandler(false)}
168-
title='You Got'
175+
title="You Got"
169176
titleStyle={tw`text-green-700`}
170177
containerStyle={tw`border border-gray-400 rounded-full`}
171-
type='clear'
178+
type="clear"
172179
/>
173180
</View>
174181
</>

src/screens/CustomerScreen.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const CustomerScreen = ({ route }) => {
104104
setGot(tGot);
105105
}, [trans]);
106106

107-
const addTransaction = (isGiving, amount, desc, url = "") => {
107+
const addTransaction = (isGiving, amount, desc, url = "", fileType = "") => {
108108
setLoading(true);
109109
fetch(`${API_BASE_URL}/api/addTransaction`, {
110110
method: "POST",
@@ -114,6 +114,7 @@ const CustomerScreen = ({ route }) => {
114114
amount,
115115
desc,
116116
url,
117+
fileType,
117118
isGiving,
118119
}),
119120
crossDomain: true,

0 commit comments

Comments
 (0)