import { NextPage } from "next"; import { useAppBridge } from "@saleor/app-sdk/app-bridge"; import { useRouter } from "next/router"; import React, { FormEventHandler, useEffect } from "react"; import { useIsMounted } from "usehooks-ts"; import Image from "next/image"; import SaleorLogoImage from "../assets/saleor-logo.svg"; import SaleorLogoImageDark from "../assets/saleor-logo-dark.svg"; import { InputAdornment, LinearProgress, TextField, Typography } from "@material-ui/core"; import { Button, makeStyles, useTheme } from "@saleor/macaw-ui"; import { isInIframe } from "@saleor/apps-shared"; const useStyles = makeStyles({ root: { maxWidth: 960, margin: "50px auto", }, headline: { marginTop: 70, lineHeight: 1.5, }, grid: { display: "grid", gridTemplateColumns: "50% 50%", gap: 116, marginTop: 48, }, form: { marginTop: 24, }, submitButton: { marginTop: 12, }, buttons: { marginTop: 24, "& > *": { marginBottom: 12, }, }, }); const Input = () => { return ( .saleor.cloud, }} /> ); }; /** * Common landing page in case of app being open outside the Dashboard. * Allows quick installation with Saleor env input * * Can be safely removed */ const IndexPage: NextPage = () => { const styles = useStyles(); const { appBridgeState } = useAppBridge(); const isMounted = useIsMounted(); const { replace } = useRouter(); const { themeType } = useTheme(); const onFormSubmit: FormEventHandler = (e) => { e.preventDefault(); const appOrigin = window.location.origin; const appManifestUrl = new URL("api/manifest", appOrigin); const saleorUrlSlug = new FormData(e.currentTarget).get("saleor-url") as string; const saleorUrl = new URL("https://" + saleorUrlSlug.replace("https://", "") + ".saleor.cloud"); const installationUrl = new URL( `dashboard/apps/install?manifestUrl=${appManifestUrl}`, saleorUrl ).href; window.location.href = installationUrl; }; useEffect(() => { if (isMounted() && appBridgeState?.ready) { replace("/configuration"); } }, [isMounted, appBridgeState?.ready]); /** * TODO Check also some timeout and show error if appBridge never handshakes */ if (isInIframe()) { return ; } return (
Saleor logo The Slack App has to be
launched in the Saleor Dashboard
Provide you Saleor URL
to quickly install the app
Or check the instructions
and see how to install the app
); }; export default IndexPage;