openreplay/frontend/app/components/Client/Sites/AddProjectButton/AddProjectButton.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

44 lines
1.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from 'react';
import { Tooltip } from 'UI';
import { Button } from 'antd';
import { useStore } from 'App/mstore';
import { observer } from 'mobx-react-lite';
import { useModal } from 'App/components/Modal';
import NewSiteForm from '../NewSiteForm';
import { TFunction } from 'i18next';
import { useTranslation } from 'react-i18next';
const PERMISSION_WARNING = (t: TFunction) =>
t('You dont have the permissions to perform this action.');
const LIMIT_WARNING = (t: TFunction) => t('You have reached site limit.');
function AddProjectButton({ isAdmin = false }: any) {
const { t } = useTranslation();
const { userStore, projectsStore } = useStore();
const init = projectsStore.initProject;
const { showModal, hideModal } = useModal();
const { limits } = userStore;
const canAddProject =
isAdmin && (limits.projects === -1 || limits.projects > 0);
const onClick = () => {
init({});
showModal(<NewSiteForm onClose={hideModal} />, { right: true });
};
return (
<Tooltip
title={`${!isAdmin ? PERMISSION_WARNING(t) : !canAddProject ? LIMIT_WARNING(t) : t('Add a Project')}`}
disabled={isAdmin || canAddProject}
>
<Button
type="primary"
onClick={onClick}
disabled={!canAddProject || !isAdmin}
>
{t('Add Project')}
</Button>
</Tooltip>
);
}
export default observer(AddProjectButton);