diff --git a/src/redux/actions/comment.js b/src/redux/actions/comment.js
index d1b2c30..a2a1323 100644
--- a/src/redux/actions/comment.js
+++ b/src/redux/actions/comment.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 = {}) =>
diff --git a/src/redux/reducers/comment.js b/src/redux/reducers/comment.js
index aefaaed..88db226 100644
--- a/src/redux/reducers/comment.js
+++ b/src/redux/reducers/comment.js
@@ -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 };
diff --git a/src/screens/Product/components/Book.js b/src/screens/Product/components/Book.js
index b5d9121..3dc1f03 100644
--- a/src/screens/Product/components/Book.js
+++ b/src/screens/Product/components/Book.js
@@ -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(
- (product) => product?.productId === book?.product[1]?.id
- )[0];
+ const physicalAvailabileInCart = React.useMemo(() => {
+ return userProducts?.filter(
+ (product) => product?.productId === book?.product[1]?.id
+ )[0];
+ }, [userProducts, book]);
- const digitalAvailabileInCart = userProducts?.filter(
- (product) => product?.productId === book?.product[0]?.id
- )[0];
-
- console.log(book);
+ const digitalAvailabileInCart = React.useMemo(() => {
+ return userProducts?.filter(
+ (product) => product?.productId === book?.product[0]?.id
+ )[0];
+ }, [userProducts, book]);
return (
@@ -222,11 +223,19 @@ function Book({
},
]}
onPress={() =>
- pushToCart({
- productId: book?.product[1]?.id,
- userId: userId,
- count: 1,
- })
+ 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) + " " + "تومان"}
- {physicalAvailabileInCart && (
-
-
- 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,
- },
- ]}
- >
-
- +
-
-
- {userProductsLoading ? (
-
- ) : (
-
- {physicalAvailabileInCart?.count}
-
- )}
-
-
- 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,
- },
- ]}
- >
-
- -
-
-
-
- )}
>
@@ -362,11 +280,19 @@ function Book({
},
]}
onPress={() =>
- pushToCart({
- productId: book?.product[0]?.id,
- userId: userId,
- count: 1,
- })
+ 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) + " " + "تومان"}
- {digitalAvailabileInCart && (
-
-
- 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,
- },
- ]}
- >
-
- +
-
-
- {userProductsLoading ? (
-
- ) : (
-
- {digitalAvailabileInCart?.count}
-
- )}
-
-
- 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,
- },
- ]}
- >
-
- -
-
-
-
- )}
>
@@ -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({
-
+
>
)}
diff --git a/src/screens/Product/components/Comments.js b/src/screens/Product/components/Comments.js
index 2ce8e0e..1f7eb15 100644
--- a/src/screens/Product/components/Comments.js
+++ b/src/screens/Product/components/Comments.js
@@ -1,21 +1,60 @@
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 (
- }
- keyExtractor={(item) => item.id}
- />
+
+ }
+ keyExtractor={(item) => item.id}
+ />
+
+
);
}
@@ -73,7 +112,12 @@ const Comment = ({ comment }) => {
@@ -82,3 +126,100 @@ const Comment = ({ comment }) => {
);
};
+
+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 (
+
+
+ setTitle(text)}
+ />
+ setText(text)}
+ />
+
+
+ isBuyed
+ ? addComment(commentForm)
+ : asyncAwesomeAlert(
+ "خطا",
+ "شما این محصول رو خریداری نکرده اید.",
+ {
+ showCancelButton: false,
+ }
+ )
+ }
+ />
+
+
+ );
+};
+
+const mapStateToProps = (state) => ({
+ orderFullList: state.userFactor.fullList,
+});
+
+const mapDispatchToProps = {
+ addComment: comment.add,
+ getFullList: userFactor.fullList,
+};
+
+export default connect(mapStateToProps, mapDispatchToProps)(Commnets);
diff --git a/src/screens/Product/index.js b/src/screens/Product/index.js
index 4218204..8978ca5 100644
--- a/src/screens/Product/index.js
+++ b/src/screens/Product/index.js
@@ -25,7 +25,6 @@ function Product({ route, book, getBook, grades }) {
}}
>
) : (
-
+
)}