diff --git a/src/components/Select/index.js b/src/components/Select/index.js index 261a064..55a2d31 100644 --- a/src/components/Select/index.js +++ b/src/components/Select/index.js @@ -8,7 +8,8 @@ function Select({ borderColor, backgroundColor, onChange, - name, + name, + defaultValue, width = "w-1/2" }) { return ( @@ -18,6 +19,7 @@ function Select({ onInput.numberOnly(val)} - name="address" - onChange={(name, value) => setMapAddress(value)} - value={mapAddress} - align="text-right" - direction="rtl" - /> -
- setMapAddress(val)} /> -
-
-
- + +
- -
+ )} + +
val} name="firstName" - onChange={(name, value) => onChange(name, value)} - value={addressFields?.firstName} + onChange={(name, value) => + profilePage + ? setProfileFields({ ...profileFields, firstName: value }) + : onChange(name, value) + } + value={ + profilePage + ? profileFields.firstName || user.firstName + : addressFields?.firstName + } align="text-right" direction="rtl" /> @@ -233,12 +282,34 @@ export const Address = ({ label={"نام خانوادگی"} regex={(val) => val} name="lastName" - onChange={(name, value) => onChange(name, value)} - value={addressFields?.lastName} + onChange={(name, value) => + profilePage + ? setProfileFields({ ...profileFields, lastName: value }) + : onChange(name, value) + } + value={ + profilePage + ? profileFields.lastName || user.lastName + : addressFields?.lastName + } align="text-right" direction="rtl" />
+ {profilePage && ( + onInput.phonenumber(val)} + name="nationalId" + onChange={(name, value) => + setProfileFields({ ...profileFields, nationalId: value }) + } + value={profileFields.nationalId || user.nationalId} + align="text-right" + direction="ltr" + /> + )} {!isMobile && ( <>
@@ -254,10 +325,18 @@ export const Address = ({ onInput.numberOnly(val)} + regex={(val) => onInput.phonenumber(val)} name="cellphone" - onChange={(name, value) => onChange(name, value)} - value={addressFields?.cellphone} + value={ + profilePage + ? profileFields.cellphone || user.cellphone + : addressFields?.cellphone + } + onChange={(name, value) => + profilePage + ? setProfileFields({ ...profileFields, cellphone: value }) + : onChange(name, value) + } align="text-right" direction="ltr" maxLength={11} @@ -267,8 +346,16 @@ export const Address = ({ label={"شماره تلفن"} regex={(val) => onInput.numberOnly(val)} name="phone" - onChange={(name, value) => onChange(name, value)} - value={addressFields?.phone} + value={ + profilePage + ? profileFields.phone || user.phone + : addressFields?.phone + } + onChange={(name, value) => + profilePage + ? setProfileFields({ ...profileFields, phone: value }) + : onChange(name, value) + } align="text-right" direction="ltr" maxLength={11} @@ -289,10 +376,23 @@ export const Address = ({ onChange(name, value)} + defaultValue={ + profilePage + ? cities?.filter( + (city) => city?.id === profileFields.cityId + )[0]?.name || city[0] + : city[0] + } + onChange={(name, value) => + value === "شهر" + ? {} + : profilePage + ? setProfileFields({ ...profileFields, cityId: value }) + : onChange(name, value) + } width={isMobile ? "w-full" : "w-1/2"} backgroundColor={ - isDark ? "dark:bg-transparent dark:text-white" : "" + isDark ? "dark:bg-transparent dark:text-white" : "bg-white" } fill={isDark ? "fill-white" : "fill-gray-600"} /> @@ -326,33 +439,49 @@ export const Address = ({ label={"کد پستی"} regex={(val) => onInput.numberOnly(val)} name="postalCode" - onChange={(name, value) => onChange(name, value)} - value={addressFields?.postalCode} + value={ + profilePage + ? profileFields.postalCode || user.postalCode + : addressFields?.postalCode + } + onChange={(name, value) => + profilePage + ? setProfileFields({ ...profileFields, postalCode: value }) + : onChange(name, value) + } align="text-right" direction="ltr" maxLength={10} /> -
+
+ {!profilePage && ( + + )}
{isMobile && ( @@ -383,16 +512,20 @@ const mapStateToProps = (state) => ({ provinces: state.publicApi.provinces, cities: state.publicApi.cities, loading: state.userAddress.loading, + user: state.user.status, cityLoading: state.publicApi.loading, isMobile: state.publicApi.isMobile, isDark: state.publicApi.isDark, + profileFields: state.user.profileFields, }); const mapDispatchToProps = { getProvince: publicApi.getProvince, getCity: publicApi.getCity, createAddress: userAddress.add, - setDialog : dialog.set, + setDialog: dialog.set, + setProfileFields: user.setProfileFields, + setProfile: user.setProfile, }; export default connect(mapStateToProps, mapDispatchToProps)(Address); diff --git a/src/views/Dashboard/index.js b/src/views/Dashboard/index.js index 53c97fb..ef69802 100644 --- a/src/views/Dashboard/index.js +++ b/src/views/Dashboard/index.js @@ -7,11 +7,19 @@ import Sidebar from "./layouts/SidebarMenu"; import Main from "./layouts/Main"; export const Dashboard = ({ isMobile, headerOptions, setHeaderOptions }) => { + const [page, setPage] = useState( + localStorage?.getItem("dashboard") || "userItems" + ); + useEffect(() => { setHeaderOptions(headerOptions); - },[]); + }, []); + + useEffect(() => { + localStorage.setItem("dashboard", page); + }, [page]); + - const [page, setPage] = useState("userItems"); return isMobile ? (
diff --git a/src/views/Dashboard/layouts/Main/index.js b/src/views/Dashboard/layouts/Main/index.js index 3ae1d9b..2d468ee 100644 --- a/src/views/Dashboard/layouts/Main/index.js +++ b/src/views/Dashboard/layouts/Main/index.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useMemo } from "react"; import { connect } from "react-redux"; import { publicApi } from "../../../../redux/actions"; @@ -8,23 +8,27 @@ import MyBooks from "./MyBooks"; import Ticket from "../../../Contact/layouts/Ticket"; import Favorites from "../../../Favorites/index"; import Addresses from "./Addresses"; +import Address from "../../../Address"; + +const views = { + orders: , + mybooks: , + userItems: , + setTicket: ( +
+ +
+ ), + favorites : , + addresses : , + profile :
, +}; export const Main = ({ setHeaderOptions, page }) => { useEffect(() => { setHeaderOptions({ shown: true }); }, []); - const views = { - orders: , - mybooks: , - userItems: , - setTicket: ( -
- -
- ), - favorites : , - addresses : - }; + return (