Skip to content

Commit

Permalink
chore: Remove old feedback submission logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Feb 16, 2024
1 parent 4f360b0 commit f9771c0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Card from "@planx/components/shared/Preview/Card";
import QuestionHeader from "@planx/components/shared/Preview/QuestionHeader";
import type { PublicProps } from "@planx/components/ui";
import DelayedLoadingIndicator from "components/DelayedLoadingIndicator";
import { useFormik } from "formik";
import capitalize from "lodash/capitalize";
import { useStore } from "pages/FlowEditor/lib/store";
import { handleSubmit } from "pages/Preview/Node";
Expand Down Expand Up @@ -131,8 +130,7 @@ function Component(props: Props) {
fn={props.fn}
constraints={constraints}
metadata={metadata}
previousFeedback={props.previouslySubmittedData?.feedback}
handleSubmit={(values: { feedback?: string }) => {
handleSubmit={() => {
const _constraints: Array<
EnhancedGISResponse | GISResponse["constraints"]
> = [];
Expand Down Expand Up @@ -170,7 +168,6 @@ function Component(props: Props) {
};

props.handleSubmit?.({
...values,
data: passportData,
});
}}
Expand All @@ -195,31 +192,15 @@ export type PlanningConstraintsContentProps = {
fn: string;
constraints: GISResponse["constraints"];
metadata: GISResponse["metadata"];
handleSubmit: (values: { feedback: string }) => void;
handleSubmit: () => void;
refreshConstraints: () => void;
previousFeedback?: string;
};

export function PlanningConstraintsContent(
props: PlanningConstraintsContentProps,
) {
const {
title,
description,
constraints,
metadata,
handleSubmit,
refreshConstraints,
previousFeedback,
} = props;
const formik = useFormik({
initialValues: {
feedback: previousFeedback || "",
},
onSubmit: (values) => {
handleSubmit?.(values);
},
});
const { title, description, constraints, metadata, refreshConstraints } =
props;
const error = constraints.error || undefined;
const showError = error || !Object.values(constraints)?.length;

Expand All @@ -232,7 +213,7 @@ export function PlanningConstraintsContent(
);

return (
<Card handleSubmit={formik.handleSubmit} isValid>
<Card handleSubmit={props.handleSubmit}>
<QuestionHeader title={title} description={description} />
{showError && (
<ConstraintsFetchError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ test("renders correctly when property override is enabled", async () => {
expect(screen.getByText("About the property")).toBeInTheDocument();
expect(screen.getByText("Property type")).toBeInTheDocument();

expect(screen.getByText("Change")).toBeInTheDocument();
expect(screen.queryByText("Report an inaccuracy")).not.toBeInTheDocument();

await user.click(screen.getByTestId("continue-button"));
expect(handleSubmit).toHaveBeenCalledTimes(1);
});
Expand All @@ -67,26 +64,7 @@ test("renders correctly when property override is toggled off", async () => {
expect(screen.getByText("Property type")).toBeInTheDocument();

expect(screen.queryByText("Change")).not.toBeInTheDocument();
expect(screen.getByText("Report an inaccuracy")).toBeInTheDocument();

await user.click(screen.getByTestId("continue-button"));
expect(handleSubmit).toHaveBeenCalledTimes(1);
});

test("retains previously submitted feedback when going back", async () => {
const { user } = setup(
<MockedProvider>
<Presentational
{...defaultPresentationalProps}
showPropertyTypeOverride={false}
previousFeedback="My property type is wrong"
/>
</MockedProvider>,
);

expect(screen.getByText("Report an inaccuracy")).toBeInTheDocument();

// expand the feedback input
await user.click(screen.getByText("Report an inaccuracy"));
expect(screen.getByText("My property type is wrong")).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Card from "@planx/components/shared/Preview/Card";
import QuestionHeader from "@planx/components/shared/Preview/QuestionHeader";
import type { PublicProps } from "@planx/components/ui";
import { Feature } from "@turf/helpers";
import { useFormik } from "formik";
import { publicClient } from "lib/graphql";
import find from "lodash/find";
import { useAnalyticsTracking } from "pages/FlowEditor/lib/analyticsProvider";
Expand Down Expand Up @@ -45,7 +44,6 @@ function Component(props: PublicProps<PropertyInformation>) {
}
titleBoundary={passport.data?.["property.boundary.title"]}
blpuCodes={blpuCodes}
previousFeedback={props.previouslySubmittedData?.feedback}
overrideAnswer={overrideAnswer}
handleSubmit={props.handleSubmit}
/>
Expand Down Expand Up @@ -77,7 +75,6 @@ export interface PresentationalProps {
localAuthorityDistrict?: string[];
titleBoundary?: Feature;
blpuCodes?: any;
previousFeedback?: string;
overrideAnswer: (fn: string) => void;
handleSubmit?: handleSubmit;
}
Expand All @@ -103,20 +100,10 @@ export function Presentational(props: PresentationalProps) {
localAuthorityDistrict,
titleBoundary,
blpuCodes,
previousFeedback,
overrideAnswer,
handleSubmit,
} = props;
const teamName = useStore((state) => state.teamName);
const formik = useFormik({
initialValues: {
feedback: previousFeedback || "",
},
onSubmit: (values) => {
handleSubmit?.(values);
},
});

const propertyDetails: PropertyDetail[] = [
{
heading: "Address",
Expand All @@ -142,7 +129,7 @@ export function Presentational(props: PresentationalProps) {
];

return (
<Card handleSubmit={formik.handleSubmit} isValid>
<Card handleSubmit={handleSubmit}>
<QuestionHeader title={title} description={description} />
<MapContainer>
<p style={visuallyHidden}>
Expand Down
31 changes: 2 additions & 29 deletions editor.planx.uk/src/@planx/components/Result/Public/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import Typography from "@mui/material/Typography";
import Card from "@planx/components/shared/Preview/Card";
import SimpleExpand from "@planx/components/shared/Preview/SimpleExpand";
import { WarningContainer } from "@planx/components/shared/Preview/WarningContainer";
import { useFormik } from "formik";
import { Store, useStore } from "pages/FlowEditor/lib/store";
import type { handleSubmit } from "pages/Preview/Node";
import React, { useEffect, useState } from "react";
import React from "react";
import { FONT_WEIGHT_SEMI_BOLD } from "theme";
import type { Node, TextContent } from "types";

Expand Down Expand Up @@ -87,50 +86,24 @@ const Responses = ({

const Result: React.FC<Props> = ({
allowChanges = false,
handleSubmit,
headingColor,
headingTitle = "",
description = "",
reasonsTitle = "",
responses,
disclaimer,
previouslySubmittedData,
}) => {
const formik = useFormik({
initialValues: {
feedback: previouslySubmittedData?.feedback || "",
},
onSubmit: (values, { resetForm }) => {
if (values.feedback) {
resetForm();
}
handleSubmit?.({ feedback: values.feedback });
},
});
const visibleResponses = responses.filter((r) => !r.hidden);
const hiddenResponses = responses.filter((r) => r.hidden);

const [showSubmitButton, setShowSubmitButton] = useState<boolean>(
Boolean(handleSubmit),
);

useEffect(() => {
if (handleSubmit) return;

setShowSubmitButton(formik.values.feedback.length > 0);
}, [formik.values.feedback]);

return (
<Box width="100%" display="flex" flexDirection="column" alignItems="center">
<ResultSummary
heading={headingTitle}
description={description}
color={headingColor}
/>
<Card
handleSubmit={showSubmitButton ? formik.handleSubmit : undefined}
isValid
>
<Card>
<Box mt={4} mb={3}>
<Typography variant="h2" gutterBottom>
{reasonsTitle}
Expand Down

0 comments on commit f9771c0

Please sign in to comment.