From edf81c70742943ecb9d8c45934de1a48bb527df8 Mon Sep 17 00:00:00 2001 From: RezaAshrafi77 Date: Sun, 19 Sep 2021 14:53:16 +0430 Subject: [PATCH] reza fixed sliders and convert redux to TS --- src/components/GradeFilter/index.scss | 9 +- src/redux/actions-type/index.tsx | 3 + src/redux/actions-type/public.tsx | 33 +++++ src/redux/actions-type/user.tsx | 49 +++++++ src/redux/actions/index.js | 4 - src/redux/actions/index.tsx | 4 + src/redux/actions/public.js | 25 ---- src/redux/actions/public.tsx | 34 +++++ src/redux/actions/user.js | 61 -------- src/redux/actions/user.tsx | 61 ++++++++ src/redux/{proxy.js => proxy.tsx} | 58 +++++--- src/redux/reducers/index.js | 3 - src/redux/reducers/index.tsx | 3 + src/redux/reducers/public.js | 171 ----------------------- src/redux/reducers/public.tsx | 171 +++++++++++++++++++++++ src/redux/reducers/{user.js => user.tsx} | 23 +-- src/views/Home/Blogs/Blog/index.tsx | 7 +- src/views/Home/Books/Book/index.tsx | 8 +- src/views/Home/Courses/Course/index.tsx | 21 +-- 19 files changed, 433 insertions(+), 315 deletions(-) create mode 100644 src/redux/actions-type/index.tsx create mode 100644 src/redux/actions-type/public.tsx create mode 100644 src/redux/actions-type/user.tsx delete mode 100644 src/redux/actions/index.js create mode 100644 src/redux/actions/index.tsx delete mode 100644 src/redux/actions/public.js create mode 100644 src/redux/actions/public.tsx delete mode 100644 src/redux/actions/user.js create mode 100644 src/redux/actions/user.tsx rename src/redux/{proxy.js => proxy.tsx} (60%) delete mode 100644 src/redux/reducers/index.js create mode 100644 src/redux/reducers/index.tsx delete mode 100644 src/redux/reducers/public.js create mode 100644 src/redux/reducers/public.tsx rename src/redux/reducers/{user.js => user.tsx} (72%) diff --git a/src/components/GradeFilter/index.scss b/src/components/GradeFilter/index.scss index c6c54aa..5a498c5 100644 --- a/src/components/GradeFilter/index.scss +++ b/src/components/GradeFilter/index.scss @@ -31,7 +31,7 @@ } &__active{ background-color: #9CDF52; - box-shadow: 0px 0px 24px #9CDF52; + box-shadow: 0px 0px 20px #9CDF52; border-radius: 5px; } } @@ -113,7 +113,7 @@ h1{ font-size: calc(100vw / 50); background-color: #9CDF52; - box-shadow: 0px 0px 24px #9CDF52; + box-shadow: 0px 0px 20px #9CDF52; border-top-right-radius: 8px; border-bottom-right-radius: 8px; padding: 12px 15px; @@ -134,7 +134,7 @@ h1{ font-size: calc(100vw / 30); background-color: #9CDF52; - box-shadow: 0px 0px 24px #9CDF52; + box-shadow: 0px 0px 20px #9CDF52; border-top-right-radius: 8px; border-bottom-right-radius: 8px; padding: 12px 15px; @@ -170,8 +170,9 @@ background : #383838; padding: 10px 20px; border-radius: 10px; + justify-content:center; li{ - width: calc(100% / 4.45) !important; + width: calc(100% / 4.7) !important; margin: 8px 5px; font-size: calc(100vw / 28); padding: 5px 0px; diff --git a/src/redux/actions-type/index.tsx b/src/redux/actions-type/index.tsx new file mode 100644 index 0000000..4713c1f --- /dev/null +++ b/src/redux/actions-type/index.tsx @@ -0,0 +1,3 @@ +// @create-index +export type { default as PublicAction } from "./public"; +export type { default as UserAction } from "./user"; diff --git a/src/redux/actions-type/public.tsx b/src/redux/actions-type/public.tsx new file mode 100644 index 0000000..32c4d48 --- /dev/null +++ b/src/redux/actions-type/public.tsx @@ -0,0 +1,33 @@ +interface getHomeData { + type : "public/homePage" + data : any +} + +interface getBlogList{ + type : "public/blogList" + data : any +} + +interface getBlogInfo{ + type : "public/blogInfo" + data : any +} + +interface error{ + type : "error" + data : undefined +} + +interface loading{ + type : "loading" + data : undefined +} + +// interface filterNewProducts{ + +// } + + +type PublicAction =getBlogList | getBlogInfo | getHomeData | loading | error; + +export default PublicAction; diff --git a/src/redux/actions-type/user.tsx b/src/redux/actions-type/user.tsx new file mode 100644 index 0000000..93851ae --- /dev/null +++ b/src/redux/actions-type/user.tsx @@ -0,0 +1,49 @@ +interface otp { + type : "public/sendOTP" + data : any +} + +interface otp_login{ + type : "user/otp/login" + data : any +} + +// interface switchRole{ +// type : "user/switchRole" +// data : Object +// } + +interface logout{ + type : "user/logout" + data : any +} + +interface getUserRole{ + type : "user/getUserRole" + data : any +} + +interface getProfile{ + type : "user/getProfile" + data : any +} + +interface setProfile{ + type : "user/setProfile" + data : any +} + +interface error{ + type : "error" + data : undefined +} + +interface loading{ + type : "loading" + data : undefined +} + + +type UserAction = otp | otp_login | logout | getUserRole | getProfile | setProfile | error | loading; + +export default UserAction; diff --git a/src/redux/actions/index.js b/src/redux/actions/index.js deleted file mode 100644 index e6cca24..0000000 --- a/src/redux/actions/index.js +++ /dev/null @@ -1,4 +0,0 @@ -// @create-index -export { default as publicApi } from "./public.js"; -export { default as user } from "./user.js"; - diff --git a/src/redux/actions/index.tsx b/src/redux/actions/index.tsx new file mode 100644 index 0000000..a305439 --- /dev/null +++ b/src/redux/actions/index.tsx @@ -0,0 +1,4 @@ +// @create-index +export { default as publicApi } from "./public"; +export { default as user } from "./user"; + diff --git a/src/redux/actions/public.js b/src/redux/actions/public.js deleted file mode 100644 index 1cd07ae..0000000 --- a/src/redux/actions/public.js +++ /dev/null @@ -1,25 +0,0 @@ -import proxy from "../proxy"; -const publicApi = { - getHomeData: (data, history) => async (dispatch) => - await proxy.get("public/homePage", data, { history, dispatch }), - getFaqList: (data, history) => async (dispatch) => - await proxy.get("faq/list", data, { history, dispatch }), - setFaqActive: (data) => async (dispatch) => - await dispatch({ type: "public/faq/activate", data: data }), - searchFaq: (data) => async (dispatch) => - await dispatch({ type: "public/faq/search", data: data }), - getContactData: - (data = {}, history) => - async (dispatch) => - await proxy.get("public/contact", data, { history, dispatch }), - getArList: (data, history) => async (dispatch) => - await proxy.get("public/ar", data, { history, dispatch }), - getBlogList: (data, history) => async (dispatch) => - await proxy.get("public/blogList", data, { history, dispatch }), - getBlogInfo: (data, history) => async (dispatch) => - await proxy.get("public/blogInfo", data, { history, dispatch }), - filterNewProducts: (data, history) => async (dispatch) => - await dispatch({ type: "public/filter", data: data }), -}; - -export default publicApi; diff --git a/src/redux/actions/public.tsx b/src/redux/actions/public.tsx new file mode 100644 index 0000000..4dd5ea8 --- /dev/null +++ b/src/redux/actions/public.tsx @@ -0,0 +1,34 @@ +import { Dispatch } from "redux"; +import proxy from "../proxy"; +const publicApi = { + getHomeData: (data: undefined, history: any) => async (dispatch: Dispatch) => + await proxy.get("public/homePage", data, { history, dispatch }), + + // getFaqList: (data: undefined, history: any) => async (dispatch: Dispatch) => + // await proxy.get("faq/list", data, { history, dispatch }), + + // setFaqActive: (data: undefined) => async (dispatch: Dispatch) => + // await dispatch({ type: "public/faq/activate", data: data }), + + // searchFaq: (data: String) => async (dispatch: Dispatch) => + // await dispatch({ type: "public/faq/search", data: data }), + + // getContactData: + // (data = {}, history: any) => + // async (dispatch: Dispatch) => + // await proxy.get("public/contact", data, { history, dispatch }), + + // getArList: (data: undefined, history: any) => async (dispatch: Dispatch) => + // await proxy.get("public/ar", data, { history, dispatch }), + + getBlogList: (data: undefined, history: any) => async (dispatch: Dispatch) => + await proxy.get("public/blogList", data, { history, dispatch }), + + getBlogInfo: (data: String, history: any) => async (dispatch: Dispatch) => + await proxy.get("public/blogInfo", data, { history, dispatch }), + + // filterNewProducts: (data: Object) => async (dispatch: Dispatch) => + // await dispatch({ type: "public/filter", data: data }), +}; + +export default publicApi; diff --git a/src/redux/actions/user.js b/src/redux/actions/user.js deleted file mode 100644 index 323b730..0000000 --- a/src/redux/actions/user.js +++ /dev/null @@ -1,61 +0,0 @@ -import proxy from "../proxy"; -const user = { - otp: (data, history) => async (dispatch) => - await proxy.login("public/sendOTP", data, { history, dispatch }), - // otp: - // (data = {}) => - // async (dispatch) => - // dispatch({ type: "public/sendOTP", payload: data }), - otp_login: (data, history) => async (dispatch) => - await proxy.login("user/otp/login", data, { history, dispatch }), - // otp_login: - // (data = {}) => - // async (dispatch) => - // dispatch({ type: "user/otp/login", payload: data }), - register: (data, history) => async (dispatch) => - await proxy.login("user/register", data, { history, dispatch }), - switchRole: (data, history) => async (dispatch) => - await proxy.login("user/switchRole", data, { history, dispatch }), - logout: (data, history) => async (dispatch) => - await proxy.logout("user/logout", data, { history, dispatch }), - getUserRole: (data) => async (dispatch) => - await proxy.get("user/getUserRole", data, { dispatch }), - list: - (data = {}) => - async (dispatch) => - await proxy.get("user/list", data, { dispatch }), - domains: - (data = {}) => - async (dispatch) => - await proxy.get("user/domains", data, { dispatch }), - getmothers: - (data = {}) => - async (dispatch) => - await proxy.get2("mothers/list", data, { - dispatch, - }), - getProfile: - (data = {}) => - async (dispatch) => - await proxy.get("user/getProfile", data, { dispatch }), - setProfile: - (data = {}, data2 = {}) => - async (dispatch) => { - await proxy.put("user/setProfile", data, { dispatch }); - await proxy.get("user/getProfile", data2, { dispatch }); - }, - add: - (data = {}, data2 = {}) => - async (dispatch) => { - await proxy.post("user/add", data); - await proxy.get("user/list", data2, { dispatch }); - }, - del: - (data = {}, data2 = {}) => - async (dispatch) => { - await proxy.delete("user/delete", data); - await proxy.get("user/list", data2, { dispatch }); - }, -}; - -export default user; diff --git a/src/redux/actions/user.tsx b/src/redux/actions/user.tsx new file mode 100644 index 0000000..2afc512 --- /dev/null +++ b/src/redux/actions/user.tsx @@ -0,0 +1,61 @@ +import proxy from "../proxy"; +import {Dispatch} from 'redux'; + +const user = { + otp: (data : String) => async (dispatch : Dispatch) => + await proxy.login("public/sendOTP", data, { dispatch }), + + otp_login: (data : Object) => async (dispatch : Dispatch) => + await proxy.login("user/otp/login", data, { dispatch }), + + // register: (data : undefined) => async (dispatch : Dispatch) => + // await proxy.login("user/register", data, { dispatch }), + + // switchRole: (data : String) => async (dispatch : Dispatch) => + // await proxy.login("user/switchRole", data, { dispatch }), + + logout: (data : String) => async (dispatch : Dispatch) => + await proxy.logout("user/logout", data, { dispatch }), + + getUserRole: (data : String) => async (dispatch : Dispatch) => + await proxy.get("user/getUserRole", data, { dispatch }), + + // list: + // (data = {}) => + // async (dispatch : Dispatch) => + // await proxy.get("user/list", data, { dispatch }), + // domains: + // (data = {}) => + // async (dispatch : Dispatch) => + // await proxy.get("user/domains", data, { dispatch }), + // getmothers: + // (data = {}) => + // async (dispatch : Dispatch) => + // await proxy.get("mothers/list", data, { + // dispatch, + // }), + getProfile: + (data = {}) => + async (dispatch : Dispatch) => + await proxy.get("user/getProfile", data, { dispatch }), + setProfile: + (data = {}, data2 = {}) => + async (dispatch : Dispatch) => { + await proxy.put("user/setProfile", data, { dispatch }); + await proxy.get("user/getProfile", data2, { dispatch }); + }, + add: + (data = {}, data2 = {}) => + async (dispatch : Dispatch) => { + await proxy.post("user/add", data); + await proxy.get("user/list", data2, { dispatch }); + }, + del: + (data = {}, data2 = {}) => + async (dispatch : Dispatch) => { + await proxy.delete("user/delete", data); + await proxy.get("user/list", data2, { dispatch }); + }, +}; + +export default user; diff --git a/src/redux/proxy.js b/src/redux/proxy.tsx similarity index 60% rename from src/redux/proxy.js rename to src/redux/proxy.tsx index 858bb02..05588b1 100644 --- a/src/redux/proxy.js +++ b/src/redux/proxy.tsx @@ -1,9 +1,11 @@ -import { ApiConfig } from "~/constants/defaultValues"; +import { ApiConfig } from "../constants/defaultValues"; import axios from "axios"; +import {Dispatch} from 'redux'; let { baseUrl } = ApiConfig; let access = window.localStorage.getItem("access"); baseUrl = baseUrl + "/"; + const Axios = axios.create({ withCredentials: true, validateStatus: null, @@ -11,41 +13,57 @@ const Axios = axios.create({ //headers: access ? { Authorization: `Bearer ${access}` } : {}, }); class Proxy { - get = async (url, params, opt = {}) => + get = async (url: any, params: any, opt: any = {}, data: any = {}) => + await this.check( + url, + opt, + async () => await Axios.get(url, { params, ...opt }), + data || params + ); + post = async (url: any, params: any, opt: any = {}, data : any = {}) => await this.check( url, opt, - async () => await Axios.get(url, { params, ...opt }) + async () => await Axios.post(url, params, opt), + data || params ); - post = async (url, params, opt = {}) => - await this.check(url, opt, async () => await Axios.post(url, params, opt)); - put = async (url, params, opt = {}) => - await this.check(url, opt, async () => await Axios.put(url, params, opt)); - delete = async (url, params, opt = {}) => { + put = async (url : any, params : any, opt : any = {}, data : any = {}) => await this.check( url, opt, - async () => await Axios.delete(url, { ...opt, data: params }) + async () => await Axios.put(url, params, opt), + data || params + ); + delete = async (url : any, params : any, opt : any = {}, data : any = {}) => { + await this.check( + url, + opt, + async () => await Axios.delete(url, { ...opt, data: params }), + data || params ); }; - check = async (url, { dispatch }, fetch) => { + check = async (url : any, { dispatch } : any, fetch : any, params : any) => { dispatch = dispatch || (() => {}); - dispatch({ type: "loading" }); + dispatch({ type: url.split("/")[0] + "/" + "loading" }); let response = await fetch(); switch (response.status) { case 200: - dispatch({ type: url, data: response.data.data }); + dispatch({ type: url, data: response.data.data, params }); return response.data.data; case 401: if (await this.refresh()) { let response = await fetch(); - dispatch({ type: url, data: response.data.data }); + dispatch({ type: url, data: response.data.data, params }); return response.data.data; } break; default: - dispatch({ type: "error", data: response.data }); + dispatch({ + type: url.split("/")[0] + "/" + "error", + data: response.data, + params, + }); } return false; }; @@ -54,14 +72,15 @@ class Proxy { let refresh = localStorage.getItem("refresh"); if (!refresh) window.location.href = "/"; let login = await this.login( + "user/login", {}, { headers: { Authorization: `Bearer ${refresh}` } } ); return login ? true : false; }; - login = async (url, params, { dispatch }) => + login = async (url : any, params : any, { dispatch } : any) => this.post(url, params, { - dispatch: (obj) => { + dispatch: (obj : any) => { let login = obj.data; if (!login || !login.refreshToken) return false; localStorage.setItem("refresh", login.refreshToken); @@ -73,9 +92,9 @@ class Proxy { }, }); - logout = async (url, params, { dispatch }) => { + logout = async (url : any, params : any, { dispatch } : any) => { this.post(url, params, { - dispatch: (obj) => { + dispatch: (obj : any) => { localStorage.removeItem("refresh"); localStorage.removeItem("access"); localStorage.removeItem("userData"); @@ -93,7 +112,8 @@ class Proxy { localStorage.removeItem("userData"); return false; } - return JSON.parse(userData); + + return JSON.parse(userData || ''); }; } const _proxy = new Proxy(); diff --git a/src/redux/reducers/index.js b/src/redux/reducers/index.js deleted file mode 100644 index 38fce99..0000000 --- a/src/redux/reducers/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// @create-index -export { default as publicApi } from "./public.js"; -export { default as user } from "./user.js"; diff --git a/src/redux/reducers/index.tsx b/src/redux/reducers/index.tsx new file mode 100644 index 0000000..d34f1e3 --- /dev/null +++ b/src/redux/reducers/index.tsx @@ -0,0 +1,3 @@ +// @create-index +export { default as publicApi } from "./public"; +export { default as user } from "./user"; diff --git a/src/redux/reducers/public.js b/src/redux/reducers/public.js deleted file mode 100644 index e444d63..0000000 --- a/src/redux/reducers/public.js +++ /dev/null @@ -1,171 +0,0 @@ -const initialState = { - homeData: [], - newProducts: [], - levels: [], - faqList: [], - loading: false, - error: null, - searchResult: [], - contactData: null, - arList: [], - blogList: [], - blog: null, -}; - -const grades = [ - "پیش دبستان", - "اول", - "دوم", - "سوم", - "چهارم", - "پنجم", - "ششم", - "هفتم", - "هشتم", - "نهم", - "دهم", - "یازدهم", - "دوازدهم", -]; -export default function publicApi(state = initialState, action) { - let { type, data } = action; - switch (type) { - case "public/homePage": - let itemsLevel; - if (window.innerWidth > 1000) { - const jadidTarin = data.filter( - (item) => item.title === "جدیدترین کتاب‌های دانوین" - ); - itemsLevel = jadidTarin[0].data - .map((item) => item.book.gradeId * 1) - .sort((a, b) => a - b) - .map((e) => grades[e]); - itemsLevel.unshift("همه"); - } - - return { - ...state, - loading: false, - levels: window.innerWidth > 1000 ? [...new Set(itemsLevel)] : [], - error: null, - homeData: data, - }; - case "public/filter": - const realList = - state.newProducts.length === 0 - ? state.homeData.filter( - (item) => item.title === "جدیدترین کتاب‌های دانوین" - )[0].data - : state.newProducts; - if (state.newProducts.length === 0) { - state = { - ...state, - newProducts: realList, - }; - console.log("here1"); - } - const level = data.levels; - const search = data.search; - if (level.length > 0 || search) { - localStorage.setItem("filter", "ON"); - } else { - return { - ...state, - loading: false, - error: null, - homeData: state.homeData.map((item) => - item.title === "جدیدترین کتاب‌های دانوین" - ? { ...item, data: state.newProducts } - : { ...item } - ), - newProducts: [], - }; - } - let byLevelFilter = []; - if (level.length > 0) { - level.map((item1) => { - for (let i = 0; i < realList.length; i++) { - if (grades[realList[i].book.gradeId] === item1) { - byLevelFilter.push(realList[i]); - } - } - }); - } else { - byLevelFilter = realList; - } - - // let bySubjectFilter = []; - // if (subject.length > 0) { - // subject.map((item1) => { - // for (let i = 0; i < byLevelFilter.length; i++) { - // if (byLevelFilter[i].name === item1) { - // bySubjectFilter.push(byLevelFilter[i]); - // } - // } - // }); - // } else { - // bySubjectFilter = byLevelFilter; - // } - - const bySearchFilter = search - ? byLevelFilter.filter((item1) => item1.name.indexOf(search) !== -1) - : byLevelFilter; - // if (sort === "گران ترین") { - // finalSort = bySearchFilter.sort((item1, item2) => { - // return item1.product[0].price - item2.product[0].price; - // }); - // } else { - // finalSort = bySearchFilter; - // } - - return { - ...state, - loading: false, - error: null, - homeData: state.homeData.map((item) => - item.title === "جدیدترین کتاب‌های دانوین" - ? { ...item, data: bySearchFilter } - : { ...item } - ), - }; - case "faq/list": - return { ...state, loading: false, error: null, faqList: data }; - case "public/faq/activate": - return { - ...state, - loading: false, - error: null, - faqList: state.faqList.map((item) => - item.id === data - ? { ...item, active: !item.active } - : { ...item, active: false } - ), - }; - case "public/faq/search": - return { - ...state, - loading: false, - error: null, - searchResult: state.faqList.filter( - (item) => - item.title.indexOf(data) !== -1 || - item.description.indexOf(data) !== -1 - ), - }; - case "public/contact": - return { ...state, loading: false, error: null, contactData: data }; - case "public/ar": - return { ...state, loading: false, error: null, arList: data }; - case "public/blogList": - return { ...state, loading: false, error: null, blogList: data }; - case "public/blogInfo": - return { ...state, loading: false, error: null, blog: data }; - case "loading": - return { ...state, loading: true }; - case "error": - return { ...state, loading: false, error: data.message }; - - default: - return state; - } -} diff --git a/src/redux/reducers/public.tsx b/src/redux/reducers/public.tsx new file mode 100644 index 0000000..b5ec61e --- /dev/null +++ b/src/redux/reducers/public.tsx @@ -0,0 +1,171 @@ +import { PublicAction } from "../actions-type"; +const initialState = { + homeData: [], + newProducts: [], + levels: [], + faqList: [], + loading: false, + error: null, + searchResult: [], + contactData: null, + arList: [], + blogList: [], + blog: null, +}; + +const grades = [ + "پیش دبستان", + "اول", + "دوم", + "سوم", + "چهارم", + "پنجم", + "ششم", + "هفتم", + "هشتم", + "نهم", + "دهم", + "یازدهم", + "دوازدهم", +]; +export default function publicApi(state = initialState, action: PublicAction) { + let { type, data } = action; + switch (type) { + case "public/homePage": + let itemsLevel; + if (window.innerWidth > 1000) { + const jadidTarin = data.filter( + (item : any) => item.title === "جدیدترین کتاب‌های دانوین" + ); + itemsLevel = jadidTarin[0].data + .map((item : any) => item.book.gradeId * 1) + .sort((a : any, b : any) => a - b) + .map((e : any) => grades[e]); + itemsLevel.unshift("همه"); + } + + return { + ...state, + loading: false, + levels: window.innerWidth > 1000 ? Array.from(new Set(itemsLevel)) : [], + error: null, + homeData: data, + }; + // case "public/filter": + // const realList = + // state.newProducts.length === 0 + // ? state.homeData.filter( + // (item) => item.title === "جدیدترین کتاب‌های دانوین" + // )[0].data + // : state.newProducts; + // if (state.newProducts.length === 0) { + // state = { + // ...state, + // newProducts: realList, + // }; + // console.log("here1"); + // } + // const level = data.levels; + // const search = data.search; + // if (level.length > 0 || search) { + // localStorage.setItem("filter", "ON"); + // } else { + // return { + // ...state, + // loading: false, + // error: null, + // homeData: state.homeData.map((item) => + // item.title === "جدیدترین کتاب‌های دانوین" + // ? { ...item, data: state.newProducts } + // : { ...item } + // ), + // newProducts: [], + // }; + // } + // let byLevelFilter = []; + // if (level.length > 0) { + // level.map((item1) => { + // for (let i = 0; i < realList.length; i++) { + // if (grades[realList[i].book.gradeId] === item1) { + // byLevelFilter.push(realList[i]); + // } + // } + // }); + // } else { + // byLevelFilter = realList; + // } + + // // let bySubjectFilter = []; + // // if (subject.length > 0) { + // // subject.map((item1) => { + // // for (let i = 0; i < byLevelFilter.length; i++) { + // // if (byLevelFilter[i].name === item1) { + // // bySubjectFilter.push(byLevelFilter[i]); + // // } + // // } + // // }); + // // } else { + // // bySubjectFilter = byLevelFilter; + // // } + + // const bySearchFilter = search + // ? byLevelFilter.filter((item1) => item1.name.indexOf(search) !== -1) + // : byLevelFilter; + // // if (sort === "گران ترین") { + // // finalSort = bySearchFilter.sort((item1, item2) => { + // // return item1.product[0].price - item2.product[0].price; + // // }); + // // } else { + // // finalSort = bySearchFilter; + // // } + + // return { + // ...state, + // loading: false, + // error: null, + // homeData: state.homeData.map((item) => + // item.title === "جدیدترین کتاب‌های دانوین" + // ? { ...item, data: bySearchFilter } + // : { ...item } + // ), + // }; + // case "faq/list": + // return { ...state, loading: false, error: null, faqList: data }; + // case "public/faq/activate": + // return { + // ...state, + // loading: false, + // error: null, + // faqList: state.faqList.map((item) => + // item.id === data + // ? { ...item, active: !item.active } + // : { ...item, active: false } + // ), + // }; + // case "public/faq/search": + // return { + // ...state, + // loading: false, + // error: null, + // searchResult: state.faqList.filter( + // (item) => + // item.title.indexOf(data) !== -1 || + // item.description.indexOf(data) !== -1 + // ), + // }; + // case "public/contact": + // return { ...state, loading: false, error: null, contactData: data }; + // case "public/ar": + // return { ...state, loading: false, error: null, arList: data }; + case "public/blogList": + return { ...state, loading: false, error: null, blogList: data }; + case "public/blogInfo": + return { ...state, loading: false, error: null, blog: data }; + 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.tsx similarity index 72% rename from src/redux/reducers/user.js rename to src/redux/reducers/user.tsx index 4dca89f..661e525 100644 --- a/src/redux/reducers/user.js +++ b/src/redux/reducers/user.tsx @@ -1,5 +1,6 @@ import proxy from "../proxy"; import { toast } from "react-toastify"; +import { UserAction} from '../actions-type' const initialState = { status: proxy.status(), loading: false, @@ -9,12 +10,12 @@ const initialState = { mothers: [], profileStatus: false, }; -export default function user(state = initialState, action) { +export default function user(state = initialState, action : UserAction) { let { type, data } = action; switch (type) { - case "user/login": - case "user/register": - case "user/switchRole": + // case "user/login": + // case "user/register": + // case "user/switchRole": case "public/sendOTP": toast.success("کد به شماره شما ارسال گردید."); return { ...state, loading: false, status: data.profile, error: null }; @@ -33,16 +34,16 @@ export default function user(state = initialState, action) { return { ...state, loading: false, status: proxy.status(), error: null }; case "user/getUserRole": return { ...state, loading: false, userRoles: data, error: null }; - case "user/list": - return { ...state, loading: false, list: data, error: null }; - case "user/domains": - return { ...state, loading: false, domains: data, error: null }; - case "mothers/list": - return { ...state, loading: false, mothers: data, error: null }; + // case "user/list": + // return { ...state, loading: false, list: data, error: null }; + // case "user/domains": + // return { ...state, loading: false, domains: data, error: null }; + // case "mothers/list": + // return { ...state, loading: false, mothers: data, error: null }; case "user/setProfile": toast.success("تغییرات اعمال شد."); setTimeout(() => { - window.location = "/"; + window.location.pathname = "/"; }, 500); return { ...state, loading: false, error: null }; case "loading": diff --git a/src/views/Home/Blogs/Blog/index.tsx b/src/views/Home/Blogs/Blog/index.tsx index 798cbd1..de9c2f1 100644 --- a/src/views/Home/Blogs/Blog/index.tsx +++ b/src/views/Home/Blogs/Blog/index.tsx @@ -1,13 +1,14 @@ import React from "react"; -import Avatar from "@material-ui/core/Avatar"; +import {Link} from 'react-router-dom'; import "./index.scss"; export default function Blog(props: any) { const { data } = props; return ( -
{/* {data.name} */}
@@ -17,6 +18,6 @@ export default function Blog(props: any) {

{data.text.slice(0, 49)}

-
+ ); } diff --git a/src/views/Home/Books/Book/index.tsx b/src/views/Home/Books/Book/index.tsx index c8127c1..b81e7fa 100644 --- a/src/views/Home/Books/Book/index.tsx +++ b/src/views/Home/Books/Book/index.tsx @@ -1,18 +1,18 @@ import React from "react"; -import Avatar from "@material-ui/core/Avatar"; +import {Link} from 'react-router-dom'; import "./index.scss"; export default function Book(props: any) { const { data } = props; return ( -
- {data.name} + + {data.name}

{data.name}

{data.text.slice(0, 50)}

-
+ ); } diff --git a/src/views/Home/Courses/Course/index.tsx b/src/views/Home/Courses/Course/index.tsx index df9cc4b..ca9041e 100644 --- a/src/views/Home/Courses/Course/index.tsx +++ b/src/views/Home/Courses/Course/index.tsx @@ -1,22 +1,23 @@ import React from "react"; import Avatar from "@material-ui/core/Avatar"; +import {Link} from 'react-router-dom'; import "./index.scss"; export default function Course(props: any) { const { data } = props; return ( -
- {data.name} + + {data.name} -
+ ); }