diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx index 0e4ef6f895..0709e23070 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/ServiceSettings.tsx @@ -1,3 +1,4 @@ +import ContentCopyIcon from "@mui/icons-material/ContentCopy"; import Alert from "@mui/material/Alert"; import Box from "@mui/material/Box"; import Button from "@mui/material/Button"; @@ -5,12 +6,15 @@ import Container from "@mui/material/Container"; import FormControlLabel, { formControlLabelClasses, } from "@mui/material/FormControlLabel"; +import Link from "@mui/material/Link"; import Snackbar from "@mui/material/Snackbar"; import Switch, { SwitchProps } from "@mui/material/Switch"; +import Tooltip from "@mui/material/Tooltip"; import Typography from "@mui/material/Typography"; import { FlowStatus } from "@opensystemslab/planx-core/types"; import { useFormik } from "formik"; import React, { useState } from "react"; +import { rootFlowPath } from "routes/utils"; import { FONT_WEIGHT_BOLD } from "theme"; import InputGroup from "ui/editor/InputGroup"; import InputLegend from "ui/editor/InputLegend"; @@ -24,6 +28,127 @@ import InputRowItem from "ui/shared/InputRowItem"; import type { FlowSettings } from "../../../../types"; import { useStore } from "../../lib/store"; +const CopyButton = (props: { link: string; isActive: boolean }) => { + const [copyMessage, setCopyMessage] = useState<"copy" | "copied">("copy"); + return ( + + + + ); +}; + +const TitledLink: React.FC<{ + link: string; + isActive: boolean; + helpText: string | undefined; +}> = ({ link, isActive, helpText }) => { + return ( + + + Your public link + + + + {helpText} + + {isActive ? ( + + {link} + + ) : ( + + {link} + + )} + + ); +}; + +const PublicLink: React.FC<{ + isFlowPublished: boolean; + status: FlowStatus; + subdomain: string; + publishedLink: string; +}> = ({ isFlowPublished, status, subdomain, publishedLink }) => { + const isFlowPublic = isFlowPublished && status === "online"; + const hasSubdomain = Boolean(subdomain); + + const publicLinkHelpText = () => { + const isFlowOnline = status === "online"; + switch (true) { + case isFlowPublished && isFlowOnline: + return undefined; + case !isFlowPublished && isFlowOnline: + return "Publish your flow to activate the public link."; + case isFlowPublished && !isFlowOnline: + return "Switch your flow to 'online' to activate the public link."; + case !isFlowPublished && !isFlowOnline: + return "Publish your flow and switch it to 'online' to activate the public link."; + } + }; + + switch (true) { + case isFlowPublic && hasSubdomain: + return ( + + ); + case isFlowPublic && !hasSubdomain: + return ( + + ); + case !isFlowPublic && hasSubdomain: + return ( + + ); + case !isFlowPublic && !hasSubdomain: + return ( + + ); + } +}; + const TextInput: React.FC<{ title: string; richText?: boolean; @@ -81,19 +206,29 @@ const TextInput: React.FC<{ }; const ServiceSettings: React.FC = () => { - const [flowSettings, updateFlowSettings, flowStatus, updateFlowStatus] = - useStore((state) => [ - state.flowSettings, - state.updateFlowSettings, - state.flowStatus, - state.updateFlowStatus, - ]); + const [ + flowSettings, + updateFlowSettings, + flowStatus, + updateFlowStatus, + flowSlug, + teamDomain, + isFlowPublished, + ] = useStore((state) => [ + state.flowSettings, + state.updateFlowSettings, + state.flowStatus, + state.updateFlowStatus, + state.flowSlug, + state.teamDomain, + state.isFlowPublished, + ]); const [isAlertOpen, setIsAlertOpen] = useState(false); const handleClose = ( _event?: React.SyntheticEvent | Event, - reason?: string, + reason?: string ) => { if (reason === "clickaway") { return; @@ -143,6 +278,12 @@ const ServiceSettings: React.FC = () => { }, }); + const publishedLink = `${window.location.origin}${rootFlowPath( + false + )}/published`; + + const subdomainLink = teamDomain && `https://${teamDomain}/${flowSlug}`; + return ( @@ -264,9 +405,7 @@ const ServiceSettings: React.FC = () => { onChange={() => statusForm.setFieldValue( "status", - statusForm.values.status === "online" - ? "offline" - : "online", + statusForm.values.status === "online" ? "offline" : "online" ) } /> @@ -280,6 +419,14 @@ const ServiceSettings: React.FC = () => {

Offline services can still be edited and published as normal.

+ + +