import { Link, List, ListItem, Paper, PaperProps, TextField, Typography } from "@material-ui/core"; import Skeleton from "@material-ui/lab/Skeleton"; import { useAppBridge, withAuthorization } from "@saleor/app-sdk/app-bridge"; import { SALEOR_API_URL_HEADER, SALEOR_AUTHORIZATION_BEARER_HEADER } from "@saleor/app-sdk/const"; import { ConfirmButton, ConfirmButtonTransitionState, makeStyles } from "@saleor/macaw-ui"; import { ChangeEvent, SyntheticEvent, useEffect, useState } from "react"; import AccessWarning from "../components/AccessWarning/AccessWarning"; import useAppApi from "../hooks/useAppApi"; import { AppColumnsLayout } from "../lib/ui/app-columns-layout"; import { AppIcon } from "../lib/ui/app-icon"; import { MainBar } from "../lib/ui/main-bar"; import useDashboardNotifier from "../utils/useDashboardNotifier"; interface ConfigurationField { key: string; value: string; } const useStyles = makeStyles((theme) => ({ confirmButton: { marginLeft: "auto", }, fieldContainer: { marginBottom: theme.spacing(2), }, })); function Section(props: PaperProps) { return ; } function Instructions() { const { appBridge } = useAppBridge(); const openExternalUrl = (url: string) => { // eslint-disable-next-line appBridge?.dispatch({ type: "redirect", payload: { newContext: true, actionId: "redirect_from_klaviyo_app", to: url, }, }); }; return ( How to set up App will send events as Klaviyo metrics each time Saleor Event occurs. When first metric is sent, it should be available in Klaviyo to build on top of. Metric name can be customized, PUBLIC_TOKEN must be provided to enable the app. Useful links { e.preventDefault(); openExternalUrl("https://github.com/saleor/saleor-app-klaviyo"); }} href="https://github.com/saleor/saleor-app-klaviyo" > Visit repository & readme How to configure { e.preventDefault(); openExternalUrl( "https://help.klaviyo.com/hc/en-us/articles/115005062267-How-to-Manage-Your-Account-s-API-Keys" ); }} href="https://help.klaviyo.com/hc/en-us/articles/115005062267-How-to-Manage-Your-Account-s-API-Keys" > Read about public tokens { e.preventDefault(); openExternalUrl("https://www.klaviyo.com/account#api-keys-tab"); }} href="https://www.klaviyo.com/account#api-keys-tab" > Get public token here { e.preventDefault(); openExternalUrl( "https://help.klaviyo.com/hc/en-us/articles/115005076787-Guide-to-Managing-Your-Metrics" ); }} href="https://help.klaviyo.com/hc/en-us/articles/115005076787-Guide-to-Managing-Your-Metrics" > Read about metrics ); } function Configuration() { const { appBridgeState } = useAppBridge(); const classes = useStyles(); const [notify] = useDashboardNotifier(); const [configuration, setConfiguration] = useState(); const [transitionState, setTransitionState] = useState("default"); const { data: configurationData, error } = useAppApi({ url: "/api/configuration", }); useEffect(() => { if (configurationData && !configuration) { setConfiguration(configurationData.data); } }, [configurationData, configuration]); /** * TODO Rewrite to tRPC */ const handleSubmit = (event: SyntheticEvent) => { event.preventDefault(); setTransitionState("loading"); fetch("/api/configuration", { method: "POST", headers: [ ["content-type", "application/json"], [SALEOR_API_URL_HEADER, appBridgeState?.saleorApiUrl!], [SALEOR_AUTHORIZATION_BEARER_HEADER, appBridgeState?.token!], ], body: JSON.stringify({ data: configuration }), }) .then(async (response) => { if (response.status !== 200) { throw new Error("Error saving configuration data"); } setTransitionState("success"); await notify({ status: "success", title: "Success", text: "Configuration updated successfully", }); }) .catch(async () => { setTransitionState("error"); await notify({ status: "error", title: "Configuration update failed. Ensure fields are filled correctly and you have MANAGE_APPS permission", }); }); }; const onChange = (event: ChangeEvent) => { const { name, value } = event.target as HTMLInputElement; setConfiguration((prev) => prev!.map((prevField) => (prevField.key === name ? { ...prevField, value } : prevField)) ); }; if (error) { console.error("Can't establish connection with the App API: ", error); return ( ⚠️ Can't connect with the App API You may see this error because: Internet connection has been lost Application installation process is still in progress. If you use Vercel, you may need to wait for redeployment of the app - try again in a minute. Application is misconfigured. If you would like to know more how auth configuration is kept,{" "} go to APL documentation . ); } if (configuration === undefined) { return ; } return ( } bottomMargin name="Saleor Klaviyo App" author="By Saleor Commerce" /> {configuration!.map(({ key, value }) => ( ))} ); } export default withAuthorization({ notIframe: , unmounted: null, noDashboardToken: , dashboardTokenInvalid: , })(Configuration);