Skip to content
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
48 changes: 37 additions & 11 deletions web/core/components/issues/issue-modal/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
const [labelModal, setLabelModal] = useState(false);
const [selectedParentIssue, setSelectedParentIssue] = useState<ISearchIssueResponse | null>(null);
const [gptAssistantModal, setGptAssistantModal] = useState(false);
const [isMoving, setIsMoving] = useState<boolean>(false);

// refs
const editorRef = useRef<EditorRefApi>(null);
Expand All @@ -113,8 +114,12 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {

// store hooks
const { getProjectById } = useProject();
const { getIssueTypeIdOnProjectChange, getActiveAdditionalPropertiesLength, handlePropertyValuesValidation } =
useIssueModal();
const {
getIssueTypeIdOnProjectChange,
getActiveAdditionalPropertiesLength,
handlePropertyValuesValidation,
handleCreateUpdatePropertyValues,
} = useIssueModal();
const { isMobile } = usePlatformOS();
const { moveIssue } = useWorkspaceDraftIssues();

Expand Down Expand Up @@ -236,6 +241,33 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
});
};

const handleMoveToProjects = async () => {
if (!data?.id || !data?.project_id || !data) return;
setIsMoving(true);
try {
await handleCreateUpdatePropertyValues({
issueId: data.id,
issueTypeId: data.type_id,
projectId: data.project_id,
workspaceSlug: workspaceSlug.toString(),
isDraft: true,
});

await moveIssue(workspaceSlug.toString(), data.id, {
...data,
...getValues(),
} as TWorkspaceDraftIssue);
} catch (error) {
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: "Failed to move issue to project. Please try again.",
});
} finally {
setIsMoving(false);
}
};
Comment on lines +244 to +269
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add validation for workspaceSlug

The function should validate workspaceSlug before using it in API calls.

Apply this diff to add the validation:

   const handleMoveToProjects = async () => {
-    if (!data?.id || !data?.project_id || !data) return;
+    if (!data?.id || !data?.project_id || !data || !workspaceSlug) {
+      setToast({
+        type: TOAST_TYPE.ERROR,
+        title: "Error!",
+        message: "Missing required data for moving to project",
+      });
+      return;
+    }
     setIsMoving(true);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleMoveToProjects = async () => {
if (!data?.id || !data?.project_id || !data) return;
setIsMoving(true);
try {
await handleCreateUpdatePropertyValues({
issueId: data.id,
issueTypeId: data.type_id,
projectId: data.project_id,
workspaceSlug: workspaceSlug.toString(),
isDraft: true,
});
await moveIssue(workspaceSlug.toString(), data.id, {
...data,
...getValues(),
} as TWorkspaceDraftIssue);
} catch (error) {
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: "Failed to move issue to project. Please try again.",
});
} finally {
setIsMoving(false);
}
};
const handleMoveToProjects = async () => {
if (!data?.id || !data?.project_id || !data || !workspaceSlug) {
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: "Missing required data for moving to project",
});
return;
}
setIsMoving(true);
try {
await handleCreateUpdatePropertyValues({
issueId: data.id,
issueTypeId: data.type_id,
projectId: data.project_id,
workspaceSlug: workspaceSlug.toString(),
isDraft: true,
});
await moveIssue(workspaceSlug.toString(), data.id, {
...data,
...getValues(),
} as TWorkspaceDraftIssue);
} catch (error) {
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: "Failed to move issue to project. Please try again.",
});
} finally {
setIsMoving(false);
}
};


const condition =
(watch("name") && watch("name") !== "") || (watch("description_html") && watch("description_html") !== "<p></p>");

Expand Down Expand Up @@ -492,15 +524,9 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
variant="primary"
type="button"
size="sm"
loading={isSubmitting}
onClick={() => {
if (data?.id && data) {
moveIssue(workspaceSlug.toString(), data?.id, {
...data,
...getValues(),
} as TWorkspaceDraftIssue);
}
}}
loading={isMoving}
onClick={handleMoveToProjects}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update button to reflect loading state

The button should display the loading state during the move operation.

-  onClick={handleMoveToProjects}
+  onClick={handleMoveToProjects}
+  loading={isMoving}  // Add this prop after adding the state
+  disabled={isMoving} // Prevent multiple clicks

Committable suggestion skipped: line range outside the PR's diff.

disabled={isMoving}
>
Add to project
</Button>
Expand Down
Loading