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 26f9a3f commit 92c150d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +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 { submitFeedback } from "lib/feedback";
import capitalize from "lodash/capitalize";
import { useStore } from "pages/FlowEditor/lib/store";
import { handleSubmit } from "pages/Preview/Node";
Expand Down Expand Up @@ -132,7 +130,6 @@ function Component(props: Props) {
fn={props.fn}
constraints={constraints}
metadata={metadata}
previousFeedback={props.previouslySubmittedData?.feedback}
handleSubmit={(values: { feedback?: string }) => {
const _constraints: Array<
EnhancedGISResponse | GISResponse["constraints"]
Expand Down Expand Up @@ -198,36 +195,13 @@ export type PlanningConstraintsContentProps = {
metadata: GISResponse["metadata"];
handleSubmit: (values: { feedback: string }) => 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) => {
if (values.feedback) {
submitFeedback(
values.feedback,
"Inaccurate planning constraints",
constraints,
);
}
handleSubmit?.(values);
},
});
const { title, description, constraints, metadata, refreshConstraints } =
props;
const error = constraints.error || undefined;
const showError = error || !Object.values(constraints)?.length;

Expand All @@ -240,7 +214,7 @@ export function PlanningConstraintsContent(
);

return (
<Card handleSubmit={formik.handleSubmit} isValid>
<Card>
<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,8 +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 { submitFeedback } from "lib/feedback";
import { publicClient } from "lib/graphql";
import find from "lodash/find";
import { useAnalyticsTracking } from "pages/FlowEditor/lib/analyticsProvider";
Expand Down Expand Up @@ -46,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 @@ -78,7 +75,6 @@ export interface PresentationalProps {
localAuthorityDistrict?: string[];
titleBoundary?: Feature;
blpuCodes?: any;
previousFeedback?: string;
overrideAnswer: (fn: string) => void;
handleSubmit?: handleSubmit;
}
Expand All @@ -104,26 +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) => {
if (values.feedback) {
submitFeedback(
values.feedback,
"Inaccurate property details",
propertyDetails,
);
}
handleSubmit?.(values);
},
});

const propertyDetails: PropertyDetail[] = [
{
Expand All @@ -150,7 +130,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
35 changes: 2 additions & 33 deletions editor.planx.uk/src/@planx/components/Result/Public/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +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 { submitFeedback } from "lib/feedback";
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 @@ -88,53 +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) {
submitFeedback(values.feedback, "Inaccurate Result", {
responses: responses,
});
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
24 changes: 0 additions & 24 deletions editor.planx.uk/src/lib/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,6 @@ import { Store, useStore } from "pages/FlowEditor/lib/store";

import { publicClient } from "./graphql";

export const submitFeedback = (
text: string,
reason: string,
componentMetadata?: { [key: string]: any },
) => {
const standardMetadata = getFeedbackMetadata();
fetch("https://api.feedback.fish/feedback", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
projectId: process.env.REACT_APP_FEEDBACK_FISH_ID,
text,
reason,
// FeedbackFish requires that Record<string, string> be passed as metadata
metadata: {
...standardMetadata,
"component-metadata": JSON.stringify(componentMetadata),
},
}),
}).catch((err) => console.error(err));
};

export const getFeedbackMetadata = (): Record<string, string> => {
const { currentCard, computePassport, breadcrumbs } = useStore.getState();

Expand Down

0 comments on commit 92c150d

Please sign in to comment.