diff --git a/src/redux/actions/index.js b/src/redux/actions/index.js
index 952f800..f95dc9e 100644
--- a/src/redux/actions/index.js
+++ b/src/redux/actions/index.js
@@ -15,4 +15,5 @@ export {default as userFavorite} from "./userFavorite";
export { default as transport } from "./transport";
export { default as activation } from "./activation";
export { default as form } from "./form";
-export { default as comment } from "./comment";
\ No newline at end of file
+export { default as comment } from "./comment";
+export { default as vote } from "./vote";
\ No newline at end of file
diff --git a/src/redux/actions/vote.js b/src/redux/actions/vote.js
new file mode 100644
index 0000000..057c5e4
--- /dev/null
+++ b/src/redux/actions/vote.js
@@ -0,0 +1,11 @@
+import proxy from "../proxy";
+const vote = {
+ add:
+ (data = {}, data2) =>
+ async (dispatch) => {
+ await proxy.post("userVote/add", data, { dispatch });
+ },
+
+};
+
+export default vote;
\ No newline at end of file
diff --git a/src/redux/reducers/index.js b/src/redux/reducers/index.js
index f0238b9..fa70dad 100644
--- a/src/redux/reducers/index.js
+++ b/src/redux/reducers/index.js
@@ -14,4 +14,5 @@ export { default as userFavorite } from "./userFavorite";
export { default as transport } from "./transport";
export { default as activation } from "./activation";
export { default as form } from "./form";
-export { default as comment } from "./comment";
\ No newline at end of file
+export { default as comment } from "./comment";
+export { default as vote } from "./vote";
\ No newline at end of file
diff --git a/src/redux/reducers/vote.js b/src/redux/reducers/vote.js
new file mode 100644
index 0000000..47c6b85
--- /dev/null
+++ b/src/redux/reducers/vote.js
@@ -0,0 +1,24 @@
+import { asyncApiAwesomeAlert } from "../../utils/AsyncWrappers";
+
+const initialState = {
+ loading: false,
+ error: null,
+};
+
+export default function vote(state = initialState, action) {
+ let { type, data } = action;
+ switch (type) {
+ case "userVote/add":
+ asyncAwesomeAlert("نتیجه", "رای شما با موفقیت ثبت شد.", {
+ showCancelButton: false,
+ });
+ return { ...state, loading: false, error: null };
+ case "userVote/loading":
+ return { ...state, loading: true };
+ case "userVote/error":
+ toast.error(data.message);
+ return { ...state, loading: false, error: data.message };
+ default:
+ return state;
+ }
+}
diff --git a/src/redux/store.js b/src/redux/store.js
index 58e0b9c..aca9623 100644
--- a/src/redux/store.js
+++ b/src/redux/store.js
@@ -19,6 +19,7 @@ import transport from "./reducers/transport"
import comment from './reducers/comment';
import form from "./reducers/form";
import userFavorite from "./reducers/userFavorite";
+import vote from "./reducers/vote";
const persistConfig = {
key: "root",
@@ -54,7 +55,8 @@ const store = createStore(
transport,
comment,
form,
- userFavorite
+ userFavorite,
+ vote
})
),
initialState,
diff --git a/src/screens/Product/components/Book.js b/src/screens/Product/components/Book.js
index 3dc1f03..de6dd1c 100644
--- a/src/screens/Product/components/Book.js
+++ b/src/screens/Product/components/Book.js
@@ -464,7 +464,7 @@ function Book({
-
+
>
)}
diff --git a/src/screens/Product/components/Rates.js b/src/screens/Product/components/Rates.js
index 0c73bbb..d904bff 100644
--- a/src/screens/Product/components/Rates.js
+++ b/src/screens/Product/components/Rates.js
@@ -1,6 +1,9 @@
import React from "react";
import { View, Text, Dimensions, Appearance } from "react-native";
-import { Rating } from 'react-native-ratings';
+import { Rating } from "react-native-ratings";
+import { connect } from "react-redux";
+import { vote } from "../../../redux/actions";
+import { asyncAwesomeAlert } from "../../../utils/AsyncWrappers";
//assets
import tw from "tailwind-rn";
@@ -9,12 +12,11 @@ import Colors from "../../../constants/Colors";
const width = Dimensions.get("window").width;
-export default function Rates({ rate }) {
-
+function Rates({ rate, productId, addVote, isBuyed }) {
const ratingCompleted = (rating) => {
return;
- }
-
+ };
+
return (
@@ -26,17 +28,27 @@ export default function Rates({ rate }) {
{rate}
ratingCompleted(rating)}
+ onFinishRating={(rating) =>
+ isBuyed
+ ? addVote({ productId, vote: rating })
+ : asyncAwesomeAlert(
+ "خطا",
+ "شما این محصول رو خریداری نکرده اید.",
+ {
+ showCancelButton: false,
+ }
+ )
+ }
/>
{`از بین ${1150} نفر`}
@@ -59,8 +71,8 @@ export default function Rates({ rate }) {
const Progress = ({ data, ...props }) => {
const colorScheme = React.useMemo(() => {
- return Appearance.getColorScheme();
- },[props.useless]);
+ return Appearance.getColorScheme();
+ }, [props.useless]);
return (
@@ -82,7 +94,10 @@ const Progress = ({ data, ...props }) => {
@@ -100,3 +115,11 @@ const Progress = ({ data, ...props }) => {
);
};
+
+const mapStateToProps = (state) => ({});
+
+const mapDispatchToProps = {
+ addVote: vote.add,
+};
+
+export default connect(mapStateToProps, mapDispatchToProps)(Rates);