SPB Git

Repository Public

ApiPanel.tsx 2.8 KB 65 lines tsx

1// Envoi d'un modèle par l'API : exemples cURL et JSON de POST /api/v1/messages/send pour CE modèle (identifiant réel,2// variables préremplies). La clé n'apparaît jamais : l'exemple la lit dans la variable d'environnement SPMAIL_API_KEY.3import { useMemo } from "react"4import { t } from "../../i18n"5import { S } from "../../state/app"6import { linkProps } from "../../state/session"7import { useStore } from "../../state/store"8import type { TemplateVariable } from "../../state/templates"9import { API_KEY_PLACEHOLDER, apiExample } from "../../templates/send"10import { Icon } from "../kit"11import { copyText } from "./shared"1213export function ApiPanel({ templateId, from, variables, values }: { templateId: string; from: string | null; variables: readonly TemplateVariable[]; values?: Readonly<Record<string, string>> }) {14  const isAdmin = useStore(S, (s) => s.me?.user.role === "admin")15  const example = useMemo(() => apiExample({ origin: window.location.origin, templateId, from, variables, values }), [templateId, from, variables, values])16  return (17    <div className="stack tpl-api" data-testid="api-panel">18      <p className="muted small">{t("tpl.api.body")}</p>19      <div className="stack tpl-api-block">20        <div className="row">21          <h3 className="spacer">{t("tpl.api.curl")}</h3>22          <button type="button" className="btn small" onClick={() => void copyText(example.curl, t("tpl.api.curlCopied"))}>23            <Icon name="copy" small />24            <span>{t("tpl.api.copyCurl")}</span>25          </button>26        </div>27        <pre className="tpl-api-code tpl-api-curl" tabIndex={0} aria-label={t("tpl.api.curl")} data-testid="api-curl">28          {example.curl}29        </pre>30      </div>31      <div className="stack tpl-api-block">32        <div className="row">33          <h3 className="spacer">{t("tpl.api.json")}</h3>34          <button type="button" className="btn small" onClick={() => void copyText(example.json, t("tpl.api.jsonCopied"))}>35            <Icon name="copy" small />36            <span>{t("tpl.api.copyJson")}</span>37          </button>38        </div>39        <pre className="tpl-api-code tpl-api-example" tabIndex={0} aria-label={t("tpl.api.json")} data-testid="api-json">40          {example.json}41        </pre>42      </div>43      <ul className="tpl-api-notes muted small">44        <li>45          <Icon name="key" small />46          <span>{t("tpl.api.keyNote", { placeholder: API_KEY_PLACEHOLDER })}</span>47        </li>48        <li>49          <Icon name="warn" small />50          <span>{t("tpl.api.rules")}</span>51        </li>52      </ul>53      {isAdmin ? (54        <p className="small">55          <a {...linkProps("/admin/keys")} data-testid="api-keys-link">56            {t("tpl.api.keysLink")}57          </a>58        </p>59      ) : (60        <p className="muted small">{t("tpl.api.keysAsk")}</p>61      )}62    </div>63  )64}65
Files main
Menu

Theme