diff --git a/src/components/Empty/index.js b/src/components/Empty/index.js new file mode 100644 index 0000000..5767929 --- /dev/null +++ b/src/components/Empty/index.js @@ -0,0 +1,16 @@ +import React from "react"; +import { connect } from "react-redux"; + +export const Empty = ({ text, buttonText, buttonAction }) => { + return ( +
+ {text} +
+ ); +}; + +const mapStateToProps = (state) => ({}); + +const mapDispatchToProps = {}; + +export default connect(mapStateToProps, mapDispatchToProps)(Empty); diff --git a/src/components/FloatingButton/index.js b/src/components/FloatingButton/index.js index 86469d1..fe67b33 100644 --- a/src/components/FloatingButton/index.js +++ b/src/components/FloatingButton/index.js @@ -4,14 +4,14 @@ import { connect } from "react-redux"; //assets import plusIcon from "./plus.svg"; -export const FloatingButton = ({ action, position, icon }) => { +export const FloatingButton = ({ action, position, icon, size }) => { return ( ); }; @@ -24,4 +24,5 @@ export default connect(mapStateToProps, mapDispatchToProps)(FloatingButton); FloatingButton.defaultProps = { icon: plusIcon, + size : 20 }; diff --git a/src/components/Navbar/index.js b/src/components/Navbar/index.js index dc4576d..f190977 100644 --- a/src/components/Navbar/index.js +++ b/src/components/Navbar/index.js @@ -179,7 +179,7 @@ function Navbar({ back navigation(-1)} /> ) : null} diff --git a/src/redux/actions/index.js b/src/redux/actions/index.js index db08d21..8bb3521 100644 --- a/src/redux/actions/index.js +++ b/src/redux/actions/index.js @@ -7,6 +7,7 @@ export { default as product } from "./product"; export { default as userFactor } from "./userFactor"; export { default as userProduct } from "./userProduct"; export { default as userAddress } from "./userAddress"; +export { default as userFavorite } from "./userFavorite"; export { default as transport } from "./transport"; export { default as content } from "./content"; export { default as faq } from "./faq"; diff --git a/src/redux/actions/userFavorite.js b/src/redux/actions/userFavorite.js new file mode 100644 index 0000000..fb140d1 --- /dev/null +++ b/src/redux/actions/userFavorite.js @@ -0,0 +1,29 @@ +import proxy from "../proxy"; + +const userFavorite = { + list: + (data = {}) => + async (dispatch) => { + await proxy.get("userFavorite/list", data, { dispatch }); + }, + update: + (data = {}, data2 = {}) => + async (dispatch) => { + await proxy.put("userFavorite/update", data); + await proxy.get("userFavorite/list", data2, { dispatch }); + }, + add: + (data = {}, data2 = {}, data3 = {}) => + async (dispatch) => { + await proxy.post("userFavorite/add", data, { dispatch }); + await proxy.get("userFavorite/list", data2, { dispatch }); + }, + del: + (data = {}, data2 = {}) => + async (dispatch) => { + await proxy.delete("userFavorite/delete", data); + await proxy.get("userFavorite/list", data2, { dispatch }); + }, +}; + +export default userFavorite; \ No newline at end of file diff --git a/src/redux/reducers/index.js b/src/redux/reducers/index.js index 8ee8dc8..54e44db 100644 --- a/src/redux/reducers/index.js +++ b/src/redux/reducers/index.js @@ -6,6 +6,7 @@ export { default as blog } from "./blog"; export { default as product } from "./product"; export { default as content } from "./content"; export { default as userAddress } from "./userAddress"; +export { default as userFavorite } from "./userFavorite"; export { default as transport } from "./transport"; export { default as faq } from "./faq"; export { default as file } from "./file"; diff --git a/src/redux/reducers/userFavorite.js b/src/redux/reducers/userFavorite.js new file mode 100644 index 0000000..8ee19a9 --- /dev/null +++ b/src/redux/reducers/userFavorite.js @@ -0,0 +1,33 @@ +import {toast} from 'react-toastify'; + +const initialState = { + loading: false, + error: null, + list: [], +}; +export default function userAddress(state = initialState, action) { + let { type, data } = action; + switch (type) { + case "userAddress/list": + return { + ...state, + loading: false, + list: data, + error: null, + }; + case "userAddress/update": + return { ...state, loading: false, error: null }; + case "userAddress/add": + toast.success('به لیست علاقه‌مندی‌ها اضافه شد.'); + return { ...state, loading: false, error: null }; + case "userAddress/delete": + return { ...state, loading: false, error: null }; + case "userAddress/loading": + return { ...state, loading: true }; + case "userAddress/error": + toast.error(data.message); + return { ...state, loading: false, error: data.message }; + default: + return state; + } +} diff --git a/src/router.js b/src/router.js index 8252cd1..2d79785 100644 --- a/src/router.js +++ b/src/router.js @@ -31,6 +31,9 @@ import Blogs from "./views/Blogs"; import Blog from "./views/Blog"; import About from "./views/About"; import Dialog from "./components/Dialog"; +import Address from "./views/Address"; +import Favorites from "./views/Favorites"; +import Addresses from "./views/Dashboard/layouts/Mobile/ProfileAddress"; function Router({ isDark, isMobile, headerOptions, dialog }) { useEffect(() => { @@ -236,13 +239,13 @@ function Router({ isDark, isMobile, headerOptions, dialog }) { } /> } /> + + } + /> + + } + /> + + } + /> { setHeaderOptions(headerOptions); getArList(); - }, []); return ( -
+
{arList.length > 0 && arList.map((book, index) => )}
diff --git a/src/views/AR/layouts/Book.js b/src/views/AR/layouts/Book.js index b20c6f0..87a9b65 100644 --- a/src/views/AR/layouts/Book.js +++ b/src/views/AR/layouts/Book.js @@ -5,17 +5,18 @@ const Book = ({ book }) => { - + {book.title} diff --git a/src/views/Address/index.js b/src/views/Address/index.js index cb5b1b8..bd37d55 100644 --- a/src/views/Address/index.js +++ b/src/views/Address/index.js @@ -32,6 +32,8 @@ export const Address = ({ profileFields, setProfile, user, + setHeaderOptions, + headerOptions, }) => { const [addressFields, setAddressFields] = useState({}); const [mapAddress, setMapAddress] = useState(null); @@ -40,6 +42,9 @@ export const Address = ({ if (province.length <= 1) { getProvince(); } + if(isMobile){ + setHeaderOptions(headerOptions); + } }, []); useEffect(() => { @@ -201,7 +206,7 @@ export const Address = ({ }; return (
{!profilePage && ( @@ -484,7 +489,7 @@ export const Address = ({ )}
- {isMobile && ( + {/* {isMobile && (
setPhase("deliveryForm")} />
- )} + )} */} ); }; @@ -526,6 +531,7 @@ const mapDispatchToProps = { setDialog: dialog.set, setProfileFields: user.setProfileFields, setProfile: user.setProfile, + setHeaderOptions : publicApi.setHeaderOptions }; export default connect(mapStateToProps, mapDispatchToProps)(Address); diff --git a/src/views/Dashboard/layouts/Mobile/List.js b/src/views/Dashboard/layouts/Mobile/List.js index 8cdb123..56bb530 100644 --- a/src/views/Dashboard/layouts/Mobile/List.js +++ b/src/views/Dashboard/layouts/Mobile/List.js @@ -16,7 +16,7 @@ const List = ({ mobile }) => { { icon: , name: "اطلاعات حساب کاربری", - link: "/CreateAddress", + link: "/editProfile", }, { icon: , @@ -36,12 +36,12 @@ const List = ({ mobile }) => { { icon: , name: "لیست علاقه‌مندی‌ها", - link: "/ProfileBookmark", + link: "/favorites", }, { icon: , name: "آدرس‌ها", - link: "/ProfileAddress", + link: "/addresses", }, ]; diff --git a/src/views/Dashboard/layouts/Mobile/ProfileAddress/index.js b/src/views/Dashboard/layouts/Mobile/ProfileAddress/index.js index da5ed4f..981e16c 100644 --- a/src/views/Dashboard/layouts/Mobile/ProfileAddress/index.js +++ b/src/views/Dashboard/layouts/Mobile/ProfileAddress/index.js @@ -1,35 +1,12 @@ -import { - View, - Text, - Pressable, - TouchableOpacity, - Appearance, - ActivityIndicator, - SafeAreaView, - ScrollView, - StyleSheet, - Platform, - Dimensions, - StatusBar, -} from "react-native"; import React from "react"; import { connect } from "react-redux"; -import { useNavigation } from "@react-navigation/native"; -import { userAddress, userFactor } from "../../../../redux/actions"; -import Svg, { G, Path } from "react-native-svg"; +import { userAddress, userFactor } from "../../../../../redux/actions"; +import { Link, useNavigate } from "react-router-dom"; //components -import Navbar from "../../../../components/Navbar"; -import CustomPressable from "../../../../components/Pressable"; -import Empty from "../../../../components/Empty"; - -//style -import tw from "tailwind-rn"; -import Colors from "../../../../constants/Colors"; -import fontSize from "../../../../constants/fontSize"; - -const { height, width } = Dimensions.get("window"); -const ios = Platform.OS === "ios"; +import Empty from "../../../../../components/Empty"; +import Button from "../../../../../components/Button"; +import FloatingButton from "../../../../../components/FloatingButton"; const ProfileAddress = ({ addresses, @@ -41,156 +18,81 @@ const ProfileAddress = ({ loading, closeBottomSheet, mobile, + isDark, }) => { - const colorScheme = Appearance.getColorScheme(); - const navigation = useNavigation(); - const [height, setHeight] = React.useState(Dimensions.get("window").height); + const navigation = useNavigate(); const Location = ({ address, active }) => { return ( - +
userAddressId === address?.id ? {} : update({ userAddressId: address.id, userId }) } > - +
{active && ( - - - +
+
+ آدرس انتخابی شما - - - فعال - - - - - - + فعال +
+ + + + - - - + + +
)} - - - +
+
+ {"آدرس:" + " " + address.address} - - + + {"نام:" + " " + address.firstName + " " + address.lastName} - - + + {"کد پستی:" + " " + address.postalCode} - - + + {"شماره تماس:" + " " + address.cellphone} - - + +
{!active && ( - - - - + + + - - + + )} - - - {}} +
+
+
); }; @@ -200,84 +102,28 @@ const ProfileAddress = ({ }, []); return ( - - +
{addresses.length > 0 ? ( - setHeight(Dimensions.get("window").height)} - > - - - {addresses.map((address, index) => ( - - ))} - - - +
+
+ {addresses.map((address, index) => ( + + ))} +
+
) : ( )} - - navigation.push("CreateAddress")} - > - - یک آدرس جدید اضافه کنید - - - + - - - - + navigation("/createAddress")} + position={{ bottom: 100, right: 16 }} + size={16} + /> +
); }; @@ -287,6 +133,7 @@ const mapStateToProps = (state) => ({ loading: state.userFactor.loading, addresses: state.userAddress.list, mobile: state.publicApi.mobile, + isDark: state.publicApi.isDark, }); const mapDispatchToProps = { @@ -296,16 +143,3 @@ const mapDispatchToProps = { }; export default connect(mapStateToProps, mapDispatchToProps)(ProfileAddress); - -const styles = StyleSheet.create({ - contentContainerStyle: { - paddingBottom: 100, - position: "relative", - }, - container: { - backgroundColor: "white", - flexDirection: "column", - paddingVertical: 0, - paddingHorizontal: 0, - }, -}); diff --git a/src/views/Favorites/index.js b/src/views/Favorites/index.js index 845d1b3..5d2a774 100644 --- a/src/views/Favorites/index.js +++ b/src/views/Favorites/index.js @@ -1,28 +1,24 @@ import React from "react"; import { connect } from "react-redux"; +import { publicApi, userFavorite } from "../../redux/actions"; + //assets import bookImage from "./book.svg"; import bookmarkIcon from "./bookmark.svg"; -const Favorites = ({ bookmarkList, isMobile }) => { - const Bookmark = ({ bookmark }) => { - return ( -
-
-
- -
- {bookmark.name} - {bookmark.grade} -
-
- -
-
- ); - }; +const Favorites = ({ + bookmarkList, + isMobile, + headerOptions, + setHeaderOptions, + getList, +}) => { + React.useEffect(() => { + if (isMobile) { + setHeaderOptions(headerOptions); + } + getList(); + }, []); return (
@@ -33,12 +29,37 @@ const Favorites = ({ bookmarkList, isMobile }) => { ); }; +const Bookmark = ({ bookmark }) => { + return ( +
+
+
+ +
+ {bookmark.name} + + {bookmark.grade} + +
+
+ +
+
+ ); +}; + const mapStateToProps = (state) => ({ loading: state.userFactor.loading, isMobile: state.publicApi.isMobile, + bookmarkList: state.userFavorite.list, }); -const mapDispatchToProps = {}; +const mapDispatchToProps = { + setHeaderOptions: publicApi.setHeaderOptions, + getList: userFavorite.list, +}; export default connect(mapStateToProps, mapDispatchToProps)(Favorites); diff --git a/src/views/Orders/index.js b/src/views/Orders/index.js index 9030453..eeed277 100644 --- a/src/views/Orders/index.js +++ b/src/views/Orders/index.js @@ -1,10 +1,15 @@ import React from "react"; import Order from "./components/Order"; import { connect } from "react-redux"; +import {publicApi} from '../../redux/actions'; + //assets import bookImage from "../../assets/images/book-mini.svg"; -function Orders({ orders }) { +function Orders({ orders, headerOptions, setHeaderOptions }) { + React.useEffect(() => { + setHeaderOptions(headerOptions); + },[]); return (
{orders.map((order, index) => ( @@ -14,9 +19,13 @@ function Orders({ orders }) { ); } -const mapStateToProps = () => ({}); +const mapStateToProps = (state) => ({ + isMobile : state.publicApi.isMobile, + +}); const mapDispatchToProps = { + setHeaderOptions: publicApi.setHeaderOptions, }; export default connect(mapStateToProps, mapDispatchToProps)(Orders);