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 { Copy, Trash } from 'lucide-react';
|
|
|
|
import { useParams } from 'next/navigation';
|
|
|
|
import { toast } from 'sonner';
|
2024-02-15 02:30:10 +00:00
|
|
|
|
2024-02-16 01:49:19 +00:00
|
|
|
import { Skeleton } from '@/components/ui/skeleton';
|
|
|
|
import { deleteCard } from '@/actions/delete-card';
|
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
import { useAction } from '@/hooks/use-action';
|
|
|
|
import { copyCard } from '@/actions/copy-card';
|
2024-02-15 02:30:10 +00:00
|
|
|
|
2024-02-16 01:49:19 +00:00
|
|
|
import { CardWithList } from '@/types';
|
|
|
|
import { useCardModal } from '@/hooks/use-card-modal';
|
2024-03-15 21:01:41 +00:00
|
|
|
import { DatePicker } from '@/components/ui/date-picker';
|
2024-02-15 02:30:10 +00:00
|
|
|
|
|
|
|
interface ActionsProps {
|
|
|
|
data: CardWithList;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Actions = ({ data }: ActionsProps) => {
|
|
|
|
const params = useParams();
|
|
|
|
const cardModal = useCardModal();
|
|
|
|
|
|
|
|
const { execute: executeDeleteCard, isLoading: isLoadingDelete } = useAction(
|
|
|
|
deleteCard,
|
|
|
|
{
|
|
|
|
onSuccess: () => {
|
|
|
|
toast.success(`Card "${data.title}" deleted`);
|
|
|
|
cardModal.onClose();
|
|
|
|
},
|
|
|
|
onError: (error) => {
|
|
|
|
toast.error(error);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const { execute: executeCopyCard, isLoading: isLoadingCopy } = useAction(
|
|
|
|
copyCard,
|
|
|
|
{
|
|
|
|
onSuccess: () => {
|
|
|
|
toast.success(`Card "${data.title}" copied`);
|
|
|
|
cardModal.onClose();
|
|
|
|
},
|
|
|
|
onError: (error) => {
|
|
|
|
toast.error(error);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const onCopy = () => {
|
|
|
|
const boardId = params.boardId as string;
|
|
|
|
|
|
|
|
executeCopyCard({
|
|
|
|
id: data.id,
|
|
|
|
boardId,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const onDelete = () => {
|
|
|
|
const boardId = params.boardId as string;
|
|
|
|
|
|
|
|
executeDeleteCard({
|
|
|
|
id: data.id,
|
|
|
|
boardId,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2024-02-16 01:49:19 +00:00
|
|
|
<div className='mt-2 space-y-2'>
|
|
|
|
<p className='text-xs font-semibold'>Actions</p>
|
2024-02-15 02:30:10 +00:00
|
|
|
<Button
|
|
|
|
onClick={onCopy}
|
|
|
|
disabled={isLoadingCopy}
|
2024-02-16 01:49:19 +00:00
|
|
|
variant='gray'
|
|
|
|
className='w-full justify-start'
|
|
|
|
size='inline'
|
2024-02-15 02:30:10 +00:00
|
|
|
>
|
2024-02-16 01:49:19 +00:00
|
|
|
<Copy className='mr-2 h-4 w-4' />
|
2024-02-15 02:30:10 +00:00
|
|
|
Copy
|
|
|
|
</Button>
|
2024-03-15 21:01:41 +00:00
|
|
|
<DatePicker
|
2024-11-08 01:29:32 +00:00
|
|
|
type='dueDate'
|
2024-03-15 21:01:41 +00:00
|
|
|
variant='gray'
|
|
|
|
className='w-full justify-start text-black'
|
|
|
|
size='inline'
|
|
|
|
placeholder='Add Due Date'
|
|
|
|
afterSelectText='Due '
|
|
|
|
boardId={params.boardId as string}
|
|
|
|
card={data}
|
|
|
|
/>
|
2024-11-08 01:29:32 +00:00
|
|
|
<DatePicker
|
|
|
|
type='startedAtDate'
|
|
|
|
variant='gray'
|
|
|
|
className='w-full justify-start text-black'
|
|
|
|
size='inline'
|
|
|
|
placeholder='Add Started Date'
|
|
|
|
afterSelectText='Started '
|
|
|
|
boardId={params.boardId as string}
|
|
|
|
card={data}
|
|
|
|
/>
|
2024-02-15 02:30:10 +00:00
|
|
|
<Button
|
|
|
|
onClick={onDelete}
|
|
|
|
disabled={isLoadingDelete}
|
2024-02-16 01:49:19 +00:00
|
|
|
variant='gray'
|
|
|
|
className='w-full justify-start text-destructive'
|
|
|
|
size='inline'
|
2024-02-15 02:30:10 +00:00
|
|
|
>
|
2024-02-16 01:49:19 +00:00
|
|
|
<Trash className='mr-2 h-4 w-4' />
|
2024-02-15 02:30:10 +00:00
|
|
|
Delete
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Actions.Skeleton = function ActionsSkeleton() {
|
|
|
|
return (
|
2024-02-16 01:49:19 +00:00
|
|
|
<div className='mt-2 space-y-2'>
|
|
|
|
<Skeleton className='h-4 w-20 bg-neutral-200' />
|
|
|
|
<Skeleton className='h-8 w-full bg-neutral-200' />
|
|
|
|
<Skeleton className='h-8 w-full bg-neutral-200' />
|
2024-02-15 02:30:10 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|