|
| 1 | +import React, { useState } from "react" |
| 2 | +import "./KapaWidget.css" |
| 3 | + |
| 4 | +export default function KapaWidget() { |
| 5 | + const [isScriptLoaded, setIsScriptLoaded] = useState(false) |
| 6 | + const [child, setChild] = useState<HTMLScriptElement | undefined>() |
| 7 | + |
| 8 | + const loadKapaWidget = () => { |
| 9 | + console.log("Kapai", window.Kapa) |
| 10 | + |
| 11 | + if (isScriptLoaded) { |
| 12 | + document.body.removeChild(child) |
| 13 | + } |
| 14 | + |
| 15 | + const script = document.createElement("script") |
| 16 | + script.src = "https://widget.kapa.ai/kapa-widget.bundle.js" |
| 17 | + script.async = true |
| 18 | + script.setAttribute( |
| 19 | + "data-website-id", |
| 20 | + "e89e7663-df2c-4c7f-974a-1bf8accdd615", |
| 21 | + ) |
| 22 | + script.setAttribute("data-project-name", "Ory") |
| 23 | + script.setAttribute("data-project-color", "#1A237E") |
| 24 | + script.setAttribute( |
| 25 | + "data-modal-disclaimer", |
| 26 | + "By utilizing this chatbot, you consent to the collection and transmission of data to kapa.ai, which may include your IP address. Please be advised that your privacy and data protection are of utmost importance to us. We assure you that any data collected will be handled in compliance with applicable laws and regulations. For further details on how your data is processed and used, we encourage you to review our Privacy Policy. If you do not agree with these terms, we kindly request that you refrain from using this chatbot.", |
| 27 | + ) |
| 28 | + script.setAttribute("data-modal-title", "Ory AI Copilot") |
| 29 | + script.setAttribute("data-button-text", "Ask AI") |
| 30 | + script.setAttribute("data-project-logo", "/docs/img/kapa-logo.png") |
| 31 | + script.setAttribute("data-consent-required", "true") |
| 32 | + script.setAttribute("data-button-hide", "true") |
| 33 | + script.setAttribute("data-modal-override-open-id", "custom-button-id") |
| 34 | + script.setAttribute("data-modal-open-by-default", "true") |
| 35 | + script.onload = () => setIsScriptLoaded(true) |
| 36 | + setChild(document.body.appendChild(script)) |
| 37 | + } |
| 38 | + |
| 39 | + return ( |
| 40 | + <button |
| 41 | + id="custom-button-id" |
| 42 | + className="mantine-UnstyledButton-root mantine-Button-root mantine-124rx6h" |
| 43 | + type="button" |
| 44 | + data-button="true" |
| 45 | + style={{ |
| 46 | + position: "fixed", |
| 47 | + bottom: "20px", |
| 48 | + right: "20px", |
| 49 | + height: "5rem", |
| 50 | + width: "4.5rem", |
| 51 | + padding: "0px", |
| 52 | + backgroundColor: "rgb(26, 35, 126)", |
| 53 | + boxShadow: "rgba(0, 0, 0, 0.2) 0px 0px 10px", |
| 54 | + zIndex: 199, |
| 55 | + }} |
| 56 | + onClick={loadKapaWidget} |
| 57 | + > |
| 58 | + <div className="mantine-1wpc1xj mantine-Button-inner"> |
| 59 | + <span className="mantine-1ryt1ht mantine-Button-label"> |
| 60 | + <div |
| 61 | + className="mantine-Stack-root mantine-1b4vo4u" |
| 62 | + style={{ marginTop: "4px" }} |
| 63 | + > |
| 64 | + <div |
| 65 | + className="mantine-Image-root mantine-yxmaw9" |
| 66 | + style={{ width: "2rem" }} |
| 67 | + > |
| 68 | + <figure className="mantine-qenwvq mantine-Image-figure"> |
| 69 | + <div className="mantine-1iugybl mantine-Image-imageWrapper"> |
| 70 | + <img |
| 71 | + src="/docs/img/kapa-logo.png" |
| 72 | + alt="Project Logo" |
| 73 | + className="mantine-1sc70ew mantine-Image-image" |
| 74 | + style={{ |
| 75 | + objectFit: "cover", |
| 76 | + width: "2rem", |
| 77 | + height: "2rem", |
| 78 | + }} |
| 79 | + /> |
| 80 | + </div> |
| 81 | + </figure> |
| 82 | + </div> |
| 83 | + <div |
| 84 | + className="mantine-Text-root mantine-1y9jqg9" |
| 85 | + style={{ textShadow: "rgba(0, 0, 0, 0.2) 1px 1px 2px" }} |
| 86 | + > |
| 87 | + Ask AI |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + </span> |
| 91 | + </div> |
| 92 | + </button> |
| 93 | + ) |
| 94 | +} |
0 commit comments