import { useState } from 'react'; import { Modal, TextInput, Textarea, Button, Stack } from '@mantine/core'; import { notifications } from '@mantine/notifications'; import { useMutation } from '@tanstack/react-query'; import api from '../../services/api'; interface IdeaModalProps { opened: boolean; onClose: () => void; } export function IdeaModal({ opened, onClose }: IdeaModalProps) { const [title, setTitle] = useState(''); const [description, setDescription] = useState(''); const submitIdea = useMutation({ mutationFn: async () => { const { data } = await api.post('/ideas', { title, description }); return data; }, onSuccess: () => { notifications.show({ message: 'Idea submitted — thank you!', color: 'green' }); setTitle(''); setDescription(''); onClose(); }, onError: (err: any) => { notifications.show({ message: err.response?.data?.message || 'Failed to submit idea', color: 'red', }); }, }); const handleClose = () => { setTitle(''); setDescription(''); onClose(); }; return ( setTitle(e.currentTarget.value)} maxLength={255} />