2022-12-11 00:00:11 +01:00
|
|
|
import { Title } from '@mantine/core';
|
2022-12-10 22:14:31 +01:00
|
|
|
import { useTranslation } from 'next-i18next';
|
|
|
|
|
import { openContextModalGeneric } from '../../../../tools/mantineModalManagerExtensions';
|
|
|
|
|
import { IntegrationsType } from '../../../../types/integration';
|
|
|
|
|
import { TileBaseType } from '../../../../types/tile';
|
2022-12-11 00:00:11 +01:00
|
|
|
import { GenericTileMenu } from '../GenericTileMenu';
|
2022-12-10 22:14:31 +01:00
|
|
|
import { IntegrationRemoveModalInnerProps } from '../IntegrationRemoveModal';
|
|
|
|
|
import {
|
|
|
|
|
IntegrationEditModalInnerProps,
|
|
|
|
|
integrationModuleTranslationsMap,
|
|
|
|
|
IntegrationOptionLabels,
|
|
|
|
|
IntegrationOptions,
|
|
|
|
|
} from '../IntegrationsEditModal';
|
|
|
|
|
|
2022-12-17 00:28:46 +09:00
|
|
|
export type IntegrationChangePositionModalInnerProps = {
|
|
|
|
|
integration: keyof IntegrationsType;
|
|
|
|
|
module: TileBaseType;
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-10 22:14:31 +01:00
|
|
|
interface IntegrationsMenuProps<TIntegrationKey extends keyof IntegrationsType> {
|
|
|
|
|
integration: TIntegrationKey;
|
|
|
|
|
module: TileBaseType | undefined;
|
|
|
|
|
options: IntegrationOptions<TIntegrationKey> | undefined;
|
|
|
|
|
labels: IntegrationOptionLabels<IntegrationOptions<TIntegrationKey>>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const IntegrationsMenu = <TIntegrationKey extends keyof IntegrationsType>({
|
|
|
|
|
integration,
|
|
|
|
|
options,
|
|
|
|
|
labels,
|
|
|
|
|
module,
|
|
|
|
|
}: IntegrationsMenuProps<TIntegrationKey>) => {
|
|
|
|
|
const { t } = useTranslation(integrationModuleTranslationsMap.get(integration));
|
|
|
|
|
|
|
|
|
|
if (!module) return null;
|
|
|
|
|
|
|
|
|
|
const handleDeleteClick = () => {
|
|
|
|
|
openContextModalGeneric<IntegrationRemoveModalInnerProps>({
|
|
|
|
|
modal: 'integrationRemove',
|
|
|
|
|
title: <Title order={4}>{t('descriptor.remove.title')}</Title>,
|
|
|
|
|
innerProps: {
|
|
|
|
|
integration,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleChangeSizeClick = () => {
|
|
|
|
|
openContextModalGeneric<IntegrationChangePositionModalInnerProps>({
|
2022-12-11 13:12:39 +01:00
|
|
|
modal: 'changeIntegrationPositionModal',
|
2022-12-10 22:14:31 +01:00
|
|
|
size: 'xl',
|
|
|
|
|
title: null,
|
|
|
|
|
innerProps: {
|
|
|
|
|
integration,
|
|
|
|
|
module,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleEditClick = () => {
|
|
|
|
|
openContextModalGeneric<IntegrationEditModalInnerProps<TIntegrationKey>>({
|
|
|
|
|
modal: 'integrationOptions',
|
|
|
|
|
title: <Title order={4}>{t('descriptor.settings.title')}</Title>,
|
|
|
|
|
innerProps: {
|
|
|
|
|
integration,
|
|
|
|
|
options,
|
|
|
|
|
labels,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2022-12-11 00:00:11 +01:00
|
|
|
<GenericTileMenu
|
|
|
|
|
handleClickEdit={handleEditClick}
|
|
|
|
|
handleClickChangePosition={handleChangeSizeClick}
|
|
|
|
|
handleClickDelete={handleDeleteClick}
|
|
|
|
|
displayEdit={options !== undefined}
|
|
|
|
|
/>
|
2022-12-10 22:14:31 +01:00
|
|
|
);
|
|
|
|
|
};
|