Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
harshit078 committed Aug 29, 2024
1 parent 8649de4 commit e08d253
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const SettingsDevelopersApiKeyDetail = () => {
confirmationValue="yes"
isOpen={isDeleteApiKeyModalOpen}
setIsOpen={setIsDeleteApiKeyModalOpen}
title="Delete Api key"
title="Delete API key"
subtitle={
<>
Please type "yes" to confirm you want to delete this API Key. Be
Expand All @@ -228,7 +228,7 @@ export const SettingsDevelopersApiKeyDetail = () => {
confirmationValue="yes"
isOpen={isRegenerateKeyModalOpen}
setIsOpen={setIsRegenerateKeyModalOpen}
title="Regenerate an Api key"
title="Regenerate an API key"
subtitle={
<>
If you’ve lost this key, you can regenerate it, but be aware that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,20 @@ export const SettingsDevelopersWebhooksNew = () => {

const validateUrl = (url: string) => {
const urlPattern = new RegExp(
'^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'^(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', // fragment locator
'i',
);
return !!urlPattern.test(url);
};

const handleSave = async () => {
const trimmedUrl = formValues.targetUrl.trim();

if (!trimmedUrl) {
setIsUrlValid(false);
throw new Error('Endpoint URL cannot be empty');
}

if (!validateUrl(trimmedUrl)) {
setIsUrlValid(false);
return;
Expand Down Expand Up @@ -98,16 +93,15 @@ export const SettingsDevelopersWebhooksNew = () => {
error={isUrlValid ? undefined : 'Please enter a valid URL'}
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault(); // Prevent form submission or other default behaviors
handleSave(); // Manually trigger the save process, which includes validation
e.preventDefault();
handleSave();
}
}}
onChange={(value) => {
setFormValues((prevState) => ({
...prevState,
targetUrl: value,
}));
setIsUrlValid(validateUrl(value));
}}
fullWidth
/>
Expand Down

0 comments on commit e08d253

Please sign in to comment.