Skip to content

Commit 3ec316b

Browse files
committed
fix: fixing bug in court page description redirection
1 parent 1d329bd commit 3ec316b

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

web/src/pages/Courts/CourtDetails/Description.tsx

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useEffect } from "react";
22
import styled from "styled-components";
33

44
import ReactMarkdown from "react-markdown";
@@ -70,7 +70,12 @@ const Description: React.FC = () => {
7070
const handleTabChange = (index: number) => {
7171
navigate(TABS[index].path);
7272
};
73-
console.log({ policy, currentTab, currentPathName });
73+
74+
useEffect(() => {
75+
if (currentPathName && !filteredTabs.map((t) => t.path).includes(currentPathName) && filteredTabs.length > 0) {
76+
navigate(filteredTabs[0].path, { replace: true });
77+
}
78+
}, [policy, currentPathName, filteredTabs, navigate]);
7479

7580
return (
7681
<>
@@ -81,16 +86,7 @@ const Description: React.FC = () => {
8186
<Routes>
8287
<Route path="purpose" element={formatMarkdown(policy?.description)} />
8388
<Route path="skills" element={formatMarkdown(policy?.requiredSkills)} />
84-
<Route
85-
path="policy"
86-
element={
87-
policy?.summary.trim() ? (
88-
formatMarkdown(policy.summary)
89-
) : (
90-
<Navigate to={filteredTabs.length > 0 ? filteredTabs[0].path : ""} replace />
91-
)
92-
}
93-
/>
89+
<Route path="policy" element={formatMarkdown(policy?.summary)} />
9490
<Route path="*" element={<Navigate to={filteredTabs.length > 0 ? filteredTabs[0].path : ""} replace />} />
9591
</Routes>
9692
</TextContainer>

0 commit comments

Comments
 (0)