Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

2.2 KB
Raw Blame
/* eslint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */
import { Icon, Input, Popover, Portal, Stack, Text } from '@chakra-ui/react';
import { Button, IconButton, PopoverContent } from '@platform/ui';
import { ArrowRightIcon, KeyRoundIcon } from 'lucide-react';
import { useTranslation } from 'react-i18next';

/** Key icon -> popover with a one-off access token and a jump to the keys tab. */
export const AccessTokenPopover = ({
  onChange,
  onManageKeys,
  value,
}: {
  onChange: (value: string) => void;
  onManageKeys: () => void;
  value: string;
}) => {
  const { t } = useTranslation();

  return (
    <Popover.Root lazyMount positioning={{ placement: 'bottom-end' }}>
      <Popover.Trigger asChild>
        <IconButton
          aria-label={t('models.accessTokenForDownload')}
          color={value.trim() === '' ? 'fg.muted' : 'accent.solid'}
          size="lg"
          variant="outline"
        >
          <Icon as={KeyRoundIcon} boxSize="4" />
        </IconButton>
      </Popover.Trigger>
      <Portal>
        <Popover.Positioner>
          <PopoverContent w="20rem">
            <Popover.Body p="2.5">
              <Stack gap="2">
                <Text color="fg.subtle" fontSize="xs" fontWeight="700" textTransform="uppercase">
                  {t('models.accessToken')}
                </Text>
                <Input
                  aria-label={t('models.accessToken')}
                  placeholder={t('models.accessTokenPlaceholder')}
                  type="password"
                  value={value}
                  onChange={(event) => onChange(event.currentTarget.value)}
                />
                <Text color="fg.subtle" fontSize="xs">
                  {t('models.accessTokenHelp')}
                </Text>
                <Button alignSelf="start" size="sm" variant="ghost" onClick={onManageKeys}>
                  {t('models.manageApiKeys')}
                  <Icon as={ArrowRightIcon} boxSize="3" />
                </Button>
              </Stack>
            </Popover.Body>
          </PopoverContent>
        </Popover.Positioner>
      </Portal>
    </Popover.Root>
  );
};