diff --git a/package-lock.json b/package-lock.json index 5d2643801d1..ab497f086a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -145,8 +145,8 @@ "node": ">=22.8.0" }, "optionalDependencies": { - "@esbuild/linux-arm64": "*", - "@esbuild/linux-x64": "*", + "@esbuild/linux-arm64": "latest", + "@esbuild/linux-x64": "latest", "@rollup/rollup-linux-arm64-gnu": "4.30.1", "@rollup/rollup-linux-x64-gnu": "4.30.1" } @@ -4532,7 +4532,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/@radix-ui/react-avatar/-/react-avatar-1.1.2.tgz", "integrity": "sha512-GaC7bXQZ5VgZvVvsJ5mu/AEbjYLnhhkoidOboC50Z6FFlLA03wG2ianUoH+zgDQ31/9gCF59bE4+2bBgTyMiig==", - "license": "MIT", "dependencies": { "@radix-ui/react-context": "1.1.1", "@radix-ui/react-primitive": "2.0.1", diff --git a/src/components/Common/Avatar.tsx b/src/components/Common/Avatar.tsx index 0ef1ce7ad56..05337526142 100644 --- a/src/components/Common/Avatar.tsx +++ b/src/components/Common/Avatar.tsx @@ -1,37 +1,31 @@ +import * as AvatarPrimitive from "@radix-ui/react-avatar"; import React from "react"; import { cn } from "@/lib/utils"; -const colors: string[] = [ - "#E6F3FF", // Light Blue - "#FFF0E6", // Light Peach - "#E6FFE6", // Light Green - "#FFE6E6", // Light Pink - "#F0E6FF", // Light Purple - "#FFFFE6", // Light Yellow - "#E6FFFF", // Light Cyan - "#FFE6F3", // Light Rose - "#F3FFE6", // Light Lime - "#E6E6FF", // Light Lavender - "#FFE6FF", // Light Magenta - "#E6FFF0", // Light Mint +// Subtle, professional color combinations that blend well with the UI +const colorPairs: Array<[string, string]> = [ + ["#E3F2FD", "#1565C0"], // Subtle Blue + ["#E8F5E9", "#2E7D32"], // Subtle Green + ["#FFF3E0", "#E65100"], // Subtle Orange + ["#F3E5F5", "#6A1B9A"], // Subtle Purple + ["#E1F5FE", "#0277BD"], // Subtle Light Blue + ["#E0F2F1", "#00695C"], // Subtle Teal + ["#FBE9E7", "#D84315"], // Subtle Deep Orange + ["#F3E5F5", "#6A1B9A"], // Subtle Purple + ["#E8EAF6", "#283593"], // Subtle Indigo + ["#FFF8E1", "#FF8F00"], // Subtle Amber + ["#FCE4EC", "#C2185B"], // Subtle Pink + ["#EFEBE9", "#4E342E"], // Subtle Brown ]; -const stringToInt = (name: string): number => { - const aux = (sum: number, remains: string): number => { - if (remains === "") return sum; - const firstCharacter = remains.slice(0, 1); - const newRemains = remains.slice(1); - return aux(sum + firstCharacter.charCodeAt(0), newRemains); - }; - - return Math.floor(aux(0, name)); +const stringToIndex = (name: string): number => { + return name.split("").reduce((acc, char) => acc + char.charCodeAt(0), 0); }; -const toColor = (name: string): [string, string] => { - const index = stringToInt(name) % colors.length; - const backgroundColor = colors[index]; - return [backgroundColor, "#333333"]; // Using dark gray for text +const getColorPair = (name: string): [string, string] => { + const index = stringToIndex(name) % colorPairs.length; + return colorPairs[index]; }; const initials = (name: string): string => { @@ -40,73 +34,67 @@ const initials = (name: string): string => { .slice(0, 2) .map((word) => word.slice(0, 1)) .join("") - .toUpperCase(); // Ensure initials are uppercase + .toUpperCase(); }; interface AvatarProps { colors?: [string, string]; - name?: string; + name: string; imageUrl?: string; className?: string; - icon?: React.ReactNode; } -const Avatar: React.FC = ({ - colors: propColors, - name, - imageUrl, - className, - icon, -}) => { - const [bgColor] = propColors || (name ? toColor(name) : toColor("")); +const Avatar = React.forwardRef< + React.ElementRef, + AvatarProps +>(({ colors: propColors, name, imageUrl, className }, ref) => { + const avatarText = name.match(/[a-zA-Z]+/g)?.join(" "); + + const [bgColor, textColor] = + propColors || + (avatarText ? getColorPair(avatarText) : getColorPair("user")); + return ( -
{imageUrl ? ( - {name} - ) : icon ? ( -
- {icon} -
) : ( - // Render initials SVG - - + - {name ? initials(name) : null} - - + + {avatarText ? initials(avatarText) : null} + + + )} -
+ ); -}; +}); export { Avatar }; export type { AvatarProps }; diff --git a/src/components/Common/LoginHeader.tsx b/src/components/Common/LoginHeader.tsx index 6a8bb48a0f6..3daa043bd83 100644 --- a/src/components/Common/LoginHeader.tsx +++ b/src/components/Common/LoginHeader.tsx @@ -4,7 +4,6 @@ import { useTranslation } from "react-i18next"; import CareIcon from "@/CAREUI/icons/CareIcon"; -import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { Button } from "@/components/ui/button"; import { DropdownMenu, @@ -13,6 +12,8 @@ import { DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; +import { Avatar } from "@/components/Common/Avatar"; + import { usePatientSignOut } from "@/hooks/usePatientSignOut"; import { LocalStorageKeys } from "@/common/constants"; @@ -33,31 +34,20 @@ export const LoginHeader = () => { dayjs(tokenData.createdAt).isAfter(dayjs().subtract(14, "minutes")); if (isLoggedIn) { - const phoneNumber = tokenData.phoneNumber?.replace("+91", "") || ""; - const initials = phoneNumber.slice(-2); - return (
- diff --git a/src/components/Facility/FacilityHome.tsx b/src/components/Facility/FacilityHome.tsx index 1dbaf401e40..89030a78a6c 100644 --- a/src/components/Facility/FacilityHome.tsx +++ b/src/components/Facility/FacilityHome.tsx @@ -159,7 +159,7 @@ export const FacilityHome = ({ facilityId }: Props) => { } }; - if (isLoading) { + if (isLoading || !facilityData) { return ; } @@ -210,7 +210,7 @@ export const FacilityHome = ({ facilityId }: Props) => {
diff --git a/src/components/ui/avatar.tsx b/src/components/ui/avatar.tsx deleted file mode 100644 index 6cc39073d38..00000000000 --- a/src/components/ui/avatar.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import * as AvatarPrimitive from "@radix-ui/react-avatar"; -import * as React from "react"; - -import { cn } from "@/lib/utils"; - -const Avatar = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -Avatar.displayName = AvatarPrimitive.Root.displayName; - -const AvatarImage = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -AvatarImage.displayName = AvatarPrimitive.Image.displayName; - -const AvatarFallback = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName; - -export { Avatar, AvatarImage, AvatarFallback }; diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx index 80e535fea9e..c77954fa11c 100644 --- a/src/components/ui/button.tsx +++ b/src/components/ui/button.tsx @@ -20,7 +20,7 @@ const buttonVariants = cva( secondary: "bg-gray-100 text-gray-900 shadow-sm hover:bg-gray-100/80 dark:bg-gray-800 dark:text-gray-50 dark:hover:bg-gray-800/80", ghost: - "underline hover:bg-gray-100 hover:text-gray-900 dark:hover:bg-gray-800 dark:hover:text-gray-50", + "hover:bg-gray-100 hover:text-gray-900 dark:hover:bg-gray-800 dark:hover:text-gray-50", link: "text-gray-900 underline-offset-4 hover:underline dark:text-gray-50", outline_primary: "border border-primary-700 text-primary-700 bg-white shadow-sm hover:bg-primary-700 hover:text-white dark:border-primary-700 dark:bg-primary-700 dark:text-white", diff --git a/src/components/ui/sidebar/patient-switcher.tsx b/src/components/ui/sidebar/patient-switcher.tsx index fe2b0aa02d6..370cafad43c 100644 --- a/src/components/ui/sidebar/patient-switcher.tsx +++ b/src/components/ui/sidebar/patient-switcher.tsx @@ -26,7 +26,7 @@ export function PatientSwitcher({ className }: PatientSwitcherProps) { const patientUserContext = usePatientContext(); - if (!patientUserContext) { + if (!patientUserContext || !patientUserContext.selectedPatient) { return null; } @@ -67,7 +67,7 @@ export function PatientSwitcher({ className }: PatientSwitcherProps) { {open && (
@@ -83,7 +83,7 @@ export function PatientSwitcher({ className }: PatientSwitcherProps) { {!open && (