some change

master
Reza_ashrafi 3 years ago
parent dd9eb2270e
commit ab08b4cacd
  1. 2
      src/redux/actions/comment.js
  2. 1
      src/redux/reducers/comment.js
  3. 243
      src/screens/Product/components/Book.js
  4. 167
      src/screens/Product/components/Comments.js
  5. 1
      src/screens/Product/index.js
  6. 2
      src/screens/Profile/components/ProfileAddress/index.js

@ -13,7 +13,7 @@ const comment = {
(data = {}, data2) => (data = {}, data2) =>
async (dispatch) => { async (dispatch) => {
await proxy.post("comment/add", data, { dispatch }); await proxy.post("comment/add", data, { dispatch });
if (data2) await proxy.get("book/info", data2, { dispatch }); // if (data2) await proxy.get("book/info", data2, { dispatch });
}, },
del: del:
(data = {}, data2 = {}) => (data = {}, data2 = {}) =>

@ -12,7 +12,6 @@ export default function comment(state = initialState, action) {
case "comment/update": case "comment/update":
return { ...state, loading: false, error: null }; return { ...state, loading: false, error: null };
case "comment/add": case "comment/add":
toast.success("ثبت درخواست با موفقیت انجام شد");
return { ...state, loading: false, error: null }; return { ...state, loading: false, error: null };
case "comment/delete": case "comment/delete":
return { ...state, loading: false, error: null }; return { ...state, loading: false, error: null };

@ -7,12 +7,11 @@ import {
TouchableHighlight, TouchableHighlight,
Dimensions, Dimensions,
Appearance, Appearance,
Pressable,
Platform, Platform,
ActivityIndicator,
} from "react-native"; } from "react-native";
import { useNavigation } from "@react-navigation/native"; import { useNavigation } from "@react-navigation/native";
import { product, userProduct } from "../../../redux/actions"; import { product, userProduct } from "../../../redux/actions";
import { asyncAwesomeAlert } from "../../../utils/AsyncWrappers";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { Entypo } from "@expo/vector-icons"; import { Entypo } from "@expo/vector-icons";
import separate from "../../../utils/separate"; import separate from "../../../utils/separate";
@ -59,15 +58,17 @@ function Book({
}, 500); }, 500);
}, [type]); }, [type]);
const physicalAvailabileInCart = userProducts?.filter( const physicalAvailabileInCart = React.useMemo(() => {
(product) => product?.productId === book?.product[1]?.id return userProducts?.filter(
)[0]; (product) => product?.productId === book?.product[1]?.id
)[0];
}, [userProducts, book]);
const digitalAvailabileInCart = userProducts?.filter( const digitalAvailabileInCart = React.useMemo(() => {
(product) => product?.productId === book?.product[0]?.id return userProducts?.filter(
)[0]; (product) => product?.productId === book?.product[0]?.id
)[0];
console.log(book); }, [userProducts, book]);
return ( return (
<ScrollView style={[tw("flex flex-1 relative")]}> <ScrollView style={[tw("flex flex-1 relative")]}>
@ -222,11 +223,19 @@ function Book({
}, },
]} ]}
onPress={() => onPress={() =>
pushToCart({ physicalAvailabileInCart
productId: book?.product[1]?.id, ? asyncAwesomeAlert(
userId: userId, "نتیجه",
count: 1, "این محصول قبلا به سبد خرید اضافه شده است.",
}) {
showCancelButton: false,
}
)
: pushToCart({
productId: book?.product[1]?.id,
userId: userId,
count: 1,
})
} }
> >
<> <>
@ -247,8 +256,6 @@ function Book({
style={[ style={[
tw("py-1 pr-2"), tw("py-1 pr-2"),
{ {
borderLeftWidth: 1,
borderColor: Colors.theme1[colorScheme].greenCF,
fontFamily: "bold", fontFamily: "bold",
color: Colors.theme1[colorScheme].green79, color: Colors.theme1[colorScheme].green79,
fontSize: fontSize.sm, fontSize: fontSize.sm,
@ -257,95 +264,6 @@ function Book({
> >
{separate(book?.product[1]?.price) + " " + "تومان"} {separate(book?.product[1]?.price) + " " + "تومان"}
</Text> </Text>
{physicalAvailabileInCart && (
<View
style={tw(
`flex items-center pl-3 ${
ios ? "flex-row-reverse" : "flex-row-reverse"
}`
)}
>
<Pressable
onPress={() =>
pushToCart({
productId: physicalAvailabileInCart?.productId,
userId: physicalAvailabileInCart.userId,
count: 1,
})
}
style={[
tw(
`rounded-md py-0 flex flex-row justify-center items-center border ${
mobile ? "px-1.5" : "px-3"
}`
),
{
borderColor: Colors.theme1[colorScheme].green79,
},
]}
>
<Text
style={{
fontSize: mobile ? fontSize.tiny : fontSize.xl4,
color: Colors.theme1[colorScheme].green79,
fontFamily: "bold",
}}
>
+
</Text>
</Pressable>
{userProductsLoading ? (
<ActivityIndicator
style={tw("mx-1.5 my-3")}
size="small"
color={Colors.theme1[colorScheme].greenBA}
/>
) : (
<Text
style={[
tw("mx-1.5"),
{
fontSize: fontSize.xl6,
color: Colors.theme1[colorScheme].green79,
fontFamily: "bold",
},
]}
>
{physicalAvailabileInCart?.count}
</Text>
)}
<Pressable
onPress={() =>
pushToCart({
productId: physicalAvailabileInCart?.productId,
userId: physicalAvailabileInCart?.userId,
count: -1,
})
}
style={[
tw(
`rounded-md flex flex-row justify-center items-center border ${
mobile ? "px-2" : "px-3.5"
}`
),
{
borderColor: Colors.theme1[colorScheme].green79,
},
]}
>
<Text
style={{
fontSize: mobile ? fontSize.tiny : fontSize.xl4,
color: Colors.theme1[colorScheme].green79,
fontFamily: "demi",
}}
>
-
</Text>
</Pressable>
</View>
)}
</View> </View>
</View> </View>
</> </>
@ -362,11 +280,19 @@ function Book({
}, },
]} ]}
onPress={() => onPress={() =>
pushToCart({ digitalAvailabileInCart
productId: book?.product[0]?.id, ? asyncAwesomeAlert(
userId: userId, "خطا",
count: 1, "این محصول قبلا به سبد خرید اضافه شده است.",
}) {
showCancelButton: false,
}
)
: pushToCart({
productId: book?.product[0]?.id,
userId: userId,
count: 1,
})
} }
> >
<> <>
@ -385,7 +311,7 @@ function Book({
style={[ style={[
tw("py-1 pr-2"), tw("py-1 pr-2"),
{ {
borderLeftWidth: 1, borderRightWidth: 1,
borderColor: Colors.theme1[colorScheme].greenCF, borderColor: Colors.theme1[colorScheme].greenCF,
fontFamily: "bold", fontFamily: "bold",
color: Colors.theme1[colorScheme].green79, color: Colors.theme1[colorScheme].green79,
@ -395,95 +321,6 @@ function Book({
> >
{separate(book?.product[0]?.price) + " " + "تومان"} {separate(book?.product[0]?.price) + " " + "تومان"}
</Text> </Text>
{digitalAvailabileInCart && (
<View
style={tw(
`flex items-center pl-3 ${
ios ? "flex-row-reverse" : "flex-row-reverse"
}`
)}
>
<Pressable
onPress={() =>
pushToCart({
productId: digitalAvailabileInCart?.productId,
userId: digitalAvailabileInCart.userId,
count: 1,
})
}
style={[
tw(
`rounded-md py-0 flex flex-row justify-center items-center border ${
mobile ? "px-1.5" : "px-3"
}`
),
{
borderColor: Colors.theme1[colorScheme].green79,
},
]}
>
<Text
style={{
fontSize: mobile ? fontSize.tiny : fontSize.xl4,
color: Colors.theme1[colorScheme].green79,
fontFamily: "bold",
}}
>
+
</Text>
</Pressable>
{userProductsLoading ? (
<ActivityIndicator
style={tw("mx-1.5 my-3")}
size="small"
color={Colors.theme1[colorScheme].greenBA}
/>
) : (
<Text
style={[
tw("mx-1.5"),
{
fontSize: fontSize.xl6,
color: Colors.theme1[colorScheme].green79,
fontFamily: "bold",
},
]}
>
{digitalAvailabileInCart?.count}
</Text>
)}
<Pressable
onPress={() =>
pushToCart({
productId: digitalAvailabileInCart?.productId,
userId: digitalAvailabileInCart?.userId,
count: -1,
})
}
style={[
tw(
`rounded-md flex flex-row justify-center items-center border ${
mobile ? "px-2" : "px-3.5"
}`
),
{
borderColor: Colors.theme1[colorScheme].green79,
},
]}
>
<Text
style={{
fontSize: mobile ? fontSize.tiny : fontSize.xl4,
color: Colors.theme1[colorScheme].green79,
fontFamily: "demi",
}}
>
-
</Text>
</Pressable>
</View>
)}
</View> </View>
</> </>
</TouchableHighlight> </TouchableHighlight>
@ -547,8 +384,6 @@ function Book({
style={[ style={[
tw("py-1 pr-2"), tw("py-1 pr-2"),
{ {
borderLeftWidth: 1,
borderColor: Colors.theme1[colorScheme].greenCF,
fontFamily: "bold", fontFamily: "bold",
color: Colors.theme1[colorScheme].green79, color: Colors.theme1[colorScheme].green79,
fontSize: fontSize.sm, fontSize: fontSize.sm,
@ -630,7 +465,7 @@ function Book({
<Entypo name="chevron-small-left" size={20} color="#196EC0" /> <Entypo name="chevron-small-left" size={20} color="#196EC0" />
</View> </View>
<Rates rate={book?.rate || 4} /> <Rates rate={book?.rate || 4} />
<Comments comments={book?.comments} /> <Comments comments={book?.comments} productId={book?.product[1]?.id} />
</> </>
)} )}
</ScrollView> </ScrollView>

@ -1,21 +1,60 @@
import React from "react"; import React from "react";
import { View, Text, FlatList, Image, Dimensions } from "react-native"; import {
View,
Text,
FlatList,
Image,
Dimensions,
TextInput,
Appearance,
KeyboardAvoidingView,
} from "react-native";
import { comment, userFactor } from "../../../redux/actions";
import { connect } from "react-redux";
import { asyncAwesomeAlert } from "../../../utils/AsyncWrappers";
//components
import Pressable from "../../../components/Pressable";
//assets
import tw from "tailwind-rn"; import tw from "tailwind-rn";
import fontSize from '../../../constants/fontSize'; import fontSize from "../../../constants/fontSize";
import Colors from "../../../constants/Colors";
const width = Dimensions.get("window").width; const width = Dimensions.get("window").width;
const ios = Platform.OS === "ios";
function Commnets({
comments,
addComment,
productId,
getFullList,
orderFullList,
}) {
React.useEffect(() => {
if (!orderFullList.length) {
getFullList();
}
}, []);
export default function Commnets({ comments }) {
return ( return (
<FlatList <View style={[tw("flex")]}>
showsHorizontalScrollIndicator={false} <FlatList
horizontal={true} showsHorizontalScrollIndicator={false}
inverted={true} horizontal={true}
style={{ marginTop: 20, paddingBottom: 10 }} inverted={true}
data={comments} style={{ marginTop: 20, paddingBottom: 10 }}
renderItem={({ item }) => <Comment comment={item} />} data={comments}
keyExtractor={(item) => item.id} renderItem={({ item }) => <Comment comment={item} />}
/> keyExtractor={(item) => item.id}
/>
<AddComment
addComment={addComment}
productId={productId}
isBuyed={null}
/>
</View>
); );
} }
@ -73,7 +112,12 @@ const Comment = ({ comment }) => {
</View> </View>
<Text <Text
style={[ style={[
{ fontSize: fontSize.sm, lineHeight: 20, color: "#132F52", fontFamily: "light",}, {
fontSize: fontSize.sm,
lineHeight: 20,
color: "#132F52",
fontFamily: "light",
},
tw("mt-2"), tw("mt-2"),
]} ]}
> >
@ -82,3 +126,100 @@ const Comment = ({ comment }) => {
</View> </View>
); );
}; };
const AddComment = ({ addComment, productId, isBuyed, ...props }) => {
const [commentForm, setCommentForm] = React.useState({
title: "",
text: "",
fileId: null,
productId: null,
});
const colorScheme = React.useMemo(() => {
return Appearance.getColorScheme();
}, [props.useless]);
return (
<KeyboardAvoidingView
behavior={ios ? "padding" : "height"}
style={[tw("flex items-end")]}
>
<View
style={[
tw("rounded-full"),
{
width: 70,
height: 70,
backgroundColor: Colors.theme1[colorScheme].grayE3,
},
]}
></View>
<TextInput
style={[
tw("w-full mt-4 px-2 rounded-md"),
{
backgroundColor: Colors.theme1[colorScheme].grayF9,
color: Colors.theme1[colorScheme].gray20,
fontSize: fontSize.base,
textAlign: "right",
fontFamily: "light",
borderWidth: 1,
borderColor: Colors.theme1[colorScheme].grayE3,
},
]}
value={comment.title}
placeholder="عنوان نظر ..."
onChangeText={(text) => setTitle(text)}
/>
<TextInput
style={[
tw("w-full mt-4 px-2 rounded-md h-40"),
{
backgroundColor: Colors.theme1[colorScheme].grayF9,
color: Colors.theme1[colorScheme].gray20,
fontSize: fontSize.tiny,
textAlign: "right",
fontFamily: "light",
borderWidth: 1,
borderColor: Colors.theme1[colorScheme].grayE3,
},
]}
value={comment.text}
multiline={true}
placeholder="متن نظر ..."
onChangeText={(text) => setText(text)}
/>
<View style={tw("w-full mt-4")}>
<Pressable
title="ارسال نظر"
backgroundColor={Colors.theme1[colorScheme].greenCF}
color={Colors.theme1[colorScheme].white}
border={{ width: 0, color: null }}
width={"40%"}
onPress={() =>
isBuyed
? addComment(commentForm)
: asyncAwesomeAlert(
"خطا",
"شما این محصول رو خریداری نکرده اید.",
{
showCancelButton: false,
}
)
}
/>
</View>
</KeyboardAvoidingView>
);
};
const mapStateToProps = (state) => ({
orderFullList: state.userFactor.fullList,
});
const mapDispatchToProps = {
addComment: comment.add,
getFullList: userFactor.fullList,
};
export default connect(mapStateToProps, mapDispatchToProps)(Commnets);

@ -25,7 +25,6 @@ function Product({ route, book, getBook, grades }) {
}} }}
> >
<Navbar <Navbar
// setBoxPosition={setBoxPosition}
headerOptions={{ headerOptions={{
logo: false, logo: false,
menu: false, menu: false,

@ -239,7 +239,7 @@ const ProfileAddress = ({
</View> </View>
</ScrollView> </ScrollView>
) : ( ) : (
<Empty text="هیچ آدرسی ثبت نشده :(" /> <Empty text="هیچ آدرسی ثبت نشده" />
)} )}
<View style={tw("w-full px-4")}> <View style={tw("w-full px-4")}>
<TouchableOpacity <TouchableOpacity

Loading…
Cancel
Save