[FIX] Integration section crashing opening in My Account (#24068)

pull/24168/head
Douglas Fabris 3 years ago committed by GitHub
parent 178ed82b29
commit 03841cede3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      client/contexts/ServerContext/methods.ts
  2. 34
      client/views/account/AccountIntegrationsPage.tsx
  3. 1
      packages/rocketchat-i18n/i18n/en.i18n.json

@ -1,3 +1,5 @@
import type { DeleteWriteOpResultObject } from 'mongodb';
import { IRoom } from '../../../definition/IRoom';
import { IUser } from '../../../definition/IUser';
import { AddWebdavAccountMethod } from './methods/addWebdavAccount';
@ -108,7 +110,7 @@ export type ServerMethods = {
'refreshOAuthService': (...args: any[]) => any;
'registerUser': (...args: any[]) => any;
'removeOAuthService': (...args: any[]) => any;
'removeWebdavAccount': (...args: any[]) => any;
'removeWebdavAccount': (accountId: string) => DeleteWriteOpResultObject;
'removeCannedResponse': (...args: any[]) => any;
'replayOutgoingIntegration': (...args: any[]) => any;
'requestDataDownload': (...args: any[]) => any;

@ -1,7 +1,8 @@
import { Box, Select, Field, Button } from '@rocket.chat/fuselage';
import React, { useMemo, useCallback } from 'react';
import { Box, Select, SelectOptions, Field, Button } from '@rocket.chat/fuselage';
import React, { useMemo, useCallback, ReactElement } from 'react';
import { WebdavAccounts } from '../../../app/models/client';
import { IWebdavAccount } from '../../../definition/IWebdavAccount';
import Page from '../../components/Page';
import { useMethod } from '../../contexts/ServerContext';
import { useToastMessageDispatch } from '../../contexts/ToastMessagesContext';
@ -9,29 +10,30 @@ import { useTranslation } from '../../contexts/TranslationContext';
import { useForm } from '../../hooks/useForm';
import { useReactiveValue } from '../../hooks/useReactiveValue';
const getWebdavAccounts = () => WebdavAccounts.find().fetch();
type WebdavAccountIntegration = Omit<IWebdavAccount, 'userId' | 'password' | '_updatedAt'>;
const getServerName = ({ name, server_url, username }) => name || `${username}@${server_url.replace(/^https?\:\/\//i, '')}`;
const getWebdavAccounts = (): Array<WebdavAccountIntegration> => WebdavAccounts.find().fetch();
const AccountIntegrationsPage = () => {
const getServerName = ({ name, serverURL, username }: Omit<WebdavAccountIntegration, '_id'>): string =>
name || `${username}@${serverURL?.replace(/^https?\:\/\//i, '')}`;
const AccountIntegrationsPage = (): ReactElement => {
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 {
values: { selected },
handlers: { handleSelected },
} = useForm({ selected: [] });
const options: SelectOptions = useMemo(() => accounts.map(({ _id, ...current }) => [_id, getServerName(current)]), [accounts]);
const handleClickRemove = useCallback(() => {
try {
removeWebdavAccount(selected);
dispatchToastMessage({ type: 'success', message: t('webdav-account-removed') });
removeWebdavAccount(selected as string);
dispatchToastMessage({ type: 'success', message: t('Webdav_account_removed') });
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
@ -45,7 +47,7 @@ const AccountIntegrationsPage = () => {
<Field>
<Field.Label>{t('WebDAV_Accounts')}</Field.Label>
<Field.Row>
<Select options={options} onChange={handleSelected} value={selected} placeholder={t('Select_an_option')} />
<Select options={options} onChange={handleSelected} value={selected as string} placeholder={t('Select_an_option')} />
<Button primary danger onClick={handleClickRemove}>
{t('Remove')}
</Button>

@ -4662,6 +4662,7 @@
"Webdav_Password": "WebDAV Password",
"Webdav_Server_URL": "WebDAV Server Access URL",
"Webdav_Username": "WebDAV Username",
"Webdav_account_removed": "WebDAV account removed",
"webdav-account-saved": "WebDAV account saved",
"webdav-account-updated": "WebDAV account updated",
"Webhook_Details": "WebHook Details",

Loading…
Cancel
Save