diff --git a/app/ui-account/client/accountIntegrations.html b/app/ui-account/client/accountIntegrations.html deleted file mode 100644 index ef894978795db..0000000000000 --- a/app/ui-account/client/accountIntegrations.html +++ /dev/null @@ -1,26 +0,0 @@ - - - {{> header sectionName="Integrations" fullpage=true}} - - - - - {{_ "WebDAV"}} - - - {{_ "WebDAV_Accounts"}} - - - {{#each webdavAccounts}} - {{getOptionValue this}} - {{/each}} - - - {{_ "Remove"}} - - - - - - - diff --git a/app/ui-account/client/accountIntegrations.js b/app/ui-account/client/accountIntegrations.js deleted file mode 100644 index a8d9d3916bcf2..0000000000000 --- a/app/ui-account/client/accountIntegrations.js +++ /dev/null @@ -1,37 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { Template } from 'meteor/templating'; -import toastr from 'toastr'; - -import { WebdavAccounts } from '../../models'; -import { modal } from '../../ui-utils'; -import { t } from '../../utils'; - -Template.accountIntegrations.helpers({ - webdavAccounts() { - return WebdavAccounts.find().fetch(); - }, - getOptionValue(account) { - return account.name || `${ account.username }@${ account.server_url.replace(/^https?\:\/\//i, '') }`; - }, -}); - -Template.accountIntegrations.events({ - 'click .webdav-account-remove'(e) { - e.preventDefault(); - const selectEl = document.getElementById('webdav-accounts'); - const { options } = selectEl; - const selectedOption = selectEl.value; - const optionIndex = Array.from(options).findIndex((option) => option.value === selectedOption); - - Meteor.call('removeWebdavAccount', selectedOption, function(error) { - if (error) { - return toastr.error(t(error.error)); - } - - toastr.success(t('webdav-account-removed')); - modal.close(); - }); - - selectEl.remove(optionIndex); - }, -}); diff --git a/app/ui-account/client/index.js b/app/ui-account/client/index.js index 836055a055104..6d435e98838c1 100644 --- a/app/ui-account/client/index.js +++ b/app/ui-account/client/index.js @@ -1,4 +1,2 @@ -import './accountIntegrations.html'; import './avatar/avatar.html'; -import './accountIntegrations'; import './avatar/avatar'; diff --git a/client/account/AccountIntegrationsPage.js b/client/account/AccountIntegrationsPage.js new file mode 100644 index 0000000000000..ee0869f90236c --- /dev/null +++ b/client/account/AccountIntegrationsPage.js @@ -0,0 +1,56 @@ +import React, { useMemo, useCallback } from 'react'; +import { Box, Select, Field, Button } from '@rocket.chat/fuselage'; + +import { useReactiveValue } from '../hooks/useReactiveValue'; +import { useTranslation } from '../contexts/TranslationContext'; +import { useMethod } from '../contexts/ServerContext'; +import { useToastMessageDispatch } from '../contexts/ToastMessagesContext'; +import { WebdavAccounts } from '../../app/models'; +import { useForm } from '../hooks/useForm'; +import Page from '../components/basic/Page'; + +const getWebdavAccounts = () => WebdavAccounts.find().fetch(); + +const getServerName = ({ name, server_url, username }) => name || `${ username }@${ server_url.replace(/^https?\:\/\//i, '') }`; + +const AccountIntegrationsPage = () => { + const t = useTranslation(); + const dispatchToastMessage = useToastMessageDispatch(); + + const accounts = useReactiveValue(getWebdavAccounts); + + const { values, handlers } = useForm({ selected: [] }); + + const { selected } = values; + const { handleSelected } = handlers; + + const removeWebdavAccount = useMethod('removeWebdavAccount'); + + const options = useMemo(() => accounts.map(({ _id, ...current }) => [_id, getServerName(current)]), [accounts]); + + const handleClickRemove = useCallback(() => { + try { + removeWebdavAccount(selected); + dispatchToastMessage({ type: 'success', message: t('webdav-account-removed') }); + } catch (error) { + dispatchToastMessage({ type: 'error', message: error }); + } + }, [dispatchToastMessage, removeWebdavAccount, selected, t]); + + return + + + + + {t('WebDAV_Accounts')} + + + {t('Remove')} + + + + + ; +}; + +export default AccountIntegrationsPage; diff --git a/client/account/AccountRoute.js b/client/account/AccountRoute.js index a8b2a0cc955a0..4112cd6b1ef2c 100644 --- a/client/account/AccountRoute.js +++ b/client/account/AccountRoute.js @@ -1,10 +1,12 @@ import React, { useEffect } from 'react'; import { SideNav } from '../../app/ui-utils'; -import NotAuthorizedPage from '../components/NotAuthorizedPage'; +import { useSetting } from '../contexts/SettingsContext'; import { usePermission } from '../contexts/AuthorizationContext'; import { useRouteParameter, useRoute } from '../contexts/RouterContext'; +import NotAuthorizedPage from '../components/NotAuthorizedPage'; import AccountProfilePage from './AccountProfilePage'; +import AccountIntegrationsPage from './AccountIntegrationsPage'; import AccountPreferencesPage from './preferences/AccountPreferencesPage'; import AccountSecurityPage from './security/AccountSecurityPage'; import AccountTokensPage from './tokens/AccountTokensPage'; @@ -21,6 +23,7 @@ const AccountRoute = () => { SideNav.openFlex(); }); + const webdavEnabled = useSetting('Webdav_Integration_Enabled'); const canCreateTokens = usePermission('create-personal-access-tokens'); if (page === 'profile') { @@ -35,6 +38,14 @@ const AccountRoute = () => { return ; } + if (page === 'integrations') { + if (!webdavEnabled) { + return ; + } + + return ; + } + if (page === 'tokens') { if (!canCreateTokens) { return ;