tasko/components/modals/card-modal/index.tsx

56 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-02-16 01:49:19 +00:00
'use client';
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
import { useQuery } from '@tanstack/react-query';
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
import { CardWithList } from '@/types';
import { fetcher } from '@/lib/fetcher';
import { AuditLog } from '@prisma/client';
import { useCardModal } from '@/hooks/use-card-modal';
import { Dialog, DialogContent } from '@/components/ui/dialog';
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
import { Header } from './header';
import { Description } from './description';
import { Actions } from './actions';
import { Activity } from './activity';
2024-02-15 02:30:10 +00:00
export const CardModal = () => {
const id = useCardModal((state) => state.id);
const isOpen = useCardModal((state) => state.isOpen);
const onClose = useCardModal((state) => state.onClose);
const { data: cardData } = useQuery<CardWithList>({
2024-02-16 01:49:19 +00:00
queryKey: ['card', id],
2024-02-15 02:30:10 +00:00
queryFn: () => fetcher(`/api/cards/${id}`),
});
const { data: auditLogsData } = useQuery<AuditLog[]>({
2024-02-16 01:49:19 +00:00
queryKey: ['card-logs', id],
2024-02-15 02:30:10 +00:00
queryFn: () => fetcher(`/api/cards/${id}/logs`),
});
return (
<Dialog open={isOpen} onOpenChange={onClose}>
<DialogContent>
{!cardData ? <Header.Skeleton /> : <Header data={cardData} />}
2024-02-16 01:49:19 +00:00
<div className='grid grid-cols-1 md:grid-cols-4 md:gap-4'>
<div className='col-span-3'>
<div className='w-full space-y-6'>
2024-02-15 02:30:10 +00:00
{!cardData ? (
<Description.Skeleton />
) : (
<Description data={cardData} />
)}
{!auditLogsData ? (
<Activity.Skeleton />
) : (
<Activity items={auditLogsData} />
)}
</div>
</div>
{!cardData ? <Actions.Skeleton /> : <Actions data={cardData} />}
</div>
</DialogContent>
</Dialog>
);
};