Skip to content

Commit

Permalink
Fixed API typo and webhook error
Browse files Browse the repository at this point in the history
  • Loading branch information
harshit078 committed Aug 28, 2024
1 parent c87ccfa commit b302dab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const SettingsDevelopersApiKeyDetail = () => {
{apiKeyToken ? (
<>
<H2Title
title="Api Key"
title="API Key"
description="Copy this key as it will only be visible this one time"
/>
<ApiKeyInput apiKey={apiKeyToken} />
Expand All @@ -147,8 +147,8 @@ export const SettingsDevelopersApiKeyDetail = () => {
) : (
<>
<H2Title
title="Api Key"
description="Regenerate an Api key"
title="API Key"
description="Regenerate an API key"
/>
<StyledInputContainer>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,36 @@ export const SettingsDevelopersWebhooksNew = () => {
targetUrl: '',
operation: '*.*',
});
const [isUrlValid, setIsUrlValid] = useState(true);

const { createOneRecord: createOneWebhook } = useCreateOneRecord<Webhook>({
objectNameSingular: CoreObjectNameSingular.Webhook,
});
const validateUrl = (url: string) => {
const urlPattern = new RegExp(
'^(https?:\\/\\/)?' +
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
'((\\d{1,3}\\.){3}\\d{1,3}))' +
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
'(\\?[;&a-z\\d%_.~+=-]*)?' +
'(\\#[-a-z\\d_]*)?$',
'i',
);
return !!urlPattern.test(url);
};

const handleSave = async () => {
setIsUrlValid(true);
const newWebhook = await createOneWebhook?.(formValues);

if (!newWebhook) {
return;
}
navigate(`/settings/developers/webhooks/${newWebhook.id}`);
};
const canSave = !!formValues.targetUrl && createOneWebhook;

const canSave = !!formValues.targetUrl && isUrlValid && createOneWebhook;

return (
<SubMenuTopBarContainer
Icon={IconCode}
Expand Down Expand Up @@ -63,6 +81,7 @@ export const SettingsDevelopersWebhooksNew = () => {
<TextInput
placeholder="URL"
value={formValues.targetUrl}
error={isUrlValid ? undefined : 'Please enter a valid URL'}
onKeyDown={(e) => {
if (e.key === 'Enter') {
handleSave();
Expand All @@ -73,6 +92,7 @@ export const SettingsDevelopersWebhooksNew = () => {
...prevState,
targetUrl: value,
}));
setIsUrlValid(validateUrl(value));
}}
fullWidth
/>
Expand Down

0 comments on commit b302dab

Please sign in to comment.