2022-09-09 17:43:25 +05:30
|
|
|
import { SaveOutlined } from '@ant-design/icons';
|
2023-11-15 15:33:45 +05:30
|
|
|
import { Col, Input, Space, Typography } from 'antd';
|
2023-10-08 23:21:17 +05:30
|
|
|
import { SOMETHING_WENT_WRONG } from 'constants/api';
|
2022-09-09 17:43:25 +05:30
|
|
|
import AddTags from 'container/NewDashboard/DashboardSettings/General/AddTags';
|
2023-10-08 23:21:17 +05:30
|
|
|
import { useUpdateDashboard } from 'hooks/dashboard/useUpdateDashboard';
|
|
|
|
|
import { useNotifications } from 'hooks/useNotifications';
|
|
|
|
|
import { useDashboard } from 'providers/Dashboard/Dashboard';
|
|
|
|
|
import { useState } from 'react';
|
2022-09-09 17:43:25 +05:30
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
|
|
import { Button } from './styles';
|
|
|
|
|
|
2023-10-08 23:21:17 +05:30
|
|
|
function GeneralDashboardSettings(): JSX.Element {
|
|
|
|
|
const { selectedDashboard, setSelectedDashboard } = useDashboard();
|
|
|
|
|
|
|
|
|
|
const updateDashboardMutation = useUpdateDashboard();
|
|
|
|
|
|
|
|
|
|
const selectedData = selectedDashboard?.data;
|
2022-09-09 17:43:25 +05:30
|
|
|
|
2023-10-08 23:21:17 +05:30
|
|
|
const { title = '', tags = [], description = '' } = selectedData || {};
|
2022-09-09 17:43:25 +05:30
|
|
|
|
|
|
|
|
const [updatedTitle, setUpdatedTitle] = useState<string>(title);
|
|
|
|
|
const [updatedTags, setUpdatedTags] = useState<string[]>(tags || []);
|
|
|
|
|
const [updatedDescription, setUpdatedDescription] = useState(
|
|
|
|
|
description || '',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { t } = useTranslation('common');
|
|
|
|
|
|
2023-10-08 23:21:17 +05:30
|
|
|
const { notifications } = useNotifications();
|
|
|
|
|
|
|
|
|
|
const onSaveHandler = (): void => {
|
|
|
|
|
if (!selectedDashboard) return;
|
|
|
|
|
|
|
|
|
|
updateDashboardMutation.mutateAsync(
|
|
|
|
|
{
|
|
|
|
|
...selectedDashboard,
|
2022-09-09 17:43:25 +05:30
|
|
|
data: {
|
2023-10-08 23:21:17 +05:30
|
|
|
...selectedDashboard.data,
|
2022-09-09 17:43:25 +05:30
|
|
|
description: updatedDescription,
|
|
|
|
|
tags: updatedTags,
|
|
|
|
|
title: updatedTitle,
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-10-08 23:21:17 +05:30
|
|
|
{
|
|
|
|
|
onSuccess: (updatedDashboard) => {
|
|
|
|
|
if (updatedDashboard.payload) {
|
|
|
|
|
setSelectedDashboard(updatedDashboard.payload);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onError: () => {
|
|
|
|
|
notifications.error({
|
|
|
|
|
message: SOMETHING_WENT_WRONG,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
};
|
2022-09-09 17:43:25 +05:30
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Col>
|
|
|
|
|
<Space direction="vertical" style={{ width: '100%' }}>
|
|
|
|
|
<div>
|
|
|
|
|
<Typography style={{ marginBottom: '0.5rem' }}>Name</Typography>
|
|
|
|
|
<Input
|
|
|
|
|
value={updatedTitle}
|
|
|
|
|
onChange={(e): void => setUpdatedTitle(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<Typography style={{ marginBottom: '0.5rem' }}>Description</Typography>
|
|
|
|
|
<Input.TextArea
|
2023-11-15 15:33:45 +05:30
|
|
|
rows={5}
|
2022-09-09 17:43:25 +05:30
|
|
|
value={updatedDescription}
|
|
|
|
|
onChange={(e): void => setUpdatedDescription(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<Typography style={{ marginBottom: '0.5rem' }}>Tags</Typography>
|
|
|
|
|
<AddTags tags={updatedTags} setTags={setUpdatedTags} />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
2023-10-08 23:21:17 +05:30
|
|
|
<Button
|
2023-11-15 15:33:45 +05:30
|
|
|
style={{
|
|
|
|
|
margin: '16px 0',
|
|
|
|
|
}}
|
2023-10-08 23:21:17 +05:30
|
|
|
disabled={updateDashboardMutation.isLoading}
|
|
|
|
|
loading={updateDashboardMutation.isLoading}
|
|
|
|
|
icon={<SaveOutlined />}
|
|
|
|
|
onClick={onSaveHandler}
|
|
|
|
|
type="primary"
|
|
|
|
|
>
|
2022-09-09 17:43:25 +05:30
|
|
|
{t('save')}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</Space>
|
|
|
|
|
</Col>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 23:21:17 +05:30
|
|
|
export default GeneralDashboardSettings;
|