diff --git a/src/AppRouter.js b/src/AppRouter.js index eee93d1..0e03167 100644 --- a/src/AppRouter.js +++ b/src/AppRouter.js @@ -39,7 +39,7 @@ class AppRouter extends Component { let home = ( {proxy.status() ? ( - this.props.profile.status ? ( + this.props.profile ? ( ) : ( diff --git a/src/Redux/actions/index.js b/src/Redux/actions/index.js index 68717d3..090cb86 100644 --- a/src/Redux/actions/index.js +++ b/src/Redux/actions/index.js @@ -7,3 +7,4 @@ export { default as user } from "./user.js"; export { default as qr } from "./qr.js"; export { default as book } from "./book.js"; export { default as userProduct } from "./userProduct.js"; +export { default as transport } from "./transport.js"; diff --git a/src/Redux/actions/transport.js b/src/Redux/actions/transport.js new file mode 100644 index 0000000..671cc9f --- /dev/null +++ b/src/Redux/actions/transport.js @@ -0,0 +1,31 @@ +import proxy from "../proxy"; +const transport = { + list: + (data = {}) => + async (dispatch) => + await proxy.get("transport/list", data, { dispatch }), + info: + (data = {}) => + async (dispatch) => + await proxy.get("transport/info", data, { dispatch }), + update: + (data = {}, data2 = {}) => + async (dispatch) => { + await proxy.put("transport/update", data); + await proxy.get("transport/list", data2, { dispatch }); + }, + add: + (data = {}, data2 = {}) => + async (dispatch) => { + await proxy.post("transport/add", data); + await proxy.get("transport/list", data2, { dispatch }); + }, + del: + (data = {}, data2 = {}) => + async (dispatch) => { + await proxy.delete("transport/delete", data); + await proxy.get("transport/list", data2, { dispatch }); + }, +}; + +export default transport; diff --git a/src/Redux/proxy.js b/src/Redux/proxy.js index c7b51b0..6058c2e 100644 --- a/src/Redux/proxy.js +++ b/src/Redux/proxy.js @@ -68,7 +68,7 @@ class Proxy { localStorage.setItem("access", login.accessToken); delete login.refreshToken; delete login.accessToken; - localStorage.setItem("userData", JSON.stringify(login)); + localStorage.setItem("userData", JSON.stringify(login.profile)); dispatch(obj); }, }); @@ -93,8 +93,7 @@ class Proxy { localStorage.removeItem("userData"); return false; } - let fakeUserData = JSON.parse(userData); - return fakeUserData.profile; + return JSON.parse(userData); }; } const _proxy = new Proxy(); diff --git a/src/Redux/reducers/book.js b/src/Redux/reducers/book.js index 28a4ca7..f97bccf 100644 --- a/src/Redux/reducers/book.js +++ b/src/Redux/reducers/book.js @@ -44,7 +44,6 @@ export default function book(state = initialState, action) { (item) => item.name.indexOf(subject.map((item) => item)) !== -1 ) : byLevelFilter; - console.log(bySubjectFilter); const bySearchFilter = search ? bySubjectFilter.filter((item) => item.name.indexOf(search) !== -1) : bySubjectFilter; diff --git a/src/Redux/reducers/index.js b/src/Redux/reducers/index.js index 6599424..6491242 100644 --- a/src/Redux/reducers/index.js +++ b/src/Redux/reducers/index.js @@ -7,3 +7,4 @@ export { default as user } from "./user.js"; export { default as qr } from "./qr.js"; export { default as book } from "./book.js"; export { default as userProduct } from "./userProduct.js"; +export { default as transport } from "./transport.js"; diff --git a/src/Redux/reducers/transport.js b/src/Redux/reducers/transport.js new file mode 100644 index 0000000..f5fbbec --- /dev/null +++ b/src/Redux/reducers/transport.js @@ -0,0 +1,27 @@ +const initialState = { + loading: true, + error: null, + list: [], + info: null, +}; +export default function transport(state = initialState, action) { + let { type, data } = action; + switch (type) { + case "transport/list": + return { ...state, loading: false, list: data, error: null }; + case "transport/info": + return { ...state, loading: false, list: null, info: data, error: null }; + case "transport/update": + return { ...state, loading: false, error: null }; + case "transport/add": + return { ...state, loading: false, error: null }; + case "transport/delete": + return { ...state, loading: false, error: null }; + case "loading": + return { ...state, loading: true }; + case "error": + return { ...state, loading: false, error: data.message }; + default: + return state; + } +} diff --git a/src/Redux/reducers/user.js b/src/Redux/reducers/user.js index 0eb7ea4..cfbc526 100644 --- a/src/Redux/reducers/user.js +++ b/src/Redux/reducers/user.js @@ -15,10 +15,8 @@ export default function user(state = initialState, action) { case "user/login": case "user/register": case "user/switchRole": - case "user/getProfile": - case "user/login": case "public/sendOTP": - return { ...state, loading: false, status: data, error: null }; + return { ...state, loading: false, status: data.profile, error: null }; case "user/otp/login": return { ...state, @@ -26,6 +24,9 @@ export default function user(state = initialState, action) { status: data.profile, error: null, }; + case "user/getProfile": + localStorage.setItem("userData", JSON.stringify(data)); + return { ...state, loading: false, status: data, error: null }; case "user/logout": return { ...state, loading: false, status: proxy.status(), error: null }; case "user/getUserRole": diff --git a/src/Redux/reducers/userProduct.js b/src/Redux/reducers/userProduct.js index 6715457..c190b26 100644 --- a/src/Redux/reducers/userProduct.js +++ b/src/Redux/reducers/userProduct.js @@ -3,7 +3,7 @@ import { toast } from "react-toastify"; const initialState = { loading: false, error: null, - list: null, + list: [], info: null, sum: null, }; @@ -13,7 +13,7 @@ export default function userProduct(state = initialState, action) { case "userProduct/list": return { ...state, loading: false, list: data, error: null }; case "userProduct/info": - return { ...state, loading: false, list: null, info: data, error: null }; + return { ...state, loading: false, info: data, error: null }; case "userProduct/update": return { ...state, loading: false, error: null }; case "userProduct/add": diff --git a/src/views/Auth/Profile/Input/index.js b/src/views/Auth/Profile/Input/index.js index 3394023..cb9c380 100644 --- a/src/views/Auth/Profile/Input/index.js +++ b/src/views/Auth/Profile/Input/index.js @@ -13,6 +13,7 @@ export default function FormPropsTextFields(props) { textAlign: props.align, direction: props.align === "right" ? "rtl" : "ltr", }, + fontFamily: "numeralLight", }, }, })); @@ -33,7 +34,6 @@ export default function FormPropsTextFields(props) { onInput={(e) => (e.target.value = onInput(e.target.value))} /> - + ); } diff --git a/src/views/Auth/Profile/index.js b/src/views/Auth/Profile/index.js index 943a806..b35d121 100644 --- a/src/views/Auth/Profile/index.js +++ b/src/views/Auth/Profile/index.js @@ -196,7 +196,7 @@ class Profile extends Component { return ( <> {window.innerWidth > 1000 ? ( - !this.props.loading ? ( + profile ? (

حساب کاربری

@@ -403,7 +403,7 @@ class Profile extends Component { ) ) : null} {window.innerWidth < 1000 ? ( - !this.props.loading ? ( + profile ? (
دانوین

حساب کاربری

@@ -423,6 +423,7 @@ class Profile extends Component { label="نام خانوادگی" parent={this} defaultValue={profile} + onInput={this.forcePersian} /> ({ - profile: state.user.status || {}, + profile: state.user.status, loading: state.user.loading, }), { getProfile: user.getProfile, setProfile: user.setProfile } diff --git a/src/views/Auth/Profile/index.scss b/src/views/Auth/Profile/index.scss index 058b9ed..bbe9bd3 100644 --- a/src/views/Auth/Profile/index.scss +++ b/src/views/Auth/Profile/index.scss @@ -25,8 +25,10 @@ } &__upload { margin: 10px auto; - min-width: 130px; - min-height: 130px; + min-width: 100px; + min-height: 100px; + height: calc(100vh / 7); + width: calc(100vh / 7); border-radius: 50%; background-color: rgb(209, 209, 209); position: relative; @@ -69,6 +71,7 @@ .MuiOutlinedInput-input { padding: 15px 14px !important; + font-family: numeralLight; } .MuiInputLabel-outlined { font-family: numeralLight !important; @@ -98,7 +101,7 @@ letter-spacing: -1px; } .Mui-focused { - color: rgba(0, 0, 0, 0.54) !important; + color: rgba(0, 0, 0, 1) !important; border-color: #c4c4c5 !important; background-color: white; } @@ -116,11 +119,11 @@ border: 0px; background-color: #128c7e; border-radius: 7px; - width: 90%; + width: 100%; font-size: 18px; - font-weight: 600; color: white; padding: 12px 0px; + margin-top: 10px; } } @media screen and (max-width: 1000px) { diff --git a/src/views/Cart/DeliveryMethod/index.js b/src/views/Cart/DeliveryMethod/index.js index 7abd8e0..9f22f7f 100644 --- a/src/views/Cart/DeliveryMethod/index.js +++ b/src/views/Cart/DeliveryMethod/index.js @@ -1,5 +1,4 @@ - -import './index.scss'; +import "./index.scss"; const maxDesktopSize = 1250; const maxMobileSize = 550; @@ -30,10 +29,7 @@ const DeliveryMethod = (props) => {
props.parent.setState({ selectedDelivery: props.data }) @@ -76,4 +72,4 @@ const DeliveryMethod = (props) => { ); }; -export default DeliveryMethod; \ No newline at end of file +export default DeliveryMethod; diff --git a/src/views/Cart/DeliveryMethod/index.scss b/src/views/Cart/DeliveryMethod/index.scss index 45e73bb..f72dbfb 100644 --- a/src/views/Cart/DeliveryMethod/index.scss +++ b/src/views/Cart/DeliveryMethod/index.scss @@ -29,6 +29,8 @@ border-radius: 10px; border: 1px solid #88a9ff; margin-top: 10px; + flex: 1; + max-width: 45%; h3, strong, span { diff --git a/src/views/Cart/Discount/index.js b/src/views/Cart/Discount/index.js index cb78483..41b05b4 100644 --- a/src/views/Cart/Discount/index.js +++ b/src/views/Cart/Discount/index.js @@ -6,9 +6,9 @@ const maxMobileSize = 550; const fontSize = { desktop: { - h2: window.innerWidth > maxDesktopSize ? 20 : window.innerWidth / 55, + h2: window.innerWidth > maxDesktopSize ? 16 : window.innerWidth / 55, input: window.innerWidth > maxDesktopSize ? 16 : window.innerWidth / 75, - button: window.innerWidth > maxDesktopSize ? 16 : window.innerWidth / 75, + button: window.innerWidth > maxDesktopSize ? 15 : window.innerWidth / 75, p: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 90, }, mobile: { diff --git a/src/views/Cart/Factor/index.js b/src/views/Cart/Factor/index.js index 9a1243b..9618fd1 100644 --- a/src/views/Cart/Factor/index.js +++ b/src/views/Cart/Factor/index.js @@ -1,5 +1,5 @@ -import React, { Component } from 'react'; -import './index.scss'; +import React, { Component } from "react"; +import "./index.scss"; const maxDesktopSize = 1250; const maxMobileSize = 550; @@ -10,8 +10,8 @@ const fontSize = { th: window.innerWidth > maxDesktopSize ? 16 : window.innerWidth / 80, h2: window.innerWidth > maxDesktopSize ? 20 : window.innerWidth / 55, h3: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 90, - strong: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 90, - span: window.innerWidth > maxDesktopSize ? 10 : window.innerWidth / 95, + strong: window.innerWidth > maxDesktopSize ? 13 : window.innerWidth / 90, + span: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 95, }, mobile: { h1: window.innerWidth > maxMobileSize ? 20 : window.innerWidth / 13, @@ -55,16 +55,28 @@ const Factor = (props) => { {window.innerWidth > 1000 ? (
- مبلغ سبد خرید - {totalPrice()} تومان + + مبلغ سبد خرید + + + {totalPrice()} تومان +
- هزینه ارسال - {props.parent.state.selectedDelivery.price} تومان + + هزینه ارسال + + + {props.parent.state.selectedDelivery.price} تومان +
- میزان تخفیف - {props.parent.state.discount} تومان + + میزان تخفیف + + + {props.parent.state.discount} تومان +
) : null} @@ -72,4 +84,4 @@ const Factor = (props) => { ); }; -export default Factor; \ No newline at end of file +export default Factor; diff --git a/src/views/Cart/index.js b/src/views/Cart/index.js index 931c747..bc07199 100644 --- a/src/views/Cart/index.js +++ b/src/views/Cart/index.js @@ -1,6 +1,6 @@ import React, { Component } from "react"; import { connect } from "react-redux"; -import { userProduct } from "~/Redux/actions"; +import { userProduct, transport } from "~/Redux/actions"; import { ToastContainer } from "react-toastify"; import Navbar from "../Home/Navbar/index"; @@ -22,7 +22,7 @@ const fontSize = { desktop: { h1: window.innerWidth > maxDesktopSize ? 30 : window.innerWidth / 40, th: window.innerWidth > maxDesktopSize ? 16 : window.innerWidth / 80, - h2: window.innerWidth > maxDesktopSize ? 20 : window.innerWidth / 55, + h2: window.innerWidth > maxDesktopSize ? 16 : window.innerWidth / 55, h3: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 90, strong: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 90, span: window.innerWidth > maxDesktopSize ? 10 : window.innerWidth / 95, @@ -77,8 +77,22 @@ class Cart extends Component { ], }; + componentDidUpdate(prevProps, prevState) { + if (this.props.list.length > 0) { + let wantedId; //should be zero + for (let item of this.props.list) { + if (item.condition) { + wantedId = item.id; + break; + } + } + this.props.getInfo({ id: wantedId }); + } + } + componentDidMount() { this.props.getList(); + this.props.getTransportList(); } handleCounter = (type, id) => { @@ -113,7 +127,7 @@ class Cart extends Component { }; render() { - const { list, payPrice } = this.props; + const { list, payPrice, payMethods } = this.props; return ( <> {window.innerWidth > 1000 ? ( @@ -145,7 +159,7 @@ class Cart extends Component { روشهای ارسال
- {this.props.payMethods.map((item, i) => ( + {payMethods.map((item, i) => ( ))}
@@ -175,7 +189,7 @@ class Cart extends Component { با توجه به شرایط یکی از دو گزینه زیر را انتخاب کنید

- {this.props.payMethods.map((item, i) => ( + {payMethods.map((item, i) => ( ))}
@@ -279,19 +293,11 @@ export default connect( (state) => ({ list: state.userProduct.list, payPrice: state.userProduct.sum, + payMethods: state.transport.list, }), - { getList: userProduct.list } + { + getList: userProduct.list, + getInfo: userProduct.info, + getTransportList: transport.list, + } )(Cart); - -Cart.defaultProps = { - payMethods: [ - { - name: "ارسال با پست پیشتاز", - price: 36.891, - }, - { - name: "ارسال با پیک موتوری", - price: 36.891, - }, - ], -};