Skip to content

Commit

Permalink
fix: skip Send event creation if not a published route (#3013)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak authored Apr 12, 2024
1 parent 0db8771 commit 194ccfd
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions editor.planx.uk/src/@planx/components/Send/Public.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import ErrorOutline from "@mui/icons-material/ErrorOutline";
import Typography from "@mui/material/Typography";
import axios from "axios";
import DelayedLoadingIndicator from "components/DelayedLoadingIndicator";
import { useStore } from "pages/FlowEditor/lib/store";
import React, { useEffect } from "react";
import { useAsync } from "react-use";

import Card from "../shared/Preview/Card";
import { WarningContainer } from "../shared/Preview/WarningContainer";
import { makeData } from "../shared/utils";
import { PublicProps } from "../ui";
import {
Expand All @@ -19,6 +22,37 @@ export type Props = PublicProps<Send>;
const SendComponent: React.FC<Props> = ({
destinations = [DEFAULT_DESTINATION],
...props
}) => {
const fullProps = { destinations: destinations, ...props };
if (
window.location.pathname.endsWith("/draft") ||
window.location.pathname.endsWith("/amber")
) {
return <SkipSendWarning {...fullProps} />;
} else {
return <CreateSendEvents {...fullProps} />;
}
};

/**
* Skip queuing up Send events on non-Save&Return layout routes because they don't record lowcal_session data
*/
const SkipSendWarning: React.FC<Props> = (props) => (
<Card handleSubmit={props.handleSubmit}>
<WarningContainer>
<ErrorOutline />
<Typography variant="body1" ml={2}>
You can only test submissions on <strong>published routes</strong> where
Save & Return is enabled. Click "Continue" to finish reviewing content
and skip submission.
</Typography>
</WarningContainer>
</Card>
);

const CreateSendEvents: React.FC<Props> = ({
destinations = [DEFAULT_DESTINATION],
...props
}) => {
const [passport, sessionId, teamSlug] = useStore((state) => [
state.computePassport(),
Expand Down

0 comments on commit 194ccfd

Please sign in to comment.