import useApi from 'hooks/useApi'; import { useRef, useState } from 'react'; import { Button, Dropdown, Form, FormButtons, FormRow, Item, SubmitButton } from 'react-basics'; import WebsiteTags from './WebsiteTags'; import useMessages from 'hooks/useMessages'; export default function WebsiteAddTeamForm({ teamId, onSave, onClose }) { const { formatMessage, labels } = useMessages(); const { get, post, useQuery, useMutation } = useApi(); const { mutate, error } = useMutation(data => post(`/teams/${teamId}/websites`, data)); const { data: websites } = useQuery(['websites'], () => get('/websites')); const [newWebsites, setNewWebsites] = useState([]); const formRef = useRef(); const handleSubmit = () => { mutate( { websiteIds: newWebsites }, { onSuccess: async () => { onSave(); onClose(); }, }, ); }; const handleAddWebsite = value => { if (!newWebsites.some(a => a === value)) { const nextValue = [...newWebsites]; nextValue.push(value); setNewWebsites(nextValue); } }; const handleRemoveWebsite = value => { const newValue = newWebsites.filter(a => a !== value); setNewWebsites(newValue); }; return ( <>
> ); }