From 3f60d432181866a8ee1709f3f84c66537427e13b Mon Sep 17 00:00:00 2001 From: monocle Date: Mon, 9 Jan 2023 12:14:17 -0800 Subject: [PATCH] Fix routing to demo bug. Closes #1472 * Separate Demo from RecordSearch * Update DemoInfo: - Remove stop demo state management - Use Link instead of button for OECI log in * Add stop demo state management to RecordSearch * Use history.replace instead of history.push in checkOeciRedirect(). This allows browser back button to work properly. --- src/frontend/src/components/App/index.tsx | 7 +- .../{RecordSearch => }/Demo/DemoInfo.tsx | 81 ++++++++++--------- src/frontend/src/components/Demo/index.tsx | 42 ++++++++++ .../RecordSearch/Assumptions/index.tsx | 32 ++++++++ .../components/RecordSearch/Demo/index.tsx | 19 ----- .../src/components/RecordSearch/index.tsx | 65 ++++----------- src/frontend/src/service/cookie-service.ts | 2 +- 7 files changed, 138 insertions(+), 110 deletions(-) rename src/frontend/src/components/{RecordSearch => }/Demo/DemoInfo.tsx (74%) create mode 100644 src/frontend/src/components/Demo/index.tsx create mode 100644 src/frontend/src/components/RecordSearch/Assumptions/index.tsx delete mode 100644 src/frontend/src/components/RecordSearch/Demo/index.tsx diff --git a/src/frontend/src/components/App/index.tsx b/src/frontend/src/components/App/index.tsx index 18976b0ed..00146413b 100644 --- a/src/frontend/src/components/App/index.tsx +++ b/src/frontend/src/components/App/index.tsx @@ -5,7 +5,7 @@ import history from "../../service/history"; import Footer from "../Footer"; import Header from "../Header"; import RecordSearch from "../RecordSearch"; -import Demo from "../RecordSearch/Demo"; +import Demo from "../Demo"; import OeciLogin from "../OeciLogin"; import Landing from "../Landing"; import Manual from "../Manual"; @@ -36,7 +36,10 @@ class App extends React.Component { - + diff --git a/src/frontend/src/components/RecordSearch/Demo/DemoInfo.tsx b/src/frontend/src/components/Demo/DemoInfo.tsx similarity index 74% rename from src/frontend/src/components/RecordSearch/Demo/DemoInfo.tsx rename to src/frontend/src/components/Demo/DemoInfo.tsx index 4ef09c24b..16e314796 100644 --- a/src/frontend/src/components/RecordSearch/Demo/DemoInfo.tsx +++ b/src/frontend/src/components/Demo/DemoInfo.tsx @@ -1,19 +1,13 @@ import React from "react"; import { Link } from "react-router-dom"; -import { connect } from "react-redux"; -import { stopDemo } from "../../../redux/search/actions"; -import history from "../../../service/history"; -import store from "../../../redux/store"; -interface Props { - stopDemo: Function; -} -class DemoInfo extends React.Component { - toOeci = () => { - store.dispatch(this.props.stopDemo()); - history.push("/oeci"); - }; - formattedInfo = (firstName: string, lastName: string, description: string[], dateOfBirth: string) => { +class DemoInfo extends React.Component { + formattedInfo = ( + firstName: string, + lastName: string, + description: string[], + dateOfBirth: string + ) => { return (

