openreplay/frontend/app/components/Dashboard/components/CreateDashboardButton.tsx
Andrey Babushkin fd5c0c9747
Add lokalisation (#3092)
* applied eslint

* add locales and lint the project

* removed error boundary

* updated locales

* fix min files

* fix locales
2025-03-06 17:43:15 +01:00

45 lines
1.3 KiB
TypeScript

import React from 'react';
import { PlusOutlined } from '@ant-design/icons';
import { Button } from 'antd';
import { useStore } from 'App/mstore';
import { useHistory } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
interface Props {
disabled?: boolean;
}
function CreateDashboardButton({ disabled }: Props) {
const { t } = useTranslation();
const [dashboardCreating, setDashboardCreating] = React.useState(false);
const { projectsStore, dashboardStore } = useStore();
const { siteId } = projectsStore;
const history = useHistory();
const createNewDashboard = async () => {
setDashboardCreating(true);
dashboardStore.initDashboard();
await dashboardStore
.save(dashboardStore.dashboardInstance)
.then(async (syncedDashboard) => {
dashboardStore.selectDashboardById(syncedDashboard.dashboardId);
history.push(`/${siteId}/dashboard/${syncedDashboard.dashboardId}`);
})
.finally(() => {
setDashboardCreating(false);
});
};
return (
<Button
loading={dashboardCreating}
icon={<PlusOutlined />}
disabled={disabled}
type="primary"
onClick={createNewDashboard}
>
{t('Create Dashboard')}
</Button>
);
}
export default CreateDashboardButton;