60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
'use client';
|
|
|
|
import { ReadonlyTimeRange } from './time-range/readonly';
|
|
import { getBadge } from '@/components/shared/status';
|
|
import type * as GQL from '@repo/graphql/types';
|
|
import { Avatar, AvatarFallback, AvatarImage } from '@repo/ui/components/ui/avatar';
|
|
import { formatDate } from '@repo/utils/datetime-format';
|
|
import Link from 'next/link';
|
|
|
|
type OrderComponentProps = GQL.OrderFieldsFragment & {
|
|
avatarSource?: 'client' | 'master';
|
|
showDate?: boolean;
|
|
};
|
|
|
|
type OrderCustomer = GQL.CustomerFieldsFragment;
|
|
|
|
export function OrderCard({
|
|
avatarSource,
|
|
documentId,
|
|
showDate,
|
|
...order
|
|
}: Readonly<OrderComponentProps>) {
|
|
const services = order?.services.map((service) => service?.name).join(', ');
|
|
const date = order?.slot?.date;
|
|
|
|
const customer = avatarSource === 'master' ? order?.slot?.master : order?.client;
|
|
|
|
return (
|
|
<Link href={`/orders/${documentId}`} rel="noopener noreferrer">
|
|
<div className="flex items-center justify-between rounded-2xl bg-background p-4 px-6 dark:bg-primary/5">
|
|
<div className="flex flex-col">
|
|
<div className="flex items-center gap-4">
|
|
{customer && <CustomerAvatar customer={customer} />}
|
|
<div className="flex flex-col">
|
|
<ReadonlyTimeRange timeEnd={order?.time_end} timeStart={order?.time_start} />
|
|
<span className="truncate text-xs text-muted-foreground">
|
|
{showDate ? `${formatDate(date).user('DD.MM.YYYY')} • ` : ''}
|
|
{services}
|
|
</span>
|
|
</div>
|
|
{/* <span className="text-xs text-foreground">{clientName}</span> */}
|
|
</div>
|
|
</div>
|
|
{order?.state && getBadge(order.state)}
|
|
</div>
|
|
</Link>
|
|
);
|
|
}
|
|
|
|
function CustomerAvatar({ customer }: { readonly customer: OrderCustomer }) {
|
|
if (!customer) return null;
|
|
|
|
return (
|
|
<Avatar>
|
|
<AvatarImage alt={customer.name} src={customer.photoUrl || ''} />
|
|
<AvatarFallback>{customer.name.charAt(0)}</AvatarFallback>
|
|
</Avatar>
|
|
);
|
|
}
|