Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

3.1 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import { Badge, Button, IconButton } from "@carbon/react";
import { Trans, useLingui } from "@lingui/react/macro";
import { AnimatePresence, motion } from "motion/react";
import { LuExternalLink, LuX } from "react-icons/lu";
import type { ChangelogPanelEntry } from "~/modules/users/users.service";
import { path } from "~/utils/path";

type ChangelogPanelProps = {
  entry: ChangelogPanelEntry | null;
  isOpen: boolean;
  onDismiss: () => void;
};

// The link opens the entry's own page. path.to.changelogEntry carries the instance
// hint the docs Subscribe popover reads, which now sits on every changelog page.
export default function ChangelogPanel({
  entry,
  isOpen,
  onDismiss
}: ChangelogPanelProps) {
  const { t } = useLingui();
  if (!entry) return null;

  return (
    <AnimatePresence mode="wait">
      {isOpen && (
        <motion.div
          key={entry.guid}
          initial={{ opacity: 0, y: 20, scale: 0.95, filter: "blur(4px)" }}
          animate={{ opacity: 1, y: 0, scale: 1, filter: "blur(0px)" }}
          exit={{ opacity: 0, y: 10, scale: 0.95, filter: "blur(4px)" }}
          transition={{ duration: 0.3, ease: "easeOut" }}
          className="fixed bottom-4 right-4 w-[calc(100vw-2rem)] max-w-[380px] rounded-lg border bg-background shadow-lg z-40 overflow-hidden max-md:inset-x-2 max-md:bottom-[calc(0.5rem+env(safe-area-inset-bottom))] max-md:z-[60] max-md:w-auto max-md:max-w-none max-md:max-h-[85dvh] max-md:overflow-y-auto"
        >
          <div className="px-4 pt-4 pb-3 space-y-2">
            <div className="flex items-center justify-between">
              <Badge variant="blue" className="h-5 px-1.5 text-[10px]">
                <Trans>New</Trans>
              </Badge>
              <IconButton
                aria-label={t`Close`}
                icon={<LuX />}
                variant="ghost"
                size="sm"
                className="-mr-2 -mt-1"
                onClick={onDismiss}
              />
            </div>
            <h3 className="text-sm font-semibold tracking-tight">
              {entry.title}
            </h3>
            {entry.description && (
              <p className="text-xs text-muted-foreground">
                {entry.description}
              </p>
            )}
          </div>

          <div className="px-4 pb-3.5 flex items-center justify-end gap-2">
            <Button variant="secondary" size="sm" onClick={onDismiss}>
              <Trans>Dismiss</Trans>
            </Button>
            <Button
              size="sm"
              rightIcon={<LuExternalLink />}
              onClick={() =>
                window.open(
                  path.to.changelogEntry(entry.slug),
                  "_blank",
                  "noopener,noreferrer"
                )
              }
            >
              <Trans>Changelog</Trans>
            </Button>
          </div>
        </motion.div>
      )}
    </AnimatePresence>
  );
}