@@ -25,19 +19,19 @@ class DemoInfo extends React.Component {

Last Name
{lastName}
- { - dateOfBirth && ( -
-
Date of Birth
-
{dateOfBirth}
-
- ) - } + {dateOfBirth && ( +
+
Date of Birth
+
{dateOfBirth}
+
+ )}

- {description.map((line: string) =>

{line}

)} + {description.map((line: string) => ( +

{line}

+ ))} ); - } + }; render() { const examplesData = [ @@ -45,7 +39,9 @@ class DemoInfo extends React.Component { name: "Single Conviction", firstName: "Single", lastName: "Conviction", - description: ["As a simple example, if a person's record has only a single convicted charge, it is eligible after three years."] + description: [ + "As a simple example, if a person's record has only a single convicted charge, it is eligible after three years.", + ], }, { name: "Multiple Charges", @@ -53,8 +49,8 @@ class DemoInfo extends React.Component { lastName: "Charges", description: [ "If a record has more than one case, the time restrictions quickly get more complex, as this example demonstrates. Eligibility dates depend on whether dismissals are on the same or a different case as a conviction. Searching OECI will also reveal traffic violations, which are always ineligible.", - "This record also includes a case with an outstanding balance due for fines, which is indicated in both the record summary and on the case itself." - ] + "This record also includes a case with an outstanding balance due for fines, which is indicated in both the record summary and on the case itself.", + ], }, { name: "John Common", @@ -62,7 +58,7 @@ class DemoInfo extends React.Component { lastName: "Common", description: [ "Searching for a common name will often bring up records that belong to different individuals, leading to an incorrect analysis for the set of resulting cases. Another source of confusion is that each case may or may not incude a birth year, as well as middle name or initial.", - "It is thus always recommended to provide a birth date in the search. You can also use the Enable Editing feature to remove cases or charges from the resulting record, and these charges will be excluded in the eligibility analysis." + "It is thus always recommended to provide a birth date in the search. You can also use the Enable Editing feature to remove cases or charges from the resulting record, and these charges will be excluded in the eligibility analysis.", ], }, { @@ -70,20 +66,19 @@ class DemoInfo extends React.Component { firstName: "John", lastName: "Common", description: [ - "Most charges that are eligible are also subject to the same set of time restrictions. There are some exceptions to this, notably Class B Felonies, and possession of less than an ounce of marijuana." + "Most charges that are eligible are also subject to the same set of time restrictions. There are some exceptions to this, notably Class B Felonies, and possession of less than an ounce of marijuana.", ], - dateOfBirth: "1/1/1970" + dateOfBirth: "1/1/1970", }, { name: "John Common – Needs More Analysis", firstName: "John", lastName: "Common", description: [ - "Some charges cannot be evaluated for eligibility until the user provides some follow-up information about the charge. RecordSponge deals with this ambiguity by showing the different possible outcomes for eligibility, and by asking the user for the required extra information in order to determine an exact analysis." + "Some charges cannot be evaluated for eligibility until the user provides some follow-up information about the charge. RecordSponge deals with this ambiguity by showing the different possible outcomes for eligibility, and by asking the user for the required extra information in order to determine an exact analysis.", ], - dateOfBirth: "2/2/1985" + dateOfBirth: "2/2/1985", }, - ]; return (
@@ -117,19 +112,26 @@ class DemoInfo extends React.Component {

Or,{" "} - + .

{examplesData.map((e: any) => (
-

- {e.name} -

+

{e.name}

- {this.formattedInfo(e.firstName, e.lastName, e.description, e.dateOfBirth)} + {this.formattedInfo( + e.firstName, + e.lastName, + e.description, + e.dateOfBirth + )}
))} @@ -139,4 +141,5 @@ class DemoInfo extends React.Component { ); } } -export default connect(() => {}, { stopDemo })(DemoInfo); + +export default DemoInfo; diff --git a/src/frontend/src/components/Demo/index.tsx b/src/frontend/src/components/Demo/index.tsx new file mode 100644 index 000000000..e14933108 --- /dev/null +++ b/src/frontend/src/components/Demo/index.tsx @@ -0,0 +1,42 @@ +import React from "react"; +import { connect } from "react-redux"; +import { RecordData } from "../RecordSearch/Record/types"; +import store, { AppState } from "../../redux/store"; +import { startDemo } from "../../redux/search/actions"; +import DemoInfo from "./DemoInfo"; +import SearchPanel from "../RecordSearch/SearchPanel"; +import Status from "../RecordSearch/Status"; +import Record from "../RecordSearch/Record"; +import Assumptions from "../RecordSearch/Assumptions"; + +interface Props { + record?: RecordData; + startDemo: Function; +} + +class Demo extends React.Component { + componentDidMount() { + document.title = "Demo - RecordSponge"; + store.dispatch(this.props.startDemo()); + } + + render() { + return ( +
+ + + + + +
+ ); + } +} + +const mapStateToProps = (state: AppState) => { + return { + record: state.search.record, + }; +}; + +export default connect(mapStateToProps, { startDemo })(Demo); diff --git a/src/frontend/src/components/RecordSearch/Assumptions/index.tsx b/src/frontend/src/components/RecordSearch/Assumptions/index.tsx new file mode 100644 index 000000000..50c843299 --- /dev/null +++ b/src/frontend/src/components/RecordSearch/Assumptions/index.tsx @@ -0,0 +1,32 @@ +import React from "react"; +import { HashLink as Link } from "react-router-hash-link"; + +export default function Assumptions() { + return ( +
+

Assumptions

+

+ We are only able to access your public Oregon records. +

+

+ Your analysis may be different if you have had cases which were: +

+
    +
  • Previously expunged
  • +
  • + From States besides Oregon within the last ten years +
  • +
  • From Federal Court within the last ten years
  • +
  • + From local District Courts, e.g. Medford Municipal Court (not Jackson + County Circuit Court) from within the last ten years +
  • +
+

+ + Learn more in the Manual + +

+
+ ); +} diff --git a/src/frontend/src/components/RecordSearch/Demo/index.tsx b/src/frontend/src/components/RecordSearch/Demo/index.tsx deleted file mode 100644 index 5fa167c4f..000000000 --- a/src/frontend/src/components/RecordSearch/Demo/index.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import React from "react"; -import RecordSearch from "../../RecordSearch"; -import { startDemo } from "../../../redux/search/actions"; -import store from "../../../redux/store"; -import { connect } from "react-redux"; - -interface Props { - startDemo: Function; -} -class Demo extends React.Component { - componentDidMount() { - store.dispatch(this.props.startDemo()); - } - render() { - return ; - } -} - -export default connect(() => {}, { startDemo })(Demo); diff --git a/src/frontend/src/components/RecordSearch/index.tsx b/src/frontend/src/components/RecordSearch/index.tsx index f2fc4f957..633d02dfb 100644 --- a/src/frontend/src/components/RecordSearch/index.tsx +++ b/src/frontend/src/components/RecordSearch/index.tsx @@ -1,66 +1,34 @@ -import React, { Component } from "react"; +import React from "react"; import { connect } from "react-redux"; -import { AppState } from "../../redux/store"; import { RecordData } from "./Record/types"; +import store, { AppState } from "../../redux/store"; +import { stopDemo } from "../../redux/search/actions"; +import { checkOeciRedirect } from "../../service/cookie-service"; import SearchPanel from "./SearchPanel"; import Record from "./Record"; import Status from "./Status"; -import DemoInfo from "./Demo/DemoInfo"; -import { checkOeciRedirect } from "../../service/cookie-service"; -import { HashLink as Link } from "react-router-hash-link"; +import Assumptions from "./Assumptions"; interface Props { - demo: boolean; record?: RecordData; + stopDemo: Function; } -class RecordSearch extends Component { - +class RecordSearch extends React.Component { componentDidMount() { - this.props.demo || checkOeciRedirect(); + checkOeciRedirect(); document.title = "Search Records - RecordSponge"; + store.dispatch(this.props.stopDemo()); } render() { return ( - <> -
- {this.props.demo && } - - - -
-

Assumptions

-

- We are only able to access your public Oregon records. -

-

- Your analysis may be different if you have had cases which were: -

-
    -
  • Previously expunged
  • -
  • - From States besides Oregon within the last ten years -
  • -
  • - From Federal Court within the last ten years -
  • -
  • - From local District Courts, e.g. Medford Municipal Court (not - Jackson County Circuit Court) from within the last ten years -
  • -
-

- - Learn more in the Manual - -

-
-
- +
+ + + + +
); } } @@ -68,8 +36,7 @@ class RecordSearch extends Component { const mapStateToProps = (state: AppState) => { return { record: state.search.record, - demo: state.search.demo, }; }; -export default connect(mapStateToProps, {})(RecordSearch); +export default connect(mapStateToProps, { stopDemo })(RecordSearch); diff --git a/src/frontend/src/service/cookie-service.ts b/src/frontend/src/service/cookie-service.ts index 30b03ac84..f1c14a85f 100644 --- a/src/frontend/src/service/cookie-service.ts +++ b/src/frontend/src/service/cookie-service.ts @@ -35,6 +35,6 @@ export function isAdmin() { export function checkOeciRedirect() { if (!hasOeciToken()) { - history.push("/oeci"); + history.replace("/oeci"); } }