Skip to content

Commit

Permalink
Replace flowslug to fix axe test
Browse files Browse the repository at this point in the history
  • Loading branch information
jamdelion committed Jan 29, 2025
1 parent d159f8b commit 2b600df
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Story = StoryObj<typeof meta>;
export const Basic = {
args: {
teamSlug: "barnet",
flowSlug: "Apply for prior permission",
flowInformation: {
status: "online",
description: "A long description of a service",
Expand Down
21 changes: 12 additions & 9 deletions editor.planx.uk/src/pages/FlowEditor/ReadMePage/ReadMePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Typography from "@mui/material/Typography";
import { TextInputType } from "@planx/components/TextInput/model";
import { useFormik } from "formik";
import { useToast } from "hooks/useToast";
import capitalize from "lodash/capitalize";
import React, { useState } from "react";
import FlowTag from "ui/editor/FlowTag/FlowTag";
import { FlowTagType, StatusVariant } from "ui/editor/FlowTag/types";
Expand All @@ -26,6 +27,7 @@ import { ReadMePageForm, ReadMePageProps } from "./types";
export const ReadMePage: React.FC<ReadMePageProps> = ({
flowInformation,
teamSlug,
flowSlug,
}) => {
const { status: flowStatus } = flowInformation;
const [
Expand Down Expand Up @@ -63,14 +65,14 @@ export const ReadMePage: React.FC<ReadMePageProps> = ({
onSubmit: async (values, { setSubmitting, setFieldError }) => {
try {
const updateFlowDescriptionPromise = updateFlowDescription(
values.serviceDescription
values.serviceDescription,
);
const updateFlowSummaryPromise = updateFlowSummary(
values.serviceSummary
values.serviceSummary,
);

const updateFlowLimitationsPromise = updateFlowLimitations(
values.serviceLimitations
values.serviceLimitations,
);

const [descriptionResult, summaryResult, limitationsResult] =
Expand All @@ -86,27 +88,27 @@ export const ReadMePage: React.FC<ReadMePageProps> = ({
if (!descriptionResult) {
setFieldError(
"serviceDescription",
"Unable to update the flow description. Please try again."
"Unable to update the flow description. Please try again.",
);
}
if (!summaryResult) {
setFieldError(
"serviceSummary",
"Unable to update the service summary. Please try again."
"Unable to update the service summary. Please try again.",
);
}
if (!limitationsResult) {
setFieldError(
"serviceLimitations",
"Unable to update the service limitations. Please try again."
"Unable to update the service limitations. Please try again.",
);
}
throw new Error("One or more updates failed");
}
} catch (error) {
console.error("Error updating descriptions:", error);
toast.error(
"An error occurred while updating descriptions. Please try again."
"An error occurred while updating descriptions. Please try again.",
);
} finally {
setSubmitting(false);
Expand All @@ -117,7 +119,7 @@ export const ReadMePage: React.FC<ReadMePageProps> = ({
validationSchema: object({
serviceSummary: string().max(
120,
"Service description must be 120 characters or less"
"Service description must be 120 characters or less",
),
}),
});
Expand All @@ -126,7 +128,8 @@ export const ReadMePage: React.FC<ReadMePageProps> = ({
<Container maxWidth="formWrap">
<SettingsSection>
<Typography variant="h2" component="h3" gutterBottom>
{flowName}
{/* fallback from request params if store not populated with flowName */}
{flowName || capitalize(flowSlug.replaceAll("-", " "))}
</Typography>

<Box display={"flex"}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export const platformAdminUser = {
};

export const defaultProps = {
flowSlug: "apply-for-planning-permission",
teamSlug: "barnet",
flowInformation: {
status: "online",
description: "A long description of a service",
Expand Down
1 change: 1 addition & 0 deletions editor.planx.uk/src/pages/FlowEditor/ReadMePage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FlowInformation } from "../utils";
export interface ReadMePageProps {
flowInformation: FlowInformation;
teamSlug: string;
flowSlug: string;
}

export interface ReadMePageForm {
Expand Down
12 changes: 9 additions & 3 deletions editor.planx.uk/src/routes/readMePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ const readMePageRoutes = compose(

mount({
"/": route(async (req) => {
const { team: teamSlug } = req.params;
const { team: teamSlug, flow: flowSlug } = req.params;

const data = await getFlowInformation(req.params.flow, req.params.team);

return {
title: makeTitle("About this page"),
view: <ReadMePage teamSlug={teamSlug} flowInformation={data} />,
view: (
<ReadMePage
teamSlug={teamSlug}
flowSlug={flowSlug}
flowInformation={data}
/>
),
};
}),
})
}),
);

export default readMePageRoutes;

0 comments on commit 2b600df

Please sign in to comment.