import { SaveOutlined } from '@ant-design/icons'; import { Col, Input, Space, Typography } from 'antd'; import { SOMETHING_WENT_WRONG } from 'constants/api'; import AddTags from 'container/NewDashboard/DashboardSettings/General/AddTags'; import { useUpdateDashboard } from 'hooks/dashboard/useUpdateDashboard'; import { useNotifications } from 'hooks/useNotifications'; import { useDashboard } from 'providers/Dashboard/Dashboard'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Button } from './styles'; function GeneralDashboardSettings(): JSX.Element { const { selectedDashboard, setSelectedDashboard } = useDashboard(); const updateDashboardMutation = useUpdateDashboard(); const selectedData = selectedDashboard?.data; const { title = '', tags = [], description = '' } = selectedData || {}; const [updatedTitle, setUpdatedTitle] = useState(title); const [updatedTags, setUpdatedTags] = useState(tags || []); const [updatedDescription, setUpdatedDescription] = useState( description || '', ); const { t } = useTranslation('common'); const { notifications } = useNotifications(); const onSaveHandler = (): void => { if (!selectedDashboard) return; updateDashboardMutation.mutateAsync( { ...selectedDashboard, data: { ...selectedDashboard.data, description: updatedDescription, tags: updatedTags, title: updatedTitle, }, }, { onSuccess: (updatedDashboard) => { if (updatedDashboard.payload) { setSelectedDashboard(updatedDashboard.payload); } }, onError: () => { notifications.error({ message: SOMETHING_WENT_WRONG, }); }, }, ); }; return (
Name setUpdatedTitle(e.target.value)} />
Description setUpdatedDescription(e.target.value)} />
Tags
); } export default GeneralDashboardSettings;