tasko/app/(platform)/(dashboard)/board/[boardId]/_components/board-options.tsx

89 lines
2.3 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 { MoreHorizontal, X } from 'lucide-react';
import { toast } from 'sonner';
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
import { deleteBoard } from '@/actions/delete-board';
import { useAction } from '@/hooks/use-action';
import { Button } from '@/components/ui/button';
2024-02-15 02:30:10 +00:00
import {
Popover,
PopoverClose,
PopoverContent,
PopoverTrigger,
2024-02-16 01:49:19 +00:00
} from '@/components/ui/popover';
2024-03-30 03:15:34 +00:00
import { copyBoard } from '@/actions/copy-board';
import { BoardUpdateImage } from './board-update-image';
2024-02-15 02:30:10 +00:00
interface BoardOptionsProps {
id: string;
}
export const BoardOptions = ({ id }: BoardOptionsProps) => {
2024-03-30 03:15:34 +00:00
const { execute: executeDelete, isLoading: isLoadingDelete } = useAction(
deleteBoard,
{
onError: (error) => {
toast.error(error);
},
}
);
const { execute: executeCopy, isLoading: isLoadingCopy } = useAction(
copyBoard,
{
onError: (error) => {
toast.error(error);
},
}
);
2024-02-15 02:30:10 +00:00
const onDelete = () => {
2024-03-30 03:15:34 +00:00
executeDelete({ id });
};
const onCopy = () => {
executeCopy({ id });
2024-02-15 02:30:10 +00:00
};
return (
<Popover>
<PopoverTrigger asChild>
2024-02-16 01:49:19 +00:00
<Button className='h-auto w-auto p-2' variant='transparent'>
<MoreHorizontal className='h-4 w-4' />
2024-02-15 02:30:10 +00:00
</Button>
</PopoverTrigger>
2024-02-16 01:49:19 +00:00
<PopoverContent className='px-0 pb-3 pt-3' side='bottom' align='start'>
<div className='pb-4 text-center text-sm font-medium text-neutral-600'>
2024-02-15 02:30:10 +00:00
Board Actions
</div>
<PopoverClose asChild>
<Button
2024-02-16 01:49:19 +00:00
className='absolute right-2 top-2 h-auto w-auto p-2 text-neutral-600'
variant='ghost'
2024-02-15 02:30:10 +00:00
>
2024-02-16 01:49:19 +00:00
<X className='h-4 w-4' />
2024-02-15 02:30:10 +00:00
</Button>
</PopoverClose>
2024-03-30 03:15:34 +00:00
<Button
variant='ghost'
onClick={onCopy}
disabled={isLoadingCopy}
className='h-auto w-full justify-start rounded-none p-2 px-5 text-sm font-normal text-neutral-600'
>
Copy this Board
2024-03-30 03:15:34 +00:00
</Button>
<BoardUpdateImage boardId={id} />
2024-02-15 02:30:10 +00:00
<Button
2024-02-16 01:49:19 +00:00
variant='ghost'
2024-02-15 02:30:10 +00:00
onClick={onDelete}
2024-03-30 03:15:34 +00:00
disabled={isLoadingDelete}
2024-02-16 01:49:19 +00:00
className='h-auto w-full justify-start rounded-none p-2 px-5 text-sm font-normal text-destructive hover:text-destructive'
2024-02-15 02:30:10 +00:00
>
Delete this Board
2024-02-15 02:30:10 +00:00
</Button>
</PopoverContent>
</Popover>
);
};