Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: validate webhook URL #4144

Merged
merged 3 commits into from
Feb 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TextInput } from '@/ui/input/components/TextInput';
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
import { Section } from '@/ui/layout/section/components/Section';
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
import { isURL } from '~/utils/is-url';

export const SettingsDevelopersWebhooksNew = () => {
const navigate = useNavigate();
Expand All @@ -23,11 +24,20 @@ export const SettingsDevelopersWebhooksNew = () => {
targetUrl: '',
operation: '*.*',
});
const [errorMessage, setErrorMessage] = useState<string | undefined>();
const { createOneRecord: createOneWebhook } = useCreateOneRecord<Webhook>({
objectNameSingular: CoreObjectNameSingular.Webhook,
});
const handleSave = async () => {
setErrorMessage(undefined);

if (!isURL(formValues.targetUrl)) {
setErrorMessage('Invalid webhook URL');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rostaklein now that we are not throwing anymore, we need to return and not actually create the webhook

return;
}

const newWebhook = await createOneWebhook?.(formValues);

if (!newWebhook) {
return;
}
Expand Down Expand Up @@ -66,6 +76,7 @@ export const SettingsDevelopersWebhooksNew = () => {
targetUrl: value,
}));
}}
error={errorMessage}
fullWidth
/>
</Section>
Expand Down
Loading