feat(Editor): show webhook info in test substep

This commit is contained in:
Ali BARIN
2022-12-07 23:42:01 +01:00
parent 3c62f182ab
commit 346a706e41
8 changed files with 81 additions and 12 deletions

View File

@@ -6,22 +6,15 @@ import DialogContentText from '@mui/material/DialogContentText';
import Dialog from '@mui/material/Dialog'; import Dialog from '@mui/material/Dialog';
import LoadingButton from '@mui/lab/LoadingButton'; import LoadingButton from '@mui/lab/LoadingButton';
import { FieldValues, SubmitHandler } from 'react-hook-form'; import { FieldValues, SubmitHandler } from 'react-hook-form';
import { IJSONObject } from '@automatisch/types'; import type { IApp, IJSONObject, IField } from '@automatisch/types';
import useFormatMessage from 'hooks/useFormatMessage'; import useFormatMessage from 'hooks/useFormatMessage';
import computeAuthStepVariables from 'helpers/computeAuthStepVariables'; import computeAuthStepVariables from 'helpers/computeAuthStepVariables';
import { processStep } from 'helpers/authenticationSteps'; import { processStep } from 'helpers/authenticationSteps';
import InputCreator from 'components/InputCreator'; import InputCreator from 'components/InputCreator';
import type { IApp, IField } from '@automatisch/types'; import { generateExternalLink } from '../../helpers/translation-values';
import { Form } from './style'; import { Form } from './style';
const generateDocsLink = (link: string) => (str: string) =>
(
<a href={link} target="_blank">
{str}
</a>
);
type AddAppConnectionProps = { type AddAppConnectionProps = {
onClose: (response: Record<string, unknown>) => void; onClose: (response: Record<string, unknown>) => void;
application: IApp; application: IApp;
@@ -112,7 +105,7 @@ export default function AddAppConnection(
<Alert severity="info" sx={{ fontWeight: 300 }}> <Alert severity="info" sx={{ fontWeight: 300 }}>
{formatMessage('addAppConnection.callToDocs', { {formatMessage('addAppConnection.callToDocs', {
appName: name, appName: name,
docsLink: generateDocsLink(authDocUrl), docsLink: generateExternalLink(authDocUrl),
})} })}
</Alert> </Alert>
)} )}

View File

@@ -9,8 +9,9 @@ import LoadingButton from '@mui/lab/LoadingButton';
import { EditorContext } from 'contexts/Editor'; import { EditorContext } from 'contexts/Editor';
import useFormatMessage from 'hooks/useFormatMessage'; import useFormatMessage from 'hooks/useFormatMessage';
import JSONViewer from 'components/JSONViewer';
import { EXECUTE_FLOW } from 'graphql/mutations/execute-flow'; import { EXECUTE_FLOW } from 'graphql/mutations/execute-flow';
import JSONViewer from 'components/JSONViewer';
import WebhookUrlInfo from 'components/WebhookUrlInfo';
import FlowSubstepTitle from 'components/FlowSubstepTitle'; import FlowSubstepTitle from 'components/FlowSubstepTitle';
import type { IStep, ISubstep } from '@automatisch/types'; import type { IStep, ISubstep } from '@automatisch/types';
@@ -115,6 +116,8 @@ function TestSubstep(props: TestSubstepProps): React.ReactElement {
</Alert> </Alert>
)} )}
{step.webhookUrl && <WebhookUrlInfo webhookUrl={step.webhookUrl} />}
{hasNoOutput && ( {hasNoOutput && (
<Alert severity="warning" sx={{ mb: 1, width: '100%' }}> <Alert severity="warning" sx={{ mb: 1, width: '100%' }}>
<AlertTitle sx={{ fontWeight: 700 }}> <AlertTitle sx={{ fontWeight: 700 }}>

View File

@@ -0,0 +1,44 @@
import * as React from 'react';
import { FormattedMessage } from 'react-intl';
import Typography from '@mui/material/Typography';
import { generateExternalLink } from '../../helpers/translation-values';
import { WEBHOOK_DOCS } from '../../config/urls';
import TextField from '../TextField';
import { Alert } from './style';
type WebhookUrlInfoProps = {
webhookUrl: string;
};
function WebhookUrlInfo(props: WebhookUrlInfoProps): React.ReactElement {
const { webhookUrl } = props;
return (
<Alert icon={false} color="info">
<Typography variant="body2" textAlign="center">
<FormattedMessage id="webhookUrlInfo.title" />
</Typography>
<Typography variant="body1" textAlign="center">
<FormattedMessage id="webhookUrlInfo.description" />
</Typography>
<TextField
readOnly
clickToCopy={true}
name="webhookUrl"
fullWidth
defaultValue={webhookUrl}
helperText={
<FormattedMessage
id="webhookUrlInfo.helperText"
values={{ link: generateExternalLink(WEBHOOK_DOCS) }}
/>
}
/>
</Alert>
);
}
export default WebhookUrlInfo;

View File

@@ -0,0 +1,14 @@
import { styled } from '@mui/material/styles';
import MuiAlert, { alertClasses } from '@mui/material/Alert';
export const Alert = styled(MuiAlert)(({ theme }) => ({
[`&.${alertClasses.root}`]: {
fontWeight: 300,
width: '100%',
display: 'flex',
flexDirection: 'column'
},
[`& .${alertClasses.message}`]: {
width: '100%'
}
}));

View File

@@ -65,3 +65,6 @@ export const UPDATES = '/updates';
export const SETTINGS_PROFILE = `${SETTINGS}/${PROFILE}`; export const SETTINGS_PROFILE = `${SETTINGS}/${PROFILE}`;
export const DASHBOARD = FLOWS; export const DASHBOARD = FLOWS;
// External links
export const WEBHOOK_DOCS = 'https://automatisch.io/docs'

View File

@@ -11,6 +11,8 @@ export const GET_FLOW = gql`
type type
key key
appKey appKey
iconUrl
webhookUrl
status status
position position
connection { connection {

View File

@@ -0,0 +1,6 @@
export const generateExternalLink = (link: string) => (str: string) =>
(
<a href={link} target="_blank">
{str}
</a>
);

View File

@@ -87,5 +87,9 @@
"profileSettings.updatedPassword": "Your password has been updated.", "profileSettings.updatedPassword": "Your password has been updated.",
"profileSettings.updatePassword": "Update password", "profileSettings.updatePassword": "Update password",
"notifications.title": "Notifications", "notifications.title": "Notifications",
"notification.releasedAt": "Released {relativeDate}" "notification.releasedAt": "Released {relativeDate}",
"webhookUrlInfo.title": "Your webhook URL",
"webhookUrlInfo.description": "You'll need to configure your application with this webhook URL.",
"webhookUrlInfo.helperText": "We've generated a custom webhook URL for you to send requests to. <link>Learn more about webhooks</link>.",
"webhookUrlInfo.copy": "Copy"
} }