Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

3.4 KB
Raw Blame
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { Button, EmptyState, Modal } from "@editor/ui";
import { ConnectedInstanceRow } from "@editor/components/settings/ConnectedInstanceRow";
import type { LinkedInstanceRow } from "@editor/types/linkedInstance";
import { PrivateContent } from "@editor/components/shared/PrivateContent";

interface Props {
  instances: LinkedInstanceRow[];
  onRevoke: (instance: LinkedInstanceRow) => void;
  revokingId?: number | null;
  excludingCurrent?: boolean;
}

/** Uses the shared cloud row design while retaining the portal's owner-authorized revoke API. */
export function LinkedInstancesTable({
  instances,
  onRevoke,
  revokingId,
  excludingCurrent = false,
}: Props) {
  const { t } = useTranslation();
  const [selected, setSelected] = useState<LinkedInstanceRow | null>(null);
  const connected = instances.filter((instance) => !instance.revoked);
  return (
    <>
      {connected.length > 0 ? (
        <ul className="account-connection__list">
          {connected.map((instance) => (
            <ConnectedInstanceRow
              key={instance.instanceId}
              instance={instance}
              busy={revokingId != null}
              onRemove={() => setSelected(instance)}
            />
          ))}
        </ul>
      ) : (
        <EmptyState
          size="compact"
          title={t(
            excludingCurrent
              ? "portal.accountLink.instances.empty.otherTitle"
              : "portal.accountLink.instances.empty.title",
            excludingCurrent
              ? "No other connected instances"
              : "No connected instances",
          )}
          description={t(
            excludingCurrent
              ? "portal.accountLink.instances.empty.otherDescription"
              : "portal.accountLink.instances.empty.description",
            excludingCurrent
              ? "This is the only connected instance shown for your team."
              : "Connect a self-hosted server to your team to see it here.",
          )}
        />
      )}

      <Modal
        open={selected !== null}
        onClose={() => setSelected(null)}
        width="sm"
        title={
          <PrivateContent>
            {t("settings.connectedInstances.confirmTitle", "Remove {{name}}?", {
              name:
                selected?.name ??
                t("portal.accountLink.instances.unnamed", "Unnamed instance"),
            })}
          </PrivateContent>
        }
        footer={
          <div className="account-connection__actions">
            <Button
              variant="secondary"
              onClick={() => setSelected(null)}
              data-autofocus
            >
              {t("common.cancel", "Cancel")}
            </Button>
            <Button
              accent="danger"
              onClick={() => {
                if (selected) onRevoke(selected);
                setSelected(null);
              }}
            >
              {t("settings.connectedInstances.remove", "Remove connection")}
            </Button>
          </div>
        }
      >
        <p>
          {t(
            "settings.connectedInstances.confirmBody",
            "This revokes the instance’s access to your team in Stirling Cloud. It does not delete local files or remove usage already recorded. To connect again, follow the original connection steps on the instance.",
          )}
        </p>
      </Modal>
    </>
  );
}