prevent from save doubled subscriber url (#3811)

Co-authored-by: Adam Garbowski <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-08-31 03:41:23 +00:00
1 parent 0c8847fb87
commit b151ccd4c6
5 files changed
+24

No files matched your search

@@ -1,3 +1,4 @@
import { Webhook } from "@prisma/client";
import { useEffect, useState } from "react";
import { Controller, useForm } from "react-hook-form";
@@ -20,10 +21,12 @@ export default function WebhookDialogForm(props: {
defaultValues?: TWebhook;
app?: string;
handleClose: () => void;
webhooks: Webhook[];
}) {
const { t } = useLocale();
const utils = trpc.useContext();
const appId = props.app;
const webhooks = props.webhooks;
const triggers = !appId
? WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP["core"]
@@ -45,6 +48,10 @@ export default function WebhookDialogForm(props: {
const hasSecretKey = !!defaultValues.secret;
const currentSecret = defaultValues.secret;
const subscriberUrlReserved = (subscriberUrl: string, id: string): boolean => {
return !!webhooks.find((webhook) => webhook.subscriberUrl === subscriberUrl && webhook.id !== id);
};
const form = useForm({
defaultValues,
});
@@ -64,6 +71,10 @@ export default function WebhookDialogForm(props: {
data-testid="WebhookDialogForm"
form={form}
handleSubmit={async (event) => {
if (subscriberUrlReserved(event.subscriberUrl, event.id)) {
showToast(t("webhook_subscriber_url_reserved"), "error");
return;
}
const e = changeSecret
? { ...event, eventTypeId: props.eventTypeId, appId }
: { ...event, secret: currentSecret, eventTypeId: props.eventTypeId, appId };
@@ -74,6 +74,7 @@ export default function WebhookListContainer(props: WebhookListContainerType) {
<DialogContent>
<WebhookDialogForm
app={props.appId}
webhooks={data}
eventTypeId={props.eventTypeId}
handleClose={() => setNewWebhookModal(false)}
/>
@@ -86,6 +87,7 @@ export default function WebhookListContainer(props: WebhookListContainerType) {
<WebhookDialogForm
app={props.appId}
key={editing.id}
webhooks={data}
eventTypeId={props.eventTypeId || undefined}
handleClose={() => setEditModalOpen(false)}
defaultValues={editing}
@@ -1040,6 +1040,7 @@
"company_size": "Company size",
"what_help_needed": "What do you need help with?",
"variable_format": "Variable format",
"webhook_subscriber_url_reserved": "Webhook subscriber url is already defined",
"custom_input_as_variable_info": "Ignore all special characters of the additional input label (use only letters and numbers), use uppercase for all letters and replace whitespaces with underscores.",
"using_additional_inputs_as_variables": "How to use additional inputs as variables?",
"download_desktop_app": "Download desktop app",