import React, { useState, useEffect, useContext } from "react"; import ReactGA from 'react-ga4'; import {getTheme} from "../theme.jsx"; import { ToastContainer, toast } from "react-toastify" import { CheckCircle as CheckCircleIcon, } from "@mui/icons-material"; import { Paper, Typography, Divider, Button, Tooltip, ToggleButtonGroup, ToggleButton, useMediaQuery, TextField, Box, } from "@mui/material"; import { red, green, } from "../views/AngularWorkflow.jsx" import { Context } from "../context/ContextApi.jsx"; //import { useAlert const Branding = (props) => { const { globalUrl, userdata, serverside, billingInfo,clickedFromOrgTab, stripeKey, selectedOrganization, handleGetOrg, } = props; const { themeMode, handleThemeChange, supportEmail, setSupportEmail, logoutUrl, setLogoutUrl, brandColor, setBrandColor, setBrandName } = useContext(Context) //const alert = useAlert(); const [publishingInfo, setPublishingInfo] = useState(""); const [publishRequirements, setPublishRequirements] = useState([]) const [currentSelectedTheme, setCurrentSelectedTheme] = useState(themeMode); const [integrationPartner, setIntegrationPartner] = useState(false); const [changingTheme, setChangingTheme] = useState(false); const theme = getTheme(themeMode, brandColor) const [selectedBrandColor, setSelectedBrandColor] = useState(theme?.palette?.main || "#FF8544") const [selectedBrandName, setSelectedBrandName] = useState(selectedOrganization?.branding?.brand_name || "") const [isLoading,setIsLoading] = useState(false); const handleEditOrg = (joinStatus) => { setIsLoading(true) const data = { "org_id": selectedOrganization.id, }; if (joinStatus === "join" || joinStatus === "leave") { data["creator_config"] = joinStatus } if (joinStatus === "light" || joinStatus === "dark" || joinStatus === "system") { data["branding"] = { "theme": joinStatus, "enable_chat": selectedOrganization?.branding?.enable_chat || false, "home_url": selectedOrganization?.branding?.home_url || "", "brand_color": selectedOrganization?.branding?.brand_color || theme.palette.primary.main, "brand_name": selectedOrganization?.branding?.brand_name || "", "logout_url": selectedOrganization?.branding?.logout_url || "", "support_email": selectedOrganization?.branding?.support_email || "", } data["editing_branding"] = true; } if (joinStatus === "brand_color") { data["branding"] = { "theme": selectedOrganization?.branding?.theme || "dark", "enable_chat": selectedOrganization?.branding?.enable_chat || false, "home_url": selectedOrganization?.branding?.home_url || "", "brand_color": selectedBrandColor, "brand_name": selectedOrganization?.branding?.brand_name || "", "logout_url": selectedOrganization?.branding?.logout_url || "", "support_email": selectedOrganization?.branding?.support_email || "", } data["editing_branding"] = true; } if (joinStatus === "brand_name") { data["branding"] = { "theme": selectedOrganization?.branding?.theme || "dark", "enable_chat": selectedOrganization?.branding?.enable_chat || false, "home_url": selectedOrganization?.branding?.home_url || "", "brand_color": selectedOrganization?.branding?.brand_color || theme.palette.primary.main, "brand_name": selectedBrandName, "logout_url": selectedOrganization?.branding?.logout_url || "", "support_email": selectedOrganization?.branding?.support_email || "", } toast.info("Updating brand name to " + selectedBrandName + ". Please wait a moment.") data["editing_branding"] = true; } if (joinStatus === "support_email") { data["branding"] = { "theme": selectedOrganization?.branding?.theme || "dark", "enable_chat": selectedOrganization?.branding?.enable_chat || false, "home_url": selectedOrganization?.branding?.home_url || "", "brand_color": selectedOrganization?.branding?.brand_color || theme.palette.primary.main, "brand_name": selectedOrganization?.branding?.brand_name || "", "support_email": supportEmail, "logout_url": selectedOrganization?.branding?.logout_url || "", } data["editing_branding"] = true; } if (joinStatus === "logout_url") { data["branding"] = { "theme": selectedOrganization?.branding?.theme || "dark", "enable_chat": selectedOrganization?.branding?.enable_chat || false, "home_url": selectedOrganization?.branding?.home_url || "", "brand_color": selectedOrganization?.branding?.brand_color || theme.palette.primary.main, "brand_name": selectedOrganization?.branding?.brand_name || "", "support_email": selectedOrganization?.branding?.support_email || "", "logout_url": logoutUrl, } data["editing_branding"] = true; } const url = globalUrl + `/api/v1/orgs/${selectedOrganization.id}`; fetch(url, { mode: "cors", method: "POST", body: JSON.stringify(data), credentials: "include", crossDomain: true, withCredentials: true, headers: { "Content-Type": "application/json; charset=utf-8", }, }) .then((response) => response.json().then((responseJson) => { if (responseJson["success"] === false) { toast("Failed updating org: ", responseJson.reason); } else { if (joinStatus === "join" || joinStatus === "leave") { if (joinStatus === "join") { setPublishingInfo("Your organization is now part of the Partner Program. You can now create, publish and manage content for your organization's public page.") } else { setPublishingInfo("Your organization is no longer part of the Creator Incentive Program. You can still create a creator account to manage your organization's content.") } } if (joinStatus === "light" || joinStatus === "dark" || joinStatus === "system") { handleThemeChange(joinStatus) setChangingTheme(false) setCurrentSelectedTheme(joinStatus) } if (joinStatus === "support_email") { toast.info("Support email updated successfully.") if (supportEmail?.length > 0) { setSupportEmail(supportEmail) }else { setSupportEmail("support@shuffler.io") } } if (joinStatus === "logout_url") { toast.info("Logout URL updated successfully.") setLogoutUrl(logoutUrl) } if (joinStatus === "brand_color") { toast.info("Brand color updated successfully.") setBrandColor(selectedBrandColor) localStorage.setItem("brandColor", selectedBrandColor) } if (joinStatus === "brand_name") { toast.info("Brand name updated successfully.") setBrandName(selectedBrandName) localStorage.setItem("brandName", selectedBrandName) } handleGetOrg(selectedOrganization.id); setIsLoading(false) } }) ) .catch((error) => { toast("Err: " + error.toString()); setIsLoading(false) }) }; useEffect(() => { if (userdata && userdata?.active_org && userdata?.active_org?.branding?.theme?.length > 0) { console.log("Setting current selected theme from userdata", userdata?.active_org?.branding?.theme); setCurrentSelectedTheme(userdata?.active_org?.branding?.theme); } },[userdata]); // Should enable / disable org branding const handleChangePublishing = () => { console.log("Handle change publishing"); if (selectedOrganization.creator_id == "") { handleEditOrg("join") } else { handleEditOrg("leave") } } const isOrganizationReady = () => { // Check if it's a suborg if (selectedOrganization.creator_org !== "") { const comment = "Child orgs can't become creators" if (!publishRequirements.includes(comment)) { setPublishRequirements([...publishRequirements, comment]) } return false; } // A simple checklist to ensure the button shows up properly if (selectedOrganization.name === selectedOrganization.org) { const comment = "Change the name of your organization" if (!publishRequirements.includes(comment)) { setPublishRequirements([...publishRequirements, comment]) } return false; } if (selectedOrganization.large_image === "" || selectedOrganization.large_image === theme.palette.defaultImage) { const comment = "Add a logo for your organization" if (!publishRequirements.includes(comment)) { setPublishRequirements([...publishRequirements, comment]) } return false; } return true } const isPublished = selectedOrganization.creator_id === "" const leadinfo = selectedOrganization.lead_info === undefined || selectedOrganization.lead_info === null || selectedOrganization.lead_info === "" ? "" : JSON.stringify(selectedOrganization.lead_info) const isPartner = leadinfo.includes("partner") useEffect(() => { if (selectedOrganization?.branding?.theme && selectedOrganization?.creator_org?.length === 0) { setCurrentSelectedTheme(selectedOrganization.branding.theme); } if (selectedOrganization?.creator_org?.length > 0 && userdata?.active_org?.branding.theme) { setCurrentSelectedTheme(userdata?.active_org?.branding.theme); } if ( selectedOrganization && selectedOrganization?.branding?.brand_color && selectedOrganization?.branding?.brand_color !== selectedBrandColor ) { setSelectedBrandColor(selectedOrganization.branding.brand_color); } if (selectedOrganization?.branding?.brand_name && selectedOrganization?.branding?.brand_name !== selectedBrandName) { setSelectedBrandName(selectedOrganization.branding.brand_name); } }, [selectedOrganization, userdata]); useEffect(() => { if ((userdata && userdata?.org_status?.includes("integration_partner") && !integrationPartner && !userdata?.org_status?.includes("sub_org")) || userdata?.support) { setIntegrationPartner(true) } },[userdata, integrationPartner]); const handleColorChange = (e) => { setSelectedBrandColor(e.target.value); }; const saveColorChanges = () => { toast.info("Updating brand color to " + selectedBrandColor + ". Please wait a moment.") handleEditOrg("brand_color"); }; return (
Partner Status & Branding Please note that same theme settings are applied to all sub organizations for partners. {isPublished ? : } {isPublished ? "Not Published" : "Published"} {!isPartner ? : } {!isPartner? "Not Officially Partnered" : "Officially Partnered"} {!isPublished ? ( ) : ( )} Public Partner Program
By changing publishing settings, you agree to our Terms of Service, and acknowledge that your organization's non-sensitive data will be added as a creator account. None of your existing workflows, apps, or other stored data will be published. Any admin in your organization can manage the creator configuration. Becoming a creator organization IS reversible.
Support: {supportEmail} {selectedOrganization.creator_id == "" ?   : null } {publishingInfo} {publishRequirements.map((item) => { return (
Required: {item}
) })}
{integrationPartner ? ( <> Parent & Sub Organization Branding Sub organizations are not allowed to change their branding. The branding is inherited from the parent organization. { if (newTheme === null) { return; } if (newTheme === currentSelectedTheme) { return; } if (changingTheme === true) { return } setChangingTheme(true) handleEditOrg(newTheme); }} aria-label="theme" style={{ justifyContent: "flex-start", marginBottom: 10, marginTop: 20 }} > Light Dark System ): null} {integrationPartner ? <> Brand Name
{ const value = e.target.value; setSelectedBrandName(value); }} size="small" PaperProps={{ style: { backgroundColor: theme.palette.backgroundColor, borderRadius: 4, border: `1px solid ${theme.palette.defaultBorder}` } }} style={{ height: 36, borderRadius: 4, border: `1px solid ${theme.palette.defaultBorder}`, width: 300 }} />
: null} {integrationPartner ? <> Brand Color
: null} {integrationPartner ? (
Support Email { setSupportEmail(e.target.value) }} color="primary" InputProps={{ style: { color: theme.palette.textFieldStyle.color, height: "35px", fontSize: "1em", borderRadius: 4, backgroundColor: theme.palette.textFieldStyle.backgroundColor, }, }} />
) : null} {integrationPartner ? (
Logout URL { setLogoutUrl(e.target.value) }} color="primary" InputProps={{ style: { color: theme.palette.textFieldStyle.color, height: "35px", fontSize: "1em", borderRadius: 4, backgroundColor: theme.palette.textFieldStyle.backgroundColor, }, }} />
) : null}
) } export default Branding;