feat(avatar): create DoctorAvatar component for improved doctor image handling
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import Image from "next/image";
|
||||
import { imageUrl } from "@/helper";
|
||||
|
||||
function getInitials(name) {
|
||||
if (!name) return "";
|
||||
const parts = name.trim().split(/\s+/).filter(Boolean);
|
||||
if (parts.length === 0) return "";
|
||||
if (parts.length === 1) return parts[0][0];
|
||||
return `${parts[0][0]}${parts[1][0]}`;
|
||||
}
|
||||
|
||||
function DoctorAvatar({ doctor, size = 72, className = "", priority = false }) {
|
||||
const url = doctor?.img?.[0]?.url;
|
||||
|
||||
if (!url) {
|
||||
return (
|
||||
<div
|
||||
style={{ width: size, height: size }}
|
||||
className={`flex items-center justify-center rounded-full bg-[#F8F8FF] text-[#3B3B3B] font-bold select-none ${className}`}
|
||||
>
|
||||
<span style={{ fontSize: size * 0.32 }}>{getInitials(doctor?.name)}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Image
|
||||
width={size}
|
||||
height={size}
|
||||
alt="image-doctor"
|
||||
src={imageUrl(url)}
|
||||
className={`object-contain rounded-full ${className}`}
|
||||
priority={priority}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default DoctorAvatar;
|
||||
@@ -1,11 +1,10 @@
|
||||
import { memo } from "react";
|
||||
import Image from "next/image";
|
||||
import { Button } from "@mui/material";
|
||||
import Link from "next/link";
|
||||
import CustomLoading from "./loading/Custom";
|
||||
import TextLoading from "./loading/Text";
|
||||
import CircularLoading from "./loading/Circular";
|
||||
import { imageUrl } from "@/helper";
|
||||
import DoctorAvatar from "./DoctorAvatar";
|
||||
|
||||
// Icons
|
||||
import ArrowLeftD from "@/components/icons/ArrowLeftD";
|
||||
@@ -29,12 +28,10 @@ function ItemDoctor({ doctor, loading, setDoctors, priority = false }) {
|
||||
{/* Detail Doctor */}
|
||||
<div className="flex items-center justify-start gap-2.5">
|
||||
<CircularLoading loading={loading} width={66} height={66}>
|
||||
<Image
|
||||
width={72}
|
||||
height={72}
|
||||
alt="image-doctor"
|
||||
src={imageUrl(doctor?.img?.[0]?.url)}
|
||||
className="object-contain rounded-full w-[64px] md:w-[68px] lg:w-[72px] h-[64px] md:h-[68px] lg:h-[72px]"
|
||||
<DoctorAvatar
|
||||
doctor={doctor}
|
||||
size={72}
|
||||
className="w-[64px] md:w-[68px] lg:w-[72px] h-[64px] md:h-[68px] lg:h-[72px]"
|
||||
priority={priority}
|
||||
/>
|
||||
</CircularLoading>
|
||||
|
||||
Reference in New Issue
Block a user