Skip to content

Commit a208c87

Browse files
update: webhooks
1 parent 79c94fc commit a208c87

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

dashboard/src/components/UpdateWebhookModal.tsx

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
webhookVerifiedStatus,
3232
} from '../constants';
3333
import { capitalizeFirstLetter, validateURI } from '../utils';
34-
import { AddWebhook, EditWebhook } from '../graphql/mutation';
34+
import { AddWebhook, EditWebhook, TestEndpoint } from '../graphql/mutation';
3535
import { rest } from 'lodash';
3636
import { BiCheckCircle, BiError, BiErrorCircle } from 'react-icons/bi';
3737

@@ -118,6 +118,12 @@ const UpdateWebhookModal = ({
118118
headerInputType: string = WebhookInputHeaderFields.KEY,
119119
headerIndex: number = 0
120120
) => {
121+
if (
122+
verifiedStatus !== webhookVerifiedStatus.PENDING &&
123+
inputType !== WebhookInputDataFields.ENABLED
124+
) {
125+
setVerifiedStatus(webhookVerifiedStatus.PENDING);
126+
}
121127
switch (inputType) {
122128
case WebhookInputDataFields.EVENT_NAME:
123129
setWebhook({ ...webhook, [inputType]: value });
@@ -163,6 +169,9 @@ const UpdateWebhookModal = ({
163169
}
164170
};
165171
const updateHeaders = (operation: string, index: number = 0) => {
172+
if (verifiedStatus !== webhookVerifiedStatus.PENDING) {
173+
setVerifiedStatus(webhookVerifiedStatus.PENDING);
174+
}
166175
switch (operation) {
167176
case ArrayInputOperations.APPEND:
168177
setWebhook({
@@ -217,9 +226,7 @@ const UpdateWebhookModal = ({
217226
)
218227
);
219228
};
220-
const saveData = async () => {
221-
if (!validateData()) return;
222-
setLoading(true);
229+
const getParams = () => {
223230
let params: any = {
224231
[WebhookInputDataFields.EVENT_NAME]:
225232
webhook[WebhookInputDataFields.EVENT_NAME],
@@ -239,6 +246,12 @@ const UpdateWebhookModal = ({
239246
params[WebhookInputDataFields.HEADERS] = headers;
240247
}
241248
}
249+
return params;
250+
};
251+
const saveData = async () => {
252+
if (!validateData()) return;
253+
setLoading(true);
254+
const params = getParams();
242255
let res: any = {};
243256
if (
244257
view === UpdateWebhookModalViews.Edit &&
@@ -317,6 +330,18 @@ const UpdateWebhookModal = ({
317330
}
318331
}
319332
}, [isOpen]);
333+
const verifyEndpoint = async () => {
334+
if (!validateData()) return;
335+
setVerifyingEndpoint(true);
336+
const { [WebhookInputDataFields.ENABLED]: _, ...params } = getParams();
337+
const res = await client.mutation(TestEndpoint, { params }).toPromise();
338+
if (res.data?._test_endpoint?.response?.success) {
339+
setVerifiedStatus(webhookVerifiedStatus.VERIFIED);
340+
} else {
341+
setVerifiedStatus(webhookVerifiedStatus.NOT_VERIFIED);
342+
}
343+
setVerifyingEndpoint(false);
344+
};
320345
return (
321346
<>
322347
{view === UpdateWebhookModalViews.ADD ? (
@@ -531,7 +556,7 @@ const UpdateWebhookModal = ({
531556
: 'red'
532557
}
533558
variant="outline"
534-
onClick={saveData}
559+
onClick={verifyEndpoint}
535560
isLoading={verifyingEndpoint}
536561
isDisabled={!validateData()}
537562
marginRight="5"
@@ -545,7 +570,11 @@ const UpdateWebhookModal = ({
545570
)
546571
}
547572
>
548-
Test Endpoint
573+
{verifiedStatus === webhookVerifiedStatus.VERIFIED
574+
? 'Endpoint Verified'
575+
: verifiedStatus === webhookVerifiedStatus.PENDING
576+
? 'Test Endpoint'
577+
: 'Endpoint Not Verified'}
549578
</Button>
550579
<Button
551580
colorScheme="blue"

dashboard/src/graphql/mutation/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,12 @@ export const DeleteWebhook = `
103103
}
104104
}
105105
`;
106+
107+
export const TestEndpoint = `
108+
mutation testEndpoint($params: TestEndpointRequest!) {
109+
_test_endpoint(params: $params) {
110+
http_status
111+
response
112+
}
113+
}
114+
`;

0 commit comments

Comments
 (0)