From 45c9dfb3cf09ab3a82067dd95cd46dd72ec49467 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Thu, 2 May 2024 19:18:08 +0530 Subject: [PATCH] chore: update useCallback dependencies (#4341) --- .../issues/attachment/attachment-upload.tsx | 40 ++++++++++--------- web/components/issues/attachment/root.tsx | 2 +- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/web/components/issues/attachment/attachment-upload.tsx b/web/components/issues/attachment/attachment-upload.tsx index 46b697691..dcb52ec13 100644 --- a/web/components/issues/attachment/attachment-upload.tsx +++ b/web/components/issues/attachment/attachment-upload.tsx @@ -1,11 +1,11 @@ import { useCallback, useState } from "react"; import { observer } from "mobx-react-lite"; import { useDropzone } from "react-dropzone"; -// hooks // constants import { MAX_FILE_SIZE } from "@/constants/common"; // helpers import { generateFileName } from "@/helpers/attachment.helper"; +// hooks import { useApplication } from "@/hooks/store"; // types import { TAttachmentOperations } from "./root"; @@ -27,24 +27,28 @@ export const IssueAttachmentUpload: React.FC = observer((props) => { // states const [isLoading, setIsLoading] = useState(false); - const onDrop = useCallback((acceptedFiles: File[]) => { - const currentFile: File = acceptedFiles[0]; - if (!currentFile || !workspaceSlug) return; + const onDrop = useCallback( + (acceptedFiles: File[]) => { + const currentFile: File = acceptedFiles[0]; + if (!currentFile || !workspaceSlug) return; - const uploadedFile: File = new File([currentFile], generateFileName(currentFile.name), { type: currentFile.type }); - const formData = new FormData(); - formData.append("asset", uploadedFile); - formData.append( - "attributes", - JSON.stringify({ - name: uploadedFile.name, - size: uploadedFile.size, - }) - ); - setIsLoading(true); - handleAttachmentOperations.create(formData).finally(() => setIsLoading(false)); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + const uploadedFile: File = new File([currentFile], generateFileName(currentFile.name), { + type: currentFile.type, + }); + const formData = new FormData(); + formData.append("asset", uploadedFile); + formData.append( + "attributes", + JSON.stringify({ + name: uploadedFile.name, + size: uploadedFile.size, + }) + ); + setIsLoading(true); + handleAttachmentOperations.create(formData).finally(() => setIsLoading(false)); + }, + [handleAttachmentOperations, workspaceSlug] + ); const { getRootProps, getInputProps, isDragActive, isDragReject, fileRejections } = useDropzone({ onDrop, diff --git a/web/components/issues/attachment/root.tsx b/web/components/issues/attachment/root.tsx index c915ebce9..b9dd5e290 100644 --- a/web/components/issues/attachment/root.tsx +++ b/web/components/issues/attachment/root.tsx @@ -95,7 +95,7 @@ export const IssueAttachmentRoot: FC = (props) => { } }, }), - [workspaceSlug, projectId, issueId, createAttachment, removeAttachment] + [captureIssueEvent, workspaceSlug, projectId, issueId, createAttachment, removeAttachment] ); return (