diff --git a/src/webapp/features/cards/components/addCardDrawer/AddCardDrawer.tsx b/src/webapp/features/cards/components/addCardDrawer/AddCardDrawer.tsx new file mode 100644 index 00000000..8e6b4e44 --- /dev/null +++ b/src/webapp/features/cards/components/addCardDrawer/AddCardDrawer.tsx @@ -0,0 +1,140 @@ +import { + Button, + Container, + Drawer, + Grid, + Group, + Stack, + Textarea, + TextInput, +} from '@mantine/core'; +import { useForm } from '@mantine/form'; + +import { notifications } from '@mantine/notifications'; +import useAddCard from '../../lib/mutations/useAddCard'; +import CollectionSelector from '@/features/collections/components/collectionSelector/CollectionSelector'; +import { Suspense, useState } from 'react'; +import CollectionSelectorSkeleton from '@/features/collections/components/collectionSelector/Skeleton.CollectionSelector'; + +interface Props { + isOpen: boolean; + onClose: () => void; + selectedCollection?: { id: string; name: string; description?: string }; +} + +export default function AddCardDrawer(props: Props) { + const initialCollections = props.selectedCollection + ? [props.selectedCollection] + : []; + const [selectedCollections, setSelectedCollections] = + useState<{ id: string; name: string; description?: string }[]>( + initialCollections, + ); + const addCard = useAddCard(); + + const form = useForm({ + initialValues: { + url: '', + note: '', + collections: initialCollections, + }, + }); + + const handleCreateCollection = (e: React.FormEvent) => { + e.preventDefault(); + + addCard.mutate( + { + url: form.getValues().url, + note: form.getValues().note, + collectionIds: selectedCollections.map((c) => c.id), + }, + { + onSuccess: () => { + notifications.show({ + message: 'Added card.', + }); + props.onClose(); + }, + onError: () => { + notifications.show({ + message: 'Could not add card.', + }); + }, + onSettled: () => { + form.reset(); + }, + }, + ); + }; + + return ( + + + + New Card + + + +
+ + + + + + +