Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

fix: issue and module link validation (#5994)

Aaryan Khandelwal89588d445157
diff --git a/web/core/components/issues/issue-detail-widgets/links/helper.tsx b/web/core/components/issues/issue-detail-widgets/links/helper.tsx
index f0a6ed3163..4669528cd3 100644
--- a/web/core/components/issues/issue-detail-widgets/links/helper.tsx
+++ b/web/core/components/issues/issue-detail-widgets/links/helper.tsx
@@ -27,6 +27,7 @@ export const useLinkOperations = (workspaceSlug: string, projectId: string, issu
type: TOAST_TYPE.ERROR,
title: "Link not created",
});
+ throw error;
}
},
update: async (linkId: string, data: Partial<TIssueLink>) => {
@@ -44,6 +45,7 @@ export const useLinkOperations = (workspaceSlug: string, projectId: string, issu
type: TOAST_TYPE.ERROR,
title: "Link not updated",
});
+ throw error;
}
},
remove: async (linkId: string) => {
diff --git a/web/core/components/issues/issue-detail/links/create-update-link-modal.tsx b/web/core/components/issues/issue-detail/links/create-update-link-modal.tsx
index ab0d80f1b2..99e350c613 100644
--- a/web/core/components/issues/issue-detail/links/create-update-link-modal.tsx
+++ b/web/core/components/issues/issue-detail/links/create-update-link-modal.tsx
@@ -7,8 +7,6 @@ import { Controller, useForm } from "react-hook-form";
import type { TIssueLinkEditableFields } from "@plane/types";
// plane ui
import { Button, Input, ModalCore } from "@plane/ui";
-// helpers
-import { checkURLValidity } from "@/helpers/string.helper";
// hooks
import { useIssueDetail } from "@/hooks/store";
// types
@@ -48,14 +46,18 @@ export const IssueLinkCreateUpdateModal: FC<TIssueLinkCreateEditModal> = observe
const onClose = () => {
setIssueLinkData(null);
- reset();
if (handleOnClose) handleOnClose();
};
const handleFormSubmit = async (formData: TIssueLinkCreateFormFieldOptions) => {
- if (!formData || !formData.id) await linkOperations.create({ title: formData.title, url: formData.url });
- else await linkOperations.update(formData.id as string, { title: formData.title, url: formData.url });
- onClose();
+ const parsedUrl = formData.url.startsWith("http") ? formData.url : `http://${formData.url}`;
+ try {
+ if (!formData || !formData.id) await linkOperations.create({ title: formData.title, url: parsedUrl });
+ else await linkOperations.update(formData.id, { title: formData.title, url: parsedUrl });
+ onClose();
+ } catch (error) {
+ console.error("error", error);
+ }
};
useEffect(() => {
@@ -77,7 +79,6 @@ export const IssueLinkCreateUpdateModal: FC<TIssueLinkCreateEditModal> = observe
name="url"
rules={{
required: "URL is required",
- validate: (value) => checkURLValidity(value) || "URL is invalid",
}}
render={({ field: { value, onChange, ref } }) => (
<Input
diff --git a/web/core/components/issues/issue-detail/links/root.tsx b/web/core/components/issues/issue-detail/links/root.tsx
index 7b1908c35a..b2fb4fb552 100644
--- a/web/core/components/issues/issue-detail/links/root.tsx
+++ b/web/core/components/issues/issue-detail/links/root.tsx
@@ -58,6 +58,7 @@ export const IssueLinkRoot: FC<TIssueLinkRoot> = (props) => {
type: TOAST_TYPE.ERROR,
title: "Link not created",
});
+ throw error;
}
},
update: async (linkId: string, data: Partial<TIssueLink>) => {
@@ -76,6 +77,7 @@ export const IssueLinkRoot: FC<TIssueLinkRoot> = (props) => {
type: TOAST_TYPE.ERROR,
title: "Link not updated",
});
+ throw error;
}
},
remove: async (linkId: string) => {
diff --git a/web/core/components/modules/links/create-update-modal.tsx b/web/core/components/modules/links/create-update-modal.tsx
index 2700dc9803..0018b2eb66 100644
--- a/web/core/components/modules/links/create-update-modal.tsx
+++ b/web/core/components/modules/links/create-update-modal.tsx
@@ -6,8 +6,6 @@ import { Controller, useForm } from "react-hook-form";
import type { ILinkDetails, ModuleLink } from "@plane/types";
// plane ui
import { Button, Input, ModalCore, setToast, TOAST_TYPE } from "@plane/ui";
-// helpers
-import { checkURLValidity } from "@/helpers/string.helper";
type Props = {
createLink: (formData: ModuleLink) => Promise<void>;
@@ -39,9 +37,10 @@ export const CreateUpdateModuleLinkModal: FC<Props> = (props) => {
};
const handleFormSubmit = async (formData: ModuleLink) => {
+ const parsedUrl = formData.url.startsWith("http") ? formData.url : `http://${formData.url}`;
const payload = {
title: formData.title,
- url: formData.url,
+ url: parsedUrl,
};
try {
@@ -92,7 +91,6 @@ export const CreateUpdateModuleLinkModal: FC<Props> = (props) => {
name="url"
rules={{
required: "URL is required",
- validate: (value) => checkURLValidity(value) || "URL is invalid",
}}
render={({ field: { value, onChange, ref } }) => (
<Input