Repository navigation
Expand file tree
/
Copy pathcreate.tsx
More file actions
70 lines (66 loc) · 2.14 KB
/
Copy pathcreate.tsx
File metadata and controls
70 lines (66 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type { NextPage } from 'next';
import { Webhook } from '@webhookModels/Webhook';
import { createWebhook } from '@webhookServices/WebhookService';
import React from 'react';
import { useForm } from 'react-hook-form';
import Link from 'next/link';
import { useRouter } from 'next/router';
import WebhookInformation from '@webhookComponents/WebhookInformation';
import { WEBHOOKS_URL } from 'constants/Common';
import { handleCreatingResponse } from '@commonServices/ResponseStatusHandlingService';
import EventInformation from '@webhookComponents/EventInformation';
import { ContentType } from '@webhookModels/ContentType';
const WebhookCreate: NextPage = () => {
const router = useRouter();
const {
register,
handleSubmit,
getValues,
formState: { errors },
setValue,
trigger,
} = useForm<Webhook>();
const handleSubmitWebhook = async (webhook: Webhook) => {
let payload: Webhook = {
id: 0,
payloadUrl: webhook.payloadUrl,
contentType: ContentType.APPLICATION_JSON,
secret: webhook.secret,
isActive: webhook.isActive,
events: webhook.events,
};
let response = await createWebhook(payload);
handleCreatingResponse(response);
router.replace(WEBHOOKS_URL);
};
return (
<>
<div className="row mt-5">
<div className="col-md-8">
<h2>Create Webhook</h2>
<form onSubmit={handleSubmit(handleSubmitWebhook)}>
<WebhookInformation
register={register}
errors={errors}
setValue={setValue}
trigger={trigger}
/>
<label className="form-label" htmlFor="events">
Events
</label>
<EventInformation setValue={setValue} getValue={getValues} />
<button className="btn btn-primary" type="submit">
Save
</button>
<Link href="/webhook">
<button className="btn btn-primary" style={{ background: 'red', marginLeft: '30px' }}>
Cancel
</button>
</Link>
</form>
</div>
</div>
</>
);
};
export default WebhookCreate;