From 8931e08769c1e70306d44deaf2027b7c353e4998 Mon Sep 17 00:00:00 2001 From: Reza_ashrafi Date: Sat, 28 May 2022 10:57:27 +0430 Subject: [PATCH] update 7 files --- src/redux/actions/file.js | 5 +- src/redux/proxy.js | 6 --- src/redux/reducers/file.js | 3 +- src/screens/DeliveryForm/index.js | 1 - src/screens/Product/components/Book.js | 4 +- src/screens/Product/components/Rates.js | 67 +++++++++++++++++++++---- src/screens/ShoppingCart/index.js | 2 - 7 files changed, 63 insertions(+), 25 deletions(-) diff --git a/src/redux/actions/file.js b/src/redux/actions/file.js index 02090a1..bb281c1 100644 --- a/src/redux/actions/file.js +++ b/src/redux/actions/file.js @@ -4,7 +4,8 @@ const file = { (data = {}) => async (dispatch) => { var formData = new FormData(); - for (let key in data) formData.append(key, data[key]); + const myData = { ...data, file: { ...data.file, type: "image/jpg" } } + for (let key in myData) formData.append(key, myData[key]); return await proxy.post( "file/upload", formData, @@ -14,7 +15,7 @@ const file = { "Content-Type": "multipart/form-data", }, }, - data + formData ); }, }; diff --git a/src/redux/proxy.js b/src/redux/proxy.js index d9e80b6..a076170 100644 --- a/src/redux/proxy.js +++ b/src/redux/proxy.js @@ -57,15 +57,9 @@ class Proxy { check = async (url, { dispatch }, fetch, params) => { try { - console.log(url.split("/")[0] === 'file'); dispatch = dispatch || (() => {}); dispatch({ type: url.split("/")[0] + "/" + "loading" }); let response = await fetch(); - if(url.split("/")[0] === 'file'){ - console.log('response'); - console.log(response); - } - // console.log(response); switch (response.status) { case 200: dispatch({ type: url, data: response.data.data, params }); diff --git a/src/redux/reducers/file.js b/src/redux/reducers/file.js index b9df297..9aa975a 100644 --- a/src/redux/reducers/file.js +++ b/src/redux/reducers/file.js @@ -7,7 +7,6 @@ export default function file(state = initialState, action) { let { type, data, params } = action; switch (type) { case "file/upload": - console.log(data); return { ...state, loading: false, @@ -16,7 +15,7 @@ export default function file(state = initialState, action) { case "file/loading": return { ...state, loading: true }; case "file/error": - console.log(error); + console.log(data.message); return { ...state, loading: false, error: data.message }; default: return state; diff --git a/src/screens/DeliveryForm/index.js b/src/screens/DeliveryForm/index.js index a675c70..b22de8a 100644 --- a/src/screens/DeliveryForm/index.js +++ b/src/screens/DeliveryForm/index.js @@ -115,7 +115,6 @@ const DeliveryForm = ({ flex: 1, }} > - {console.log(factorInfo)} - {product?.rate || 4 ? ( + {book?.rate || 4 ? ( <> - + { + return rateDetail?.filter((rate) => rate?.rate === 5)[0]; + }, [rateDetail]); + + const fourCount = React.useMemo(() => { + return rateDetail?.filter((rate) => rate?.rate === 4)[0]; + }, [rateDetail]); + + const threeCount = React.useMemo(() => { + return rateDetail?.filter((rate) => rate?.rate === 3)[0]; + }, [rateDetail]); + + const twoCount = React.useMemo(() => { + return rateDetail?.filter((rate) => rate?.rate === 2)[0]; + }, [rateDetail]); + + const oneCount = React.useMemo(() => { + return rateDetail?.filter((rate) => rate?.rate === 1)[0]; + }, [rateDetail]); + + const allCount = React.useMemo(() => { + return rateDetail?.reduce((a, b) => a + b?.count, 0); + }, [rateDetail]); + + const rate = React.useMemo(() => { + return ((oneCount?.count || 0) * 1 + + (twoCount?.count || 0) * 2 + + (threeCount?.count || 0) * 3 + + (fourCount?.count || 0) * 4 + + (fiveCount?.count || 0) * 5) / rateDetail?.length; + }, [rateDetail]); + return ( - {rate} + {rate || 4} addVote({ productId, vote: rating })} readonly={!isBuyed} /> - {/* - {`از بین ${1150} نفر`} - */} + {`از بین ${allCount} نفر`} + {[ - { name: "یک ستاره", value: 40 }, - { name: "دو ستاره", value: 10 }, - { name: "سه ستاره", value: 10 }, - { name: "چهار ستاره", value: 30 }, - { name: "پنج ستاره", value: 10 }, + { + name: "یک ستاره", + value: ((oneCount?.count || 0) / allCount) * 100, + }, + { + name: "دو ستاره", + value: ((twoCount?.count || 0) / allCount) * 100, + }, + { + name: "سه ستاره", + value: ((threeCount?.count || 0) / allCount) * 100, + }, + { + name: "چهار ستاره", + value: ((fourCount?.count || 0) / allCount) * 100, + }, + { + name: "پنج ستاره", + value: ((fiveCount?.count || 0) / allCount) * 100, + }, ].map((field, index) => ( ))} diff --git a/src/screens/ShoppingCart/index.js b/src/screens/ShoppingCart/index.js index 4a47ea2..d517fb8 100644 --- a/src/screens/ShoppingCart/index.js +++ b/src/screens/ShoppingCart/index.js @@ -187,7 +187,6 @@ function ShoppingCart({ type="error" theme={theme} /> - - {console.log(factorInfo?.transportPrice)} {isEmpty ? 0 : separate(factorInfo?.payPrice)}