Skip to content

Commit 681f47a

Browse files
authored
Merge pull request #66 from iranpsc/fix/url
refactor: migrate modals, tabs, and nested tabs to URL-based navigation
2 parents c76e4e1 + 716bfa4 commit 681f47a

72 files changed

Lines changed: 1248 additions & 1154 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/components/Education/Header.jsx

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import { IoIosClose } from "react-icons/io";
22
import { TbMinimize } from "react-icons/tb";
33
import styled from "styled-components";
4-
import { getFieldTranslationByNames } from "../../services/Utility";
54
import { ExitIcon } from "../Icons/IconsHeader";
6-
import {
7-
getTitleTranslation,
8-
getTitleFromHref,
9-
translateLocationPage,
10-
} from "../../services/TitleManager";
115
import { useLocation } from "react-router-dom";
12-
import { useState, useEffect } from "react";
6+
import { useEffect, useState } from "react";
7+
import getModalHeaderFromPrevious from "../../services/TitleManager";
8+
139
const Div = styled.div`
1410
position: relative;
1511
display: flex;
@@ -23,10 +19,10 @@ const Div = styled.div`
2319
cursor: pointer;
2420
}
2521
`;
22+
2623
const HeaderWrapper = styled.div`
2724
display: flex;
2825
align-items: center;
29-
3026
width: 100%;
3127
justify-content: space-between;
3228
@@ -47,7 +43,6 @@ const Text = styled.h2`
4743
const Icons = styled.div`
4844
display: flex;
4945
align-items: center;
50-
justify-content: space-between;
5146
gap: 10px;
5247
svg {
5348
color: ${(props) => props.theme.colors.newColors.otherColors.iconText};
@@ -63,30 +58,29 @@ const Icons = styled.div`
6358

6459
const Header = ({ show, setOpenEducation, setSize }) => {
6560
const location = useLocation();
66-
const lastPart = getTitleFromHref(location.pathname);
61+
const [title, setTitle] = useState("");
6762

68-
const [title, setTitle] = useState(getFieldTranslationByNames("1455"));
6963
useEffect(() => {
70-
const translated = translateLocationPage(location.state?.locationPage);
64+
const basePath = location.state?.from || location.pathname;
7165

72-
if (translated) {
73-
setTitle(translated);
74-
} else {
75-
setTitle(getTitleTranslation(lastPart));
76-
}
77-
}, [location.state?.locationPage, lastPart]);
66+
const { title } = getModalHeaderFromPrevious(basePath);
67+
68+
setTitle(title);
69+
}, [location.pathname, location.state]);
7870

79-
const handleMinimizeClick = (event) => {
80-
event.stopPropagation();
71+
const handleMinimizeClick = (e) => {
72+
e.stopPropagation();
8173
setSize(true);
8274
};
8375

84-
const handleCloseClick = (event) => {
76+
const handleCloseClick = () => {
8577
setOpenEducation(false);
8678
};
79+
8780
return (
8881
<HeaderWrapper show={show}>
8982
<Text>{title}</Text>
83+
9084
<Icons>
9185
<Div onClick={handleMinimizeClick}>
9286
<TbMinimize style={{ color: "#949494" }} />

src/components/Header/Header.jsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ExitIcon } from "../Icons/IconsHeader";
66
import { BiExitFullscreen } from "react-icons/bi";
77
import { PiGearSixFill } from "react-icons/pi";
88
import { TiWarning } from "react-icons/ti";
9-
import Education from "../../components/Education/Education" ;
9+
import Education from "../../components/Education/Education";
1010
import useAdviserData from "../../services/Hooks/useAdviserData";
1111
import { useLocation, useNavigate } from "react-router-dom";
1212
import { useSelectedEnvironment } from "../../services/reducers/SelectedEnvironmentContext";
@@ -38,7 +38,6 @@ const ReportIcon = styled(Report)`
3838
cursor: pointer;
3939
`;
4040

41-
4241
const IconWrapper = styled.div`
4342
width: 11px;
4443
height: 11px;
@@ -72,9 +71,9 @@ const HeaderWrapper = styled.div`
7271
margin-bottom: 30px;
7372
margin-top: 10px;
7473
}
75-
74+
7675
@media (max-height: 500px) and (max-width: 1000px) {
77-
padding-bottom: 5px;
76+
padding-bottom: 5px;
7877
}
7978
`;
8079

@@ -135,16 +134,20 @@ const Header = ({
135134
const newStr = location.pathname.replace(/\/metaverse\//g, "") + "-";
136135
const locationPage = location?.state?.locationPage;
137136
const adviserData = useAdviserData(newStr, locationPage);
137+
138138
const handleReportClick = () => {
139-
navigation("/metaverse/report", {
139+
navigation("/metaverse/report/send", {
140140
state: {
141-
href: window.location.href.split("/").slice(3).join("/"),
141+
from: location.pathname,
142142
},
143143
});
144144
};
145+
145146
const handleExitClick = () => {
146147
if (handleExit) {
147-
navigation("/metaverse/")
148+
navigation(location.state?.background?.pathname || "/metaverse", {
149+
replace: true,
150+
});
148151
handleExit();
149152
return;
150153
}

src/components/ModalPosition/Styles.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ export const Container = styled(animated.div)`
2424
bottom: 0;
2525
padding: 15px 20px;
2626
z-index: 10;
27-
${(props) => (props.isPersian ? "left: 0;" : "right: 0;")}
27+
${(props) => (props.isPersian ? "left: 184px;" : "right: 184px;")}
2828
position: fixed;
2929
height: 100%;
30+
@media screen and (max-width: 1024px) {
31+
${(props) => (props.isPersian ? "left: 167px;" : "right: 167px;")}
32+
}
33+
@media screen and (max-width: 834px) {
34+
${(props) => (props.isPersian ? "left: 19%;" : "right: 19%;")}
35+
}
3036
`;
3137

3238
export const ContainerIcon = styled.div`

src/components/SidebarOptions.jsx

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import styled from "styled-components";
22
import { getFieldTranslationByNames } from "../services/Utility";
3-
3+
import { NavLink } from "react-router-dom";
4+
import { Label } from "./sidbar";
45
const Wrapper = styled.div`
56
max-width: 171px !important;
67
background-color: ${(props) =>
@@ -11,36 +12,27 @@ const Wrapper = styled.div`
1112
margin-top: 20px;
1213
`;
1314

14-
const Option = styled.h2`
15-
font-weight: 500;
16-
font-size: 18px;
17-
padding: 10px 20px;
18-
white-space: nowrap;
19-
cursor: pointer;
20-
color: ${(props) =>
21-
props.option
22-
? props.theme.colors.primary
23-
: props.theme.colors.newColors.shades.title};
24-
border-right: ${(props) =>
25-
props.option
26-
? `2px solid ${(props) =>
27-
props.theme.colors.newColors.otherColors.inputBorder}`
28-
: "2px solid transparent"};
29-
`;
30-
31-
const SidebarOptions = ({ option, setOption, seller }) => {
15+
const SidebarOptions = ({ seller }) => {
3216
return (
3317
<Wrapper>
34-
<Option option={option === true} onClick={() => setOption(true)}>
35-
{seller
36-
? getFieldTranslationByNames("517")
37-
: getFieldTranslationByNames("524")}
38-
</Option>
39-
<Option option={option === false} onClick={() => setOption(false)}>
40-
{seller
41-
? getFieldTranslationByNames("519")
42-
: getFieldTranslationByNames("525")}
43-
</Option>
18+
<NavLink to={seller ? "lowest" : "price"} replace end>
19+
{({ isActive }) => (
20+
<Label menu={isActive}>
21+
{seller
22+
? getFieldTranslationByNames("517")
23+
: getFieldTranslationByNames("524")}
24+
</Label>
25+
)}
26+
</NavLink>
27+
<NavLink to={seller ? "PriceDefine" : "suggest"} replace end>
28+
{({ isActive }) => (
29+
<Label menu={isActive}>
30+
{seller
31+
? getFieldTranslationByNames("519")
32+
: getFieldTranslationByNames("525")}
33+
</Label>
34+
)}
35+
</NavLink>
4436
</Wrapper>
4537
);
4638
};

src/layouts/map/3dModelMap/SatisfactionLunch.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, useContext, useMemo } from "react";
1+
import React, { useState, useEffect, useContext } from "react";
22
import ModalXs from "../../../components/Modal/ModalXs";
33
import InputNumber from "../../../components/Inputs/InputNumber";
44
import TextValueIcon from "../../../components/TextValue/TextValueIcon";
@@ -18,6 +18,7 @@ import {
1818
ToastError,
1919
ToastSuccess,
2020
} from "../../../services/Utility";
21+
import { useMapData } from "../../../services/reducers/mapContext";
2122

2223
const Icon = styled(WatchIcon)`
2324
stroke: ${(props) => props.theme.colors.primary};
@@ -41,6 +42,8 @@ const SatisfactionLunch = ({
4142
const initialSatisfaction =
4243
Wallet && Wallet.satisfaction ? parseFloat(Wallet.satisfaction) : 0;
4344
const [inputValue, setInputValue] = useState(initialSatisfaction.toString());
45+
const { buildings, addBuilding } = useMapData();
46+
4447
const [error, setError] = useState(false);
4548
const [formData, setFormData] = useState({
4649
activity_line: "",
@@ -74,7 +77,6 @@ const SatisfactionLunch = ({
7477

7578
const hourOfComplete =
7679
satisfaction > 0 && input > 0 ? (satisfaction * 288000) / input : 0;
77-
7880

7981
const dayOfComplete = hourOfComplete / 24;
8082

@@ -108,7 +110,8 @@ const SatisfactionLunch = ({
108110
HTTP_METHOD.POST,
109111
formData
110112
)
111-
.then(() => {
113+
.then((res) => {
114+
addBuilding(res.data.data.building_models[0])
112115
handelSubmitEnvironment();
113116
ToastSuccess(getFieldTranslationByNames("1606"));
114117
dispatch({

0 commit comments

Comments
 (0)