Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip Send event creation if not a published route #3013

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading