diff --git a/components/edit-collective/sections/Webhooks.js b/components/edit-collective/sections/Webhooks.js index c3e34d14b29..8644ff474dd 100644 --- a/components/edit-collective/sections/Webhooks.js +++ b/components/edit-collective/sections/Webhooks.js @@ -2,9 +2,8 @@ import React from 'react'; import PropTypes from 'prop-types'; import { graphql } from '@apollo/client/react/hoc'; import { InfoCircle } from '@styled-icons/boxicons-regular/InfoCircle'; -import { Add } from '@styled-icons/material/Add'; -import { Close } from '@styled-icons/material/Close'; import { cloneDeep, difference, get, pick } from 'lodash'; +import { PlusCircle, Save, Trash, WebhookIcon } from 'lucide-react'; import memoizeOne from 'memoize-one'; import { FormattedMessage, injectIntl } from 'react-intl'; import { isURL } from 'validator'; @@ -17,15 +16,14 @@ import { gqlV1 } from '../../../lib/graphql/helpers'; import { i18nWebhookEventType } from '../../../lib/i18n/webhook-event-type'; import { compose } from '../../../lib/utils'; -import { Box, Flex } from '../../Grid'; import { getI18nLink } from '../../I18nFormatters'; import Loading from '../../Loading'; import MessageBox from '../../MessageBox'; -import StyledButton from '../../StyledButton'; -import StyledHr from '../../StyledHr'; import StyledInputGroup from '../../StyledInputGroup'; import StyledSelect from '../../StyledSelect'; -import { Label, P, Span } from '../../Text'; +import { Button } from '../../ui/Button'; +import { Separator } from '../../ui/Separator'; +import { toast } from '../../ui/useToast'; import WebhookActivityInfoModal, { hasWebhookEventInfo } from './WebhookActivityInfoModal'; @@ -49,7 +47,6 @@ class Webhooks extends React.Component { webhooks: cloneDeep(this.getWebhooksFromProps(props)), isLoaded: false, status: null, - error: '', }; } @@ -170,7 +167,8 @@ class Webhooks extends React.Component { }, 3000); } catch (e) { const message = getErrorFromGraphqlException(e).message; - this.setState({ status: 'error', error: message }); + toast({ variant: 'error', message }); + this.setState({ status: null }); } }; @@ -178,37 +176,32 @@ class Webhooks extends React.Component { const { intl, data } = this.props; return ( - - - +
+
+
+ +
+ + + +
+ +
+ +
+
+ + this.editWebhook(index, 'webhookUrl', target.value)} /> - - -
+
+ - + +
({ label: i18nWebhookEventType(intl, eventType), value: eventType, @@ -234,18 +227,18 @@ class Webhooks extends React.Component { onChange={({ value }) => this.editWebhook(index, 'type', value)} /> {hasWebhookEventInfo(webhook.type) && ( - this.setState({ moreInfoModal: webhook.type })} - ml={2} > - - + + )} - - +
+
{data.Collective.isHost && [WebhookEvents.COLLECTIVE_EXPENSE_CREATED, WebhookEvents.COLLECTIVE_TRANSACTION_CREATED].includes( webhook.type, @@ -264,15 +257,14 @@ class Webhooks extends React.Component { onClose={() => this.setState({ moreInfoModal: null })} /> )} - - +
+ ); }; render() { - const { webhooks, status, error } = this.state; + const { webhooks, status } = this.state; const { data } = this.props; - const webhooksCount = webhooks.length; if (data.loading) { return ; @@ -280,7 +272,7 @@ class Webhooks extends React.Component { return (
-

+

-

+

-
{webhooks.map(this.renderWebhook)}
+ - {webhooksCount > 0 && } - - - this.addWebhook()} - > - - {' '} +
+

- - - - {status === 'error' && ( - - {error} - +

+ +
+ + {webhooks.length === 0 ? ( +
+ +

+ +

+
+ ) : ( +
{webhooks.map(this.renderWebhook)}
)} - - - {status === 'saved' ? ( - - - - ) : ( - - )} - - +
); }