mirror of
https://github.com/bitbaum/botsmann.git
synced 2026-12-04 05:30:41 +01:00
Refactored multiple API routes and components to improve code organization and reduce duplication: - Simplified API route implementations across chat, documents, consultations, and other endpoints - Reorganized navigation components for better maintainability - Added shared utility functions and hooks - Created reusable Avatar and Logo components - Added validation schemas and API utilities - Improved type definitions and constants management Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { type FC } from 'react';
|
|
|
|
type AvatarSize = 'sm' | 'md' | 'lg' | 'xl';
|
|
|
|
interface AvatarProps {
|
|
src?: string | null;
|
|
alt: string;
|
|
fallback?: string;
|
|
size?: AvatarSize;
|
|
/** Border styling. Set to false to remove border */
|
|
border?: string | false;
|
|
className?: string;
|
|
}
|
|
|
|
const sizeClasses: Record<AvatarSize, string> = {
|
|
sm: 'h-8 w-8 text-sm',
|
|
md: 'h-12 w-12 text-lg',
|
|
lg: 'h-16 w-16 text-2xl',
|
|
xl: 'h-24 w-24 text-4xl',
|
|
} as const;
|
|
|
|
/**
|
|
* Reusable Avatar component
|
|
* Displays image if available, otherwise shows fallback initial
|
|
*/
|
|
export const Avatar: FC<AvatarProps> = ({
|
|
src,
|
|
alt,
|
|
fallback,
|
|
size = 'lg',
|
|
border = 'border-4 border-white',
|
|
className = '',
|
|
}) => {
|
|
const sizeClass = sizeClasses[size];
|
|
const initial = fallback || alt.charAt(0).toUpperCase();
|
|
const borderClass = border === false ? '' : border;
|
|
|
|
if (src) {
|
|
return (
|
|
/* eslint-disable-next-line @next/next/no-img-element -- Dynamic external avatar URL */
|
|
<img
|
|
className={`${sizeClass} rounded-full ${borderClass} object-cover ${className}`}
|
|
src={src}
|
|
alt={alt}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div
|
|
className={`${sizeClass} rounded-full ${borderClass} bg-gray-200 flex items-center justify-center text-gray-500 ${className}`}
|
|
>
|
|
{initial}
|
|
</div>
|
|
);
|
|
};
|