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. 219
      src/screens/Product/components/Book.js
  4. 149
      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) =>
async (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:
(data = {}, data2 = {}) =>

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

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

@ -1,12 +1,45 @@
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 fontSize from '../../../constants/fontSize';
import fontSize from "../../../constants/fontSize";
import Colors from "../../../constants/Colors";
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 (
<View style={[tw("flex")]}>
<FlatList
showsHorizontalScrollIndicator={false}
horizontal={true}
@ -16,6 +49,12 @@ export default function Commnets({ comments }) {
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>
<Text
style={[
{ fontSize: fontSize.sm, lineHeight: 20, color: "#132F52", fontFamily: "light",},
{
fontSize: fontSize.sm,
lineHeight: 20,
color: "#132F52",
fontFamily: "light",
},
tw("mt-2"),
]}
>
@ -82,3 +126,100 @@ const Comment = ({ comment }) => {
</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
// setBoxPosition={setBoxPosition}
headerOptions={{
logo: false,
menu: false,

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

Loading…
Cancel
Save