remove next image

This commit is contained in:
Ichsan Kurniawan
2026-01-28 21:10:07 +07:00
parent e0e9f8651f
commit 5e439ea9f7
38 changed files with 216 additions and 113 deletions
@@ -183,7 +183,7 @@ const AdjusmentAutoCheckout: FC<Props> = ({ data, className }) => {
<div className="flex justify-between border-b border-zinc-300 dark:border-zinc-800 pt-3 pb-3.5" key={key} onClick={() => handleFetchPresenceByID(item.presence_id)} >
<div className="flex">
<Suspense fallback={<FallbackAvatar />}>
<Avatar avatar={item.avatar} className='w-10 h-10' sizes='40px' />
<Avatar avatar={item.avatar} className='w-10 h-10' />
</Suspense>
<div className="ml-4 space-y-0.5">
<p className="text-sm font-medium leading-none">{item.fullname}</p>
@@ -231,7 +231,7 @@ const AdjusmentAutoCheckout: FC<Props> = ({ data, className }) => {
<div className='grid grid-cols-1 md:grid-cols-5 text-center md:text-left text-sm md:text-base md:my-3'>
<div className='col-span-2 flex flex-col items-center md:items-start'>
<Suspense fallback={<FallbackAvatar className='w-52 h-52 rounded-xl' />}>
<ViewAvatar isPresence avatar={dataPresence.face_image} className='w-52 h-52 sm:w-52 sm:h-52 rounded-xl shadow' sizes='208px' />
<ViewAvatar isPresence avatar={dataPresence.face_image} className='w-52 h-52 sm:w-52 sm:h-52 rounded-xl shadow' />
</Suspense>
<span className='text-base font-semibold mt-2'>{dataPresence.user.fullname}</span>
<span className='text-muted-foreground'>{dataPresence?.user?.position?.name || dataPresence?.user.nickname}</span>
@@ -147,7 +147,7 @@ const ApprovalLeaveSick: FC<Props> = ({ data, className }) => {
<div className="flex justify-between border-b border-zinc-300 dark:border-zinc-800 pt-3 pb-3.5" key={key} onClick={() => handleFetchPresenceByID(item.application_form_id)}>
<div className="flex">
<Suspense fallback={<FallbackAvatar />}>
<Avatar avatar={item.avatar} className='w-10 h-10' sizes='40px' />
<Avatar avatar={item.avatar} className='w-10 h-10' />
</Suspense>
<div className="ml-3.5 space-y-0.5">
<p className="text-sm font-medium leading-none">{item.fullname}</p>
@@ -185,7 +185,7 @@ const ApprovalLeaveSick: FC<Props> = ({ data, className }) => {
<div className='grid grid-cols-1 md:grid-cols-5 text-center md:text-left text-sm md:text-base md:my-3'>
<div className='col-span-2 flex flex-col items-center md:items-start'>
<Suspense fallback={<FallbackAvatar className='w-52 h-52 shadow' />}>
<ViewAvatar avatar={dataPresence?.avatar} className='w-52 h-52 sm:w-52 sm:h-52 shadow' sizes='208px' />
<ViewAvatar avatar={dataPresence?.avatar} className='w-52 h-52 sm:w-52 sm:h-52 shadow' />
</Suspense>
<span className='text-base font-semibold mt-2'>{dataPresence.user.fullname}</span>
<span className='text-muted-foreground'>{dataPresence?.position_name || dataPresence?.user.nickname}</span>
@@ -47,7 +47,7 @@ const EmployeeBirthday: FC<Props> = ({ data, className }) => {
data.list.map((item: any, key: number) =>
<div className="flex" key={key}>
<Suspense fallback={<FallbackAvatar />}>
<ViewAvatar avatar={item.avatar} className='w-10 h-10' sizes='40px' />
<ViewAvatar avatar={item.avatar} className='w-10 h-10' />
</Suspense>
<div className="ml-4 space-y-0.5 text-xs">
<p className="text-sm font-medium leading-none">{item.fullname}</p>
+2 -2
View File
@@ -156,7 +156,7 @@ const NeedApproval: FC<Props> = ({ data, className }) => {
<div className="flex justify-between border-b border-zinc-300 dark:border-zinc-800 pt-3 pb-3.5" key={key} onClick={() => handleFetchPresenceByID(item.presence_id)}>
<div className='flex'>
<Suspense fallback={<FallbackAvatar />}>
<Avatar avatar={item.avatar} className='w-10 h-10' sizes='40px' />
<Avatar avatar={item.avatar} className='w-10 h-10' />
</Suspense>
<div className="ml-4 space-y-0.5">
<p className="text-sm font-medium leading-none">{item.fullname}</p>
@@ -204,7 +204,7 @@ const NeedApproval: FC<Props> = ({ data, className }) => {
<div className='grid grid-cols-1 md:grid-cols-5 text-center md:text-left text-sm md:text-base md:my-3'>
<div className='col-span-2 flex flex-col items-center md:items-start'>
<Suspense fallback={<FallbackAvatar className='w-52 h-52 rounded-xl' />}>
<ViewAvatar isPresence avatar={dataPresence.face_image} className='w-52 h-52 sm:w-52 sm:h-52 rounded-xl shadow' sizes='208px' />
<ViewAvatar isPresence avatar={dataPresence.face_image} className='w-52 h-52 sm:w-52 sm:h-52 rounded-xl shadow' />
</Suspense>
<span className='text-base font-semibold mt-2'>{dataPresence.user.fullname}</span>
<span className='text-muted-foreground'>{dataPresence?.user?.position?.name || dataPresence?.user.nickname}</span>
@@ -78,7 +78,7 @@ const PresenceDetail: FC<Props> = ({ data, className }) => {
<div className="flex justify-between" key={key}>
<div className="flex">
<Suspense fallback={<FallbackAvatar />}>
<ViewAvatar avatar={item.avatar} className='w-10 h-10' sizes='40px' />
<ViewAvatar avatar={item.avatar} className='w-10 h-10' />
</Suspense>
<div className="ml-4 space-y-0.5">
<p className="text-sm font-medium leading-none">{item.fullname}</p>
+1 -1
View File
@@ -96,7 +96,7 @@ const TeamMemberCard = ({ member, isPast = false }: { member: TeamMember; isPast
<Card className={`transition-all duration-300 hover:shadow-lg ${isPast ? "opacity-70" : "hover:-translate-y-1"}`}>
<CardContent className="p-6 text-center">
<Suspense fallback={<FallbackAvatar className="w-20 h-20" />}>
<ViewAvatar avatar={member.avatar!} className={`rounded-full min-w-20 min-h-20 mx-auto ring-4 ${isPast ? "ring-muted" : "ring-primary/20"}`} sizes="80px" quality={75} />
<ViewAvatar avatar={member.avatar!} className={`rounded-full min-w-20 min-h-20 mx-auto ring-4 ${isPast ? "ring-muted" : "ring-primary/20"}`} />
</Suspense>
<h3 className={`font-semibold text-lg mb-1 mt-4 ${isPast ? "text-muted-foreground" : "text-foreground"}`}>
@@ -142,7 +142,7 @@ const ChangeAvatar: FC<Props> = ({ nik, existAvatar }) => {
<>
<div className='flex flex-col sm:flex-row items-center sm:space-x-6 xl:space-x-8 space-y-5 sm:space-y-0 pt-6'>
<Suspense fallback={<FallbackAvatar className='w-[120px] h-[120px] md:w-40 md:h-40' />}>
<ViewAvatar avatar={existAvatar!} className='w-[120px] h-[120px] md:w-40 md:h-40 duration-300' sizes="(max-width: 768px) 100vw, 200px" quality={80} />
<ViewAvatar avatar={existAvatar!} className='w-[120px] h-[120px] md:w-40 md:h-40 duration-300' />
</Suspense>
<div className='flex flex-col items-center sm:items-start space-y-3'>
<p className='w-full xl:w-5/12 text-center sm:text-left text-sm'>Personalize your account with photos. Your profile photo will appear on apps and devices that use your Supper Apps account.</p>
+1 -1
View File
@@ -24,7 +24,7 @@ const releaseNotes: ReleaseNote[] = [
{ category: 'breaking', description: <div>Fixing two additional vulnerabilities (Denial of Service <Link href='https://www.cve.org/CVERecord?id=CVE-2025-55184' className="underline text-blue-500">CVE-2025-55184</Link> and Source Code Exposure <Link href='https://www.cve.org/CVERecord?id=CVE-2025-55183' className="underline text-blue-500">CVE-2025-55183</Link>) in React Server Components. Please see this <Link href='https://react.dev/blog/2025/12/11/denial-of-service-and-source-code-exposure-in-react-server-components' className="underline text-blue-500"> React blog</Link> and this <Link href='https://vercel.com/kb/bulletin/security-bulletin-cve-2025-55184-and-cve-2025-55183?inf_ver=2&inf_ctx=g-3JhSYYZ0cx0G92duvbVawt9MIUiJBx04F4TGk46SdN0tsn1FNDXF_G5vKieBlBKax98GA9lOoIe74XNaed1S6Wa8A9XVCcQnf7JfzhcMcYf7mVYAioJHKT9Sz7nfnFFJxWbT5NcYyo9VREl4uBiO2Kg2t3KGzayTEuONY9ltlAMbGM5Z1mivcoj51nMOAu9c0OrD6gBntT6f4p1hnaFo6EC84B8QRJzR76vvHPz8vVnwiEEeHb-XcKtmFe2TOsyeNm5HO9vJAje1YNVus4Raff2EPwyfGci7qB61IJx0MXss_h7pK0-2jDL3mQiodUo-BTOiItMTByT3jaKzQ9fw%3D%3D' className="underline text-blue-500">Next.js bulletin</Link> to learn more about these vulnerabilities (December 11, 2025).</div> },
{ category: "improvement", description: "Upgraded Next.js from v13.5.6 to v16.0.10" },
{ category: "improvement", description: "Upgraded React and ReactDOM from v18.2.0 to v19.2.3" },
{ category: "improvement", description: "Replaced native img tags with Next.js Image component and added lazy loading for avatars" },
{ category: "improvement", description: "Replaced native img tags with LazyLoad Image component and added lazy loading for avatars" },
{ category: "bugfix", description: "Fixed spamming \"Failed to fetch geolocation\" alerts when presence using mobile devices" },
{ category: "feature", description: "Added progress bar indicator when route change in employee routes" },
{ category: 'feature', description: <div>Added <Link href="/hats-team" className="underline text-blue-500">hats team</Link> page</div> },
@@ -148,7 +148,7 @@ const ComponentAreaPage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -172,7 +172,7 @@ const ComponentCompanyPage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default',
// size: 'default',
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -145,7 +145,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -258,7 +258,7 @@ const TableAttendanceHistory: FC<Props> = ({ data }) => {
defaultPageSize: 15,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -186,7 +186,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
+1 -1
View File
@@ -151,7 +151,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
+1 -1
View File
@@ -143,7 +143,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -151,7 +151,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
+1 -1
View File
@@ -151,7 +151,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -160,7 +160,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -92,7 +92,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -63,7 +63,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -92,7 +92,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -134,7 +134,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -63,7 +63,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -2,7 +2,7 @@ import ViewAvatar from '@/components/ViewAvatar';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { getVariantApproved, getVariantWorkingStatus } from '@/lib/helper';
import { getVariantWorkingStatus } from '@/lib/helper';
import dayjs from 'dayjs';
import { Dispatch, FC, MouseEvent, SetStateAction } from 'react';
@@ -28,7 +28,7 @@ const DetailModalComponent: FC<Props> = ({ data, open, onOpenChange, onClose })
</DialogHeader>
<div className='grid grid-cols-1 md:grid-cols-5 text-center md:text-left text-sm md:text-base md:my-3'>
<div className='col-span-2 flex flex-col items-center md:items-start'>
<ViewAvatar avatar={data.avatar} className='w-52 h-52 sm:w-52 sm:h-52 rounded-xl shadow' sizes='208px' />
<ViewAvatar avatar={data.avatar} className='w-52 h-52 sm:w-52 sm:h-52 rounded-xl shadow' />
<span className='text-base font-semibold mt-2'>{data.fullname}</span>
<span className='text-muted-foreground'>{data?.position_name || data?.nickname}</span>
</div>
@@ -96,7 +96,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 15,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -28,7 +28,7 @@ const DetailModalComponent: FC<Props> = ({ data, open, onOpenChange, onClose })
</DialogHeader>
<div className='grid grid-cols-1 md:grid-cols-5 text-center md:text-left text-sm md:text-base md:my-3'>
<div className='col-span-2 flex flex-col items-center md:items-start'>
<ViewAvatar isPresence avatar={data.presence_checkin_face_image} className='w-52 h-52 sm:w-52 sm:h-52 rounded-xl shadow' sizes='208px' />
<ViewAvatar isPresence avatar={data.presence_checkin_face_image} className='w-52 h-52 sm:w-52 sm:h-52 rounded-xl shadow' />
<span className='text-base font-semibold mt-2'>{data.fullname}</span>
<span className='text-muted-foreground max-w-full! truncate'>{data?.position_name || data?.nickname}</span>
</div>
@@ -106,7 +106,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 15,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
+1 -1
View File
@@ -173,7 +173,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -651,7 +651,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 15,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
+1 -1
View File
@@ -47,7 +47,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 15,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -51,7 +51,7 @@ const DetailModalComponent: FC<Props> = ({ data, open, onOpenChange, onClose })
</div>
<div>
<p className='text-muted-foreground text-xs md:text-sm font-medium'>Note</p>
<p className='break-words'>{data.note || '-'}</p>
<p className='wrap-break-words'>{data.note || '-'}</p>
{data.tag?.length > 0 && data.tag?.map((item: string) =>
<Badge variant='secondary' className='mr-1' key={item}>{item}</Badge>
)}
@@ -111,7 +111,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 15,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
@@ -115,7 +115,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
defaultPageSize: 30,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
+1 -1
View File
@@ -47,7 +47,7 @@ const TableAttendanceHistory: FC<Props> = ({ data }) => {
defaultPageSize: 15,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
// size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
+2 -5
View File
@@ -9,9 +9,8 @@ import fetchData, { fetchDataWithPost } from '@/lib/fetchData';
import { generateHourMinutes } from '@/lib/helper';
import { type IUser } from '@/app/admin/administration/user/component/type';
import { type IPerformace } from './type';
import FallbackAvatar from '@/components/loader/FallbackAvatar';
import ViewAvatar from '@/components/ViewAvatar';
const ViewAvatar = lazy(() => import('@/components/ViewAvatar'));
const DonutChart = lazy(() => import('./DonutChart'));
const AreaChart = lazy(() => import('./AreaChart'))
const TableAttendanceHistory = lazy(() => import('./Table'))
@@ -47,9 +46,7 @@ const PerformanceComponent: FC<Props> = async ({ id, start_date, end_date }) =>
<div className='gap-4 space-y-7 w-full mx-auto mt-6'>
<Card900>
<CardContent className='flex flex-col sm:flex-row items-center gap-6 sm:gap-0'>
<Suspense fallback={<FallbackAvatar className='w-40 h-40 sm:min-w-44 sm:w-44! sm:h-44! duration-300' />}>
<ViewAvatar avatar={user.avatar} className='w-40 h-40 sm:min-w-44 sm:w-44! sm:h-44! duration-300' sizes="(max-width: 640px) 100vw, 640px" quality={75} />
</Suspense>
<ViewAvatar avatar={user.avatar} className='w-40 h-40 sm:min-w-44 sm:w-44! sm:h-44! duration-300' />
<div className='sm:ml-6 2xl:ml-10 w-full'>
<span className='text-lg font-semibold leading-none tracking-tight sm:text-2xl'>{user.fullname}</span>
<div className='grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-2 mt-3 w-full'>
+103
View File
@@ -0,0 +1,103 @@
import { FC } from 'react';
import Image from 'next/image';
import { Dialog, DialogContent, DialogHeader, DialogTrigger } from './ui/dialog';
import { cn } from '@/lib/utils';
import { DialogDescription, DialogTitle } from '@radix-ui/react-dialog';
type Props = {
avatar: string
className?: string,
isPresence?: boolean
sizes?: string;
quality?: number
};
const ViewAvatarNextImage: FC<Props> = ({ avatar, className, isPresence, quality = 65, sizes = "(max-width: 640px) 36px, 40px" }) => {
return (
<>
{avatar ?
<Dialog>
<DialogTrigger asChild>
{/* <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + avatar} className={cn("h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border cursor-pointer hover:scale-110 duration-200", className)} /> */}
<div className={cn("relative h-9 w-9 sm:h-10 sm:w-10", className)}>
<Image
src={`${process.env.BASE_URL_IMG}${avatar}`}
alt="avatar"
fill
sizes={sizes}
quality={quality}
className="rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
/>
</div>
</DialogTrigger>
<DialogContent className={`overflow-hidden p-0 rounded-2xl ${isPresence ? 'h-auto w-full' : 'w-full h-[400px] sm:w-[500px] sm:h-[500px]'}`}>
<DialogHeader className='sr-only'>
<DialogTitle>Profile</DialogTitle>
<DialogDescription>Description of profile avatar</DialogDescription>
</DialogHeader>
{/* <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + avatar} className="w-full h-full shadow-sm rounded-2xl border border-border" /> */}
{/* 2. Logic Switch for Image Mode */}
{isPresence ? (
// MODE A: Presence (Natural Aspect Ratio)
// We use width=0 height=0 + sizes=100vw to emulate "width: 100%, height: auto"
<Image
src={process.env.BASE_URL_IMG + avatar}
alt="avatar"
width={0}
height={0}
sizes="100vw"
quality={90}
className="w-full h-auto object-contain" // h-auto lets it grow naturally
/>
) : (
// MODE B: Default Profile (Fixed Box with Crop)
// We use fill to cover the specific 500x500 box
<div className="relative w-full h-full">
<Image
src={process.env.BASE_URL_IMG + avatar}
alt="avatar"
fill
className="object-cover shadow-sm border border-border"
sizes="(max-width: 640px) 100vw, 500px"
quality={90}
/>
</div>
)}
</DialogContent>
</Dialog>
:
<div className={cn("relative h-9 w-9 sm:h-10 sm:w-10", className)}>
<Image
alt='avatar'
src='/assets/no-avatar.jpg'
fill
sizes={sizes}
className='shadow-sm rounded-full object-cover border border-border'
/>
</div>
}
</>
);
}
export const Avatar: FC<Props> = ({ avatar, className, sizes = "(max-width: 640px) 36px, 40px" }) => {
return (
<>
{avatar ?
// <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + avatar} className={cn("h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border cursor-pointer hover:scale-110 duration-200", className)} />
<div className={cn("relative h-9 w-9 sm:h-10 sm:w-10", className)}>
<Image src={`${process.env.BASE_URL_IMG}${avatar}`} alt="avatar"
fill // This replaces width/height
sizes={sizes} // Optimization (explained below)
className="rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
/>
</div>
:
<Image alt='avatar' height={0} width={0} quality={50} src='/assets/no-avatar.jpg' className={cn('h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border', className)} />
}
</>
);
}
export default ViewAvatarNextImage;
+72 -69
View File
@@ -1,101 +1,104 @@
'use client'
import { FC } from 'react';
import Image from 'next/image';
import { Dialog, DialogContent, DialogHeader, DialogTrigger } from './ui/dialog';
import { LazyLoadImage } from 'react-lazy-load-image-component';
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from './ui/dialog';
import { cn } from '@/lib/utils';
import { DialogDescription, DialogTitle } from '@radix-ui/react-dialog';
type Props = {
avatar: string
className?: string,
isPresence?: boolean
sizes?: string;
quality?: number
avatar: string | null; // Allow null to handle fallback logic safely
className?: string;
isPresence?: boolean;
// sizes and quality are removed as they are specific to Next/Image server processing
};
const ViewAvatar: FC<Props> = ({ avatar, className, isPresence, quality = 65, sizes = "(max-width: 640px) 36px, 40px" }) => {
const ViewAvatar: FC<Props> = ({ avatar, className, isPresence }) => {
return (
<>
{avatar ?
{avatar ? (
<Dialog>
<DialogTrigger asChild>
{/* <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + avatar} className={cn("h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border cursor-pointer hover:scale-110 duration-200", className)} /> */}
<div className={cn("relative h-9 w-9 sm:h-10 sm:w-10", className)}>
<Image
src={`${process.env.BASE_URL_IMG}${avatar}`}
{/* 1. TRIGGER IMAGE
Removed the wrapper div. Applied classes directly to LazyLoadImage.
Added `block` to wrapperClassName to prevent extra inline spacing.
*/}
<span className={cn("inline-block h-9 w-9 sm:h-10 sm:w-10", className)}>
<LazyLoadImage
alt="avatar"
fill
sizes={sizes}
quality={quality}
className="rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
src={`${process.env.BASE_URL_IMG}${avatar}`}
effect="blur"
wrapperClassName="w-full h-full"
className="w-full h-full rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
/>
</div>
</span>
</DialogTrigger>
<DialogContent className={`overflow-hidden p-0 rounded-2xl ${isPresence ? 'h-auto w-full' : 'w-full h-[400px] sm:w-[500px] sm:h-[500px]'}`}>
<DialogContent className={cn(
"overflow-hidden p-0 rounded-2xl",
isPresence ? "w-full max-w-screen-3xl h-auto" : "w-full h-[400px] sm:w-[500px] sm:h-[500px]"
)}>
<DialogHeader className='sr-only'>
<DialogTitle>Profile</DialogTitle>
<DialogDescription>Description of profile avatar</DialogDescription>
</DialogHeader>
{/* <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + avatar} className="w-full h-full shadow-sm rounded-2xl border border-border" /> */}
{/* 2. Logic Switch for Image Mode */}
{isPresence ? (
// MODE A: Presence (Natural Aspect Ratio)
// We use width=0 height=0 + sizes=100vw to emulate "width: 100%, height: auto"
<Image
src={process.env.BASE_URL_IMG + avatar}
alt="avatar"
width={0}
height={0}
sizes="100vw"
quality={90}
className="w-full h-auto object-contain" // h-auto lets it grow naturally
/>
) : (
// MODE B: Default Profile (Fixed Box with Crop)
// We use fill to cover the specific 500x500 box
<div className="relative w-full h-full">
<Image
src={process.env.BASE_URL_IMG + avatar}
alt="avatar"
fill
className="object-cover shadow-sm border border-border"
sizes="(max-width: 640px) 100vw, 500px"
quality={90}
/>
</div>
)}
{/* 2. DIALOG CONTENT IMAGE
Logic for Presence vs Standard is much simpler now.
Standard CSS handles the width/height.
*/}
<LazyLoadImage
src={`${process.env.BASE_URL_IMG}${avatar}`}
alt="avatar"
effect="blur"
wrapperClassName="w-full h-full block" // Ensures the wrapper fills the dialog
className={cn(
"w-full", // Always full width of container
isPresence ? "h-auto object-contain" : "h-full object-cover shadow-sm border border-border"
)}
/>
</DialogContent>
</Dialog>
:
<div className={cn("relative h-9 w-9 sm:h-10 sm:w-10", className)}>
<Image
) : (
// 3. FALLBACK IMAGE
<span className={cn("inline-block h-9 w-9 sm:h-10 sm:w-10", className)}>
<LazyLoadImage
alt='avatar'
src='/assets/no-avatar.jpg'
fill
sizes={sizes}
className='shadow-sm rounded-full object-cover border border-border'
effect="blur"
wrapperClassName="w-full h-full"
className='w-full h-full shadow-sm rounded-full object-cover border border-border'
/>
</div>
}
</span>
)}
</>
);
}
export const Avatar: FC<Props> = ({ avatar, className, sizes = "(max-width: 640px) 36px, 40px" }) => {
export const Avatar: FC<Props> = ({ avatar, className }) => {
return (
<>
{avatar ?
// <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + avatar} className={cn("h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border cursor-pointer hover:scale-110 duration-200", className)} />
<div className={cn("relative h-9 w-9 sm:h-10 sm:w-10", className)}>
<Image src={`${process.env.BASE_URL_IMG}${avatar}`} alt="avatar"
fill // This replaces width/height
sizes={sizes} // Optimization (explained below)
className="rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
{avatar ? (
<span className={cn("inline-block h-9 w-9 sm:h-10 sm:w-10", className)}>
<LazyLoadImage
src={`${process.env.BASE_URL_IMG}${avatar}`}
alt="avatar"
effect="blur"
wrapperClassName="w-full h-full"
className="w-full h-full rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
/>
</div>
:
<Image alt='avatar' height={0} width={0} quality={50} src='/assets/no-avatar.jpg' className={cn('h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border', className)} />
}
</span>
) : (
<span className={cn("inline-block h-9 w-9 sm:h-10 sm:w-10", className)}>
<LazyLoadImage
alt='avatar'
src='/assets/no-avatar.jpg'
effect="blur"
wrapperClassName="w-full h-full"
className='w-full h-full shadow-sm rounded-full object-cover border border-border'
/>
</span>
)}
</>
);
}
+1 -1
View File
@@ -12,7 +12,7 @@ const nextConfig: NextConfig = {
'DEVICE_CODE': process.env.DEVICE_CODE,
},
images: {
unoptimized: true, // <--- ADD THIS LINE
// unoptimized: true, // <--- ADD THIS LINE
remotePatterns: [
new URL('https://36.66.3.44/**'),
new URL('https://his.nutech-integrasi.com/**'),