mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
Improve image fallbacks and status display
This commit adds reusable client and end-user fallback assets and updates profile cards, lists, and assignment views to render graceful placeholders when images are missing or fail to load. It also hardens the shared LazyImage component with fallback handling and improves BadgeStatus so it accepts object-like status values and still renders clean labels. Minor UX fixes include dismissing upload toasts after completion and clarifying end-user form labels/copy.
This commit is contained in:
@@ -11,7 +11,7 @@ import { Button } from '@/components/ui/button';
|
||||
import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { IClient } from '../../../types';
|
||||
import { IClient, CLIENT_FALLBACK_IMAGE } from '../../../types';
|
||||
|
||||
interface Props {
|
||||
client: IClient;
|
||||
@@ -37,9 +37,10 @@ export default function ClientProfileCard({ client, clientId }: Props) {
|
||||
<section aria-labelledby="client-name" className="rounded-2xl border border-border bg-card p-5 sm:p-7">
|
||||
<div className="flex flex-col gap-6 md:flex-row md:items-start md:justify-between">
|
||||
<div className="flex min-w-0 items-start gap-4 sm:gap-5">
|
||||
<div className="flex h-20 w-20 shrink-0 items-center justify-center overflow-hidden rounded-2xl border border-border bg-zinc-50 p-1.5 sm:h-24 sm:w-24 dark:bg-zinc-100">
|
||||
<div className="flex h-20 w-20 shrink-0 items-center justify-center overflow-hidden rounded-2xl border border-border bg-muted/30 p-1.5 sm:h-24 sm:w-24">
|
||||
<LazyImage
|
||||
src={client.photo}
|
||||
src={client.photo || CLIENT_FALLBACK_IMAGE}
|
||||
fallbackSrc={CLIENT_FALLBACK_IMAGE}
|
||||
alt={client.name}
|
||||
className="h-full w-full bg-transparent"
|
||||
imgClassName="object-contain"
|
||||
|
||||
+11
-9
@@ -22,7 +22,7 @@ import { Badge } from '@/components/ui/badge';
|
||||
import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { IClient } from '../../../types';
|
||||
import { IClient, CLIENT_FALLBACK_IMAGE, END_USER_FALLBACK_IMAGE } from '../../../types';
|
||||
import { IProjectAssignment, ProjectAssignmentWorkOrderDetail } from '../../../type.assignment';
|
||||
import { ManageTeam } from '../../../component/ManageTeam';
|
||||
import UpdateTimelineStatus from '../../../component/UpdateTimelineStatus';
|
||||
@@ -458,16 +458,18 @@ function initials(name?: string) {
|
||||
}
|
||||
|
||||
function PartyRow({ role, party, href }: { role: string; party?: { name?: string; photo?: string; description?: string | null; code?: string } | null; href?: string }) {
|
||||
const fallback = role.toLowerCase().includes('end user') ? END_USER_FALLBACK_IMAGE : CLIENT_FALLBACK_IMAGE;
|
||||
|
||||
const body = (
|
||||
<>
|
||||
<div className="relative h-12 w-12 shrink-0 overflow-hidden rounded-xl border border-border bg-background">
|
||||
{party?.photo ? (
|
||||
<LazyImage src={party.photo} alt={party.name ?? role} className="h-full w-full bg-transparent" imgClassName="object-contain p-1" />
|
||||
) : (
|
||||
<div className="flex h-full w-full items-center justify-center text-sm font-semibold text-muted-foreground">
|
||||
{initials(party?.name) || '-'}
|
||||
</div>
|
||||
)}
|
||||
<div className="relative h-12 w-12 shrink-0 overflow-hidden rounded-xl border border-border bg-muted/20 p-1">
|
||||
<LazyImage
|
||||
src={party?.photo || fallback}
|
||||
fallbackSrc={fallback}
|
||||
alt={party?.name ?? role}
|
||||
className="h-full w-full bg-transparent"
|
||||
imgClassName="object-contain"
|
||||
/>
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-xs text-muted-foreground">{role}</p>
|
||||
|
||||
+3
-3
@@ -11,7 +11,7 @@ import { Badge } from '@/components/ui/badge';
|
||||
import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { IClient } from '@/app/(dashboard)/task/types';
|
||||
import { IClient, CLIENT_FALLBACK_IMAGE } from '@/app/(dashboard)/task/types';
|
||||
import { IProject } from '@/app/(dashboard)/task/type.project';
|
||||
import { formatDate, formatSpan } from './format';
|
||||
|
||||
@@ -90,8 +90,8 @@ export default function ProjectHeader({ client, clientId, project }: Props) {
|
||||
href={`/task/client-detail/${clientId}`}
|
||||
className="group mt-6 flex items-center gap-3 rounded-xl border border-border/60 bg-muted/20 p-3 transition-colors hover:bg-muted/40"
|
||||
>
|
||||
<div className="flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-border bg-zinc-50 p-1 dark:bg-zinc-100">
|
||||
<LazyImage src={client.photo} alt={client.name} className="h-full w-full bg-transparent" imgClassName="object-contain" />
|
||||
<div className="flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-border bg-muted/30 p-1">
|
||||
<LazyImage src={client.photo || CLIENT_FALLBACK_IMAGE} fallbackSrc={CLIENT_FALLBACK_IMAGE} alt={client.name} className="h-full w-full bg-transparent" imgClassName="object-contain" />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-xs text-muted-foreground">Client</p>
|
||||
|
||||
@@ -110,6 +110,7 @@ const FormEndUser: FC<Props> = ({ data, onSuccess, onCancel }) => {
|
||||
} catch (error: any) {
|
||||
toast.error(`Failed uploading image.\n(${error?.response?.data?.code || error?.response?.status || '-'}) ${error?.response?.data?.message || error?.response?.statusText || error?.message}`, { id: toastId });
|
||||
} finally {
|
||||
toast.dismiss(toastId)
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
@@ -149,9 +150,9 @@ const FormEndUser: FC<Props> = ({ data, onSuccess, onCancel }) => {
|
||||
<AlertDialog open={true}>
|
||||
<AlertDialogContent className='max-h-[90vh] overflow-y-auto'>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>EndUser Information</AlertDialogTitle>
|
||||
<AlertDialogTitle>End User Information</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Enter the basic details of the EndUser.
|
||||
Enter the basic details of the End User.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<Form {...form}>
|
||||
@@ -160,7 +161,7 @@ const FormEndUser: FC<Props> = ({ data, onSuccess, onCancel }) => {
|
||||
<FormField control={form.control} name='name'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>EndUser Name <span className='text-red-600 font-bold'>*</span></FormLabel>
|
||||
<FormLabel>End User Name <span className='text-red-600 font-bold'>*</span></FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} placeholder='e.g. PT ASDP Indonesia Ferry' />
|
||||
</FormControl>
|
||||
@@ -235,7 +236,7 @@ const FormEndUser: FC<Props> = ({ data, onSuccess, onCancel }) => {
|
||||
<AlertDialogCancel onClick={onCancel} disabled={isLoading} type='button'>Cancel</AlertDialogCancel>
|
||||
<Button type="submit" disabled={isLoading}>
|
||||
{isLoading && <Loader2 className='animate-spin' />}
|
||||
Save EndUser
|
||||
Save End User
|
||||
</Button>
|
||||
</AlertDialogFooter>
|
||||
</form>
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
} from "@/components/ui/hover-card";
|
||||
import { cn } from '@/lib/utils';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { IClient } from '../../types';
|
||||
import { IClient, CLIENT_FALLBACK_IMAGE } from '../../types';
|
||||
|
||||
interface ClientGridProps {
|
||||
clients: IClient[];
|
||||
@@ -49,7 +49,8 @@ export default function ClientGrid({ clients, onEdit, onDelete }: ClientGridProp
|
||||
<div className="relative h-40 bg-muted/20 dark:bg-zinc-800/30 overflow-hidden flex items-center justify-center p-3 border-b border-border/50">
|
||||
<Link href={`/task/client-detail/${client.id}`} className="w-full h-full flex items-center justify-center">
|
||||
<LazyImage
|
||||
src={client.photo!}
|
||||
src={client.photo || CLIENT_FALLBACK_IMAGE}
|
||||
fallbackSrc={CLIENT_FALLBACK_IMAGE}
|
||||
alt={client.name}
|
||||
className="w-full h-full max-h-32 bg-transparent"
|
||||
imgClassName="object-contain p-1 group-hover:scale-105 transition-transform duration-500"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IClient } from '../../types';
|
||||
import { IClient, CLIENT_FALLBACK_IMAGE } from '../../types';
|
||||
import { motion } from 'motion/react';
|
||||
import { Card900, CardContent } from '@/components/ui/card';
|
||||
import Link from 'next/link';
|
||||
@@ -50,7 +50,8 @@ export default function ClientList({ clients, onEdit, onDelete }: ClientListProp
|
||||
<div className="relative w-full lg:w-56 xl:w-64 h-48 lg:h-auto min-h-40 bg-muted/20 dark:bg-zinc-800/20 shrink-0 overflow-hidden flex items-center justify-center p-3 border-b lg:border-b-0 lg:border-r border-border/50">
|
||||
<Link href={`/task/client-detail/${client.id}`} className="w-full h-full flex items-center justify-center">
|
||||
<LazyImage
|
||||
src={client.photo!}
|
||||
src={client.photo || CLIENT_FALLBACK_IMAGE}
|
||||
fallbackSrc={CLIENT_FALLBACK_IMAGE}
|
||||
alt={client.name}
|
||||
className="w-full h-full max-h-36 bg-transparent"
|
||||
imgClassName="object-contain p-1 group-hover:scale-105 transition-transform duration-500"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { IProjectAssignment } from '../../type.assignment';
|
||||
import { CLIENT_FALLBACK_IMAGE, END_USER_FALLBACK_IMAGE } from '../../types';
|
||||
import { motion } from 'motion/react';
|
||||
import { Card900 } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
@@ -205,16 +206,13 @@ export default function AssignmentGrid({
|
||||
href={`/task/client-detail/${assignment.client.id}`}
|
||||
className="flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-muted/60 hover:bg-muted border border-border/50 text-foreground transition-colors text-[11px] max-w-full min-w-0"
|
||||
>
|
||||
{assignment.client.photo ?
|
||||
<LazyImage
|
||||
src={assignment.client.photo}
|
||||
alt={assignment.client.name}
|
||||
className="w-3 h-3 rounded-xs bg-transparent shrink-0"
|
||||
imgClassName="object-cover"
|
||||
/>
|
||||
:
|
||||
<BuildingComplex className="w-3 h-3 text-muted-foreground shrink-0" />
|
||||
}
|
||||
<LazyImage
|
||||
src={assignment.client.photo || CLIENT_FALLBACK_IMAGE}
|
||||
fallbackSrc={CLIENT_FALLBACK_IMAGE}
|
||||
alt={assignment.client.name}
|
||||
className="w-3.5 h-3.5 rounded-xs bg-transparent shrink-0"
|
||||
imgClassName="object-contain"
|
||||
/>
|
||||
<span className="text-muted-foreground shrink-0">Client:</span>
|
||||
<span className="font-medium truncate max-w-32.5 sm:max-w-45">{assignment.client.name}</span>
|
||||
</Link>
|
||||
@@ -222,17 +220,14 @@ export default function AssignmentGrid({
|
||||
|
||||
{assignment.end_user?.name && (
|
||||
<div className="flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-muted/40 border border-border/40 text-foreground text-[11px] max-w-full min-w-0">
|
||||
<div className="w-3.5 h-3.5 rounded-xs overflow-hidden shrink-0 bg-secondary">
|
||||
{assignment.end_user?.photo ? (
|
||||
<LazyImage
|
||||
src={assignment.end_user.photo ? assignment.end_user.photo : '/assets/ilustration.png'}
|
||||
alt={assignment.end_user.name}
|
||||
className="w-full h-full bg-transparent"
|
||||
imgClassName="object-contain"
|
||||
/>
|
||||
) : (
|
||||
<Building className="w-3 h-3 text-muted-foreground" />
|
||||
)}
|
||||
<div className="w-3.5 h-3.5 rounded-xs overflow-hidden shrink-0 bg-transparent">
|
||||
<LazyImage
|
||||
src={assignment.end_user?.photo || END_USER_FALLBACK_IMAGE}
|
||||
fallbackSrc={END_USER_FALLBACK_IMAGE}
|
||||
alt={assignment.end_user.name}
|
||||
className="w-full h-full bg-transparent"
|
||||
imgClassName="object-contain"
|
||||
/>
|
||||
</div>
|
||||
<span className="text-muted-foreground shrink-0">End User:</span>
|
||||
<span className="font-medium truncate max-w-32.5 sm:max-w-45">{assignment.end_user.name}</span>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { IUser } from "@/app/admin/administration/user/component/type";
|
||||
|
||||
export const CLIENT_FALLBACK_IMAGE = '/assets/illustrations/client_fallback.webp';
|
||||
export const END_USER_FALLBACK_IMAGE = '/assets/illustrations/end_user_fallback.webp';
|
||||
|
||||
export type IEndUser = {
|
||||
id?: string;
|
||||
code?: string
|
||||
|
||||
@@ -1,37 +1,49 @@
|
||||
import { Badge, STATUS_BADGE_MAP } from "@/components/ui/badge"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export function formatStatusText(status?: string): string {
|
||||
if (!status) return "";
|
||||
const trimmed = status.trim();
|
||||
if (!trimmed) return "";
|
||||
|
||||
// Tetap UPPERCASE jika seluruh teks status hanya 3 huruf (SIT, UAT, PTR, dll) atau akronim BAST
|
||||
const upperAcronyms = new Set(["SIT", "UAT", "PTR", "BAST", "POC", "WIP", "WO", "IM"]);
|
||||
if (trimmed.length === 3 || upperAcronyms.has(trimmed.toUpperCase())) {
|
||||
return trimmed.toUpperCase();
|
||||
}
|
||||
|
||||
// Capitalize setiap kata untuk teks status lainnya
|
||||
return trimmed
|
||||
.split(/\s+/)
|
||||
.map(word => {
|
||||
if (!word) return "";
|
||||
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
||||
})
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
export default function BadgeStatus({ status, className }: { status: string, className?: string }) { // e.g. status = "UAT"
|
||||
const formatted = formatStatusText(status);
|
||||
const lookupKey = (status || "").toLowerCase().trim();
|
||||
|
||||
return (
|
||||
<Badge
|
||||
variant={STATUS_BADGE_MAP[lookupKey] || "default"}
|
||||
className={cn("text-[10px] font-semibold tracking-wide px-2 py-0.5", className)}
|
||||
>
|
||||
{formatted}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
import { Badge, STATUS_BADGE_MAP } from "@/components/ui/badge"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function extractStatusString(status?: any): string {
|
||||
if (!status) return "";
|
||||
if (typeof status === "string") return status;
|
||||
if (typeof status === "object") {
|
||||
return status.name || status.status || status.title || "";
|
||||
}
|
||||
return String(status);
|
||||
}
|
||||
|
||||
export function formatStatusText(status?: any): string {
|
||||
const raw = extractStatusString(status);
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed) return "";
|
||||
|
||||
// Tetap UPPERCASE jika seluruh teks status hanya 3 huruf (SIT, UAT, PTR, dll) atau akronim BAST
|
||||
const upperAcronyms = new Set(["SIT", "UAT", "PTR", "BAST", "POC", "WIP", "WO", "IM"]);
|
||||
if (trimmed.length === 3 || upperAcronyms.has(trimmed.toUpperCase())) {
|
||||
return trimmed.toUpperCase();
|
||||
}
|
||||
|
||||
// Capitalize setiap kata untuk teks status lainnya
|
||||
return trimmed
|
||||
.split(/\s+/)
|
||||
.map(word => {
|
||||
if (!word) return "";
|
||||
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
||||
})
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
export default function BadgeStatus({ status, className }: { status: any, className?: string }) { // e.g. status = "UAT"
|
||||
const raw = extractStatusString(status);
|
||||
const formatted = formatStatusText(raw);
|
||||
if (!formatted) return null;
|
||||
|
||||
const lookupKey = raw.toLowerCase().trim();
|
||||
|
||||
return (
|
||||
<Badge
|
||||
variant={STATUS_BADGE_MAP[lookupKey] || "default"}
|
||||
className={cn("text-[10px] font-semibold tracking-wide px-2 py-0.5", className)}
|
||||
>
|
||||
{formatted}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use client"
|
||||
"use client";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useState, useRef, useEffect } from "react";
|
||||
@@ -8,31 +8,47 @@ export function LazyImage({
|
||||
alt,
|
||||
className,
|
||||
imgClassName,
|
||||
fallbackSrc,
|
||||
}: {
|
||||
src: string;
|
||||
src?: string | null;
|
||||
alt: string;
|
||||
className?: string;
|
||||
imgClassName?: string;
|
||||
fallbackSrc?: string;
|
||||
}) {
|
||||
const effectiveSrc = src || fallbackSrc || "";
|
||||
const [currentSrc, setCurrentSrc] = useState(effectiveSrc);
|
||||
const [isLoaded, setIsLoaded] = useState(false);
|
||||
const imgRef = useRef<HTMLImageElement>(null);
|
||||
|
||||
// Check if the image is already loaded from the cache
|
||||
useEffect(() => {
|
||||
if (imgRef.current?.complete) {
|
||||
const nextSrc = src || fallbackSrc || "";
|
||||
setCurrentSrc(nextSrc);
|
||||
setIsLoaded(false);
|
||||
}, [src, fallbackSrc]);
|
||||
|
||||
useEffect(() => {
|
||||
if (imgRef.current?.complete && (imgRef.current?.naturalWidth ?? 0) > 0) {
|
||||
setIsLoaded(true);
|
||||
}
|
||||
}, [src]); // Re-run this check if the src prop changes
|
||||
}, [currentSrc]);
|
||||
|
||||
const handleError = () => {
|
||||
if (fallbackSrc && currentSrc !== fallbackSrc) {
|
||||
setCurrentSrc(fallbackSrc);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cn("relative overflow-hidden bg-secondary/50", className)}>
|
||||
<img
|
||||
ref={imgRef}
|
||||
src={src}
|
||||
src={currentSrc}
|
||||
alt={alt}
|
||||
loading="lazy"
|
||||
referrerPolicy="no-referrer"
|
||||
onLoad={() => setIsLoaded(true)}
|
||||
onError={handleError}
|
||||
className={cn(
|
||||
"w-full h-full object-cover transition-all duration-700 ease-in-out",
|
||||
imgClassName,
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
Reference in New Issue
Block a user