Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

3.9 KB
Raw Blame
import {
  ColorName,
  PROJECT_COLOR_PALETTE,
  ProjectType,
} from '@activepieces/shared';

import { Avatar } from '@/components/ui/avatar';
import { cn } from '@/lib/utils';

interface ProjectAvatarProps {
  displayName: string;
  projectType: ProjectType;
  iconColor: ColorName;
  size?: 'sm' | 'md' | 'lg';
  showBackground?: boolean;
  showDetails?: boolean;
  createdDate?: Date;
}

export const ProjectAvatar = ({
  displayName,
  projectType,
  iconColor,
  size = 'md',
  showBackground = true,
  showDetails = false,
  createdDate,
}: ProjectAvatarProps) => {
  const sizeClasses = {
    sm: {
      container: showDetails ? 'min-h-[140px]' : 'h-[60px]',
      avatar: 'h-[30px] w-[30px]',
      text: 'text-sm',
    },
    md: {
      container: showDetails ? 'min-h-[160px]' : 'h-[114px]',
      avatar: 'h-[50px] w-[50px]',
      text: 'text-xl',
    },
    lg: {
      container: showDetails ? 'min-h-[200px]' : 'h-[150px]',
      avatar: 'h-[70px] w-[70px]',
      text: 'text-3xl',
    },
  };

  const currentSize = sizeClasses[size];

  if (projectType === ProjectType.PERSONAL) {
    return (
      <div
        className={`flex ${
          showDetails ? 'flex-col items-center' : 'items-center'
        } justify-center w-full ${currentSize.container} ${
          showBackground ? 'rounded-tr-md' : ''
        } ${showDetails ? 'py-6' : ''}`}
        style={{
          backgroundColor: showBackground ? 'var(--gray-3)' : 'transparent',
        }}
      >
        <Avatar
          className={`${
            currentSize.avatar
          } flex items-center justify-center rounded-full ${
            showDetails ? 'mb-3' : ''
          }`}
          style={{
            backgroundColor: 'var(--gray-11)',
            color: 'var(--gray-1)',
          }}
        >
          <span className={cn(currentSize.text, 'leading-none')}>
            {displayName.charAt(0).toUpperCase()}
          </span>
        </Avatar>
        {showDetails && (
          <div className="px-4 text-center">
            <div className="font-semibold text-sm text-gray-12">
              {displayName}
            </div>
            {createdDate && (
              <div className="text-xs text-gray-11 mt-1">
                Created on{' '}
                {new Intl.DateTimeFormat('en-US', {
                  month: 'numeric',
                  day: 'numeric',
                  year: 'numeric',
                }).format(createdDate)}
              </div>
            )}
          </div>
        )}
      </div>
    );
  }

  return (
    <div
      className={`flex ${
        showDetails ? 'flex-col items-center' : 'items-center'
      } justify-center w-full ${currentSize.container} ${
        showBackground ? 'rounded-tr-md' : ''
      } ${showDetails ? 'py-6' : ''}`}
      style={{
        backgroundColor: showBackground
          ? `color-mix(in oklab, ${PROJECT_COLOR_PALETTE[iconColor].color}, transparent 85%)`
          : 'transparent',
      }}
    >
      <Avatar
        className={`${
          currentSize.avatar
        } flex items-center justify-center rounded-sm ${
          showDetails ? 'mb-3' : ''
        }`}
        style={{
          backgroundColor: PROJECT_COLOR_PALETTE[iconColor].color,
          color: PROJECT_COLOR_PALETTE[iconColor].textColor,
        }}
      >
        <span className={cn(currentSize.text, 'leading-none')}>
          {displayName.charAt(0).toUpperCase()}
        </span>
      </Avatar>
      {showDetails && (
        <div className="px-4 text-center">
          <div className="font-semibold text-sm text-gray-12">
            {displayName}
          </div>
          {createdDate && (
            <div className="text-xs text-gray-11 mt-1">
              Created on{' '}
              {new Intl.DateTimeFormat('en-US', {
                month: 'numeric',
                day: 'numeric',
                year: 'numeric',
              }).format(createdDate)}
            </div>
          )}
        </div>
      )}
    </div>
  );
};