[WEB-1154] fix: delete attachment modal logic (#4338)

* fix: delete attachment modal logic

* chore: remove console log

* chore: update delete attachment button type
This commit is contained in:
Aaryan Khandelwal 2024-05-02 16:13:04 +05:30 committed by GitHub
parent 6918393b63
commit 42c4c46939
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 37 deletions

View File

@ -2,19 +2,19 @@ import { FC } from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import Link from "next/link"; import Link from "next/link";
import { AlertCircle, X } from "lucide-react"; import { AlertCircle, X } from "lucide-react";
// ui
import { Tooltip } from "@plane/ui"; import { Tooltip } from "@plane/ui";
import { getFileIcon } from "@/components/icons/attachment"; // icons
import { getFileIcon } from "@/components/icons";
// components
import { IssueAttachmentDeleteModal } from "@/components/issues";
// helpers
import { convertBytesToSize, getFileExtension, getFileName } from "@/helpers/attachment.helper"; import { convertBytesToSize, getFileExtension, getFileName } from "@/helpers/attachment.helper";
import { renderFormattedDate } from "@/helpers/date-time.helper"; import { renderFormattedDate } from "@/helpers/date-time.helper";
import { truncateText } from "@/helpers/string.helper"; import { truncateText } from "@/helpers/string.helper";
// hooks
import { useIssueDetail, useMember } from "@/hooks/store"; import { useIssueDetail, useMember } from "@/hooks/store";
import { usePlatformOS } from "@/hooks/use-platform-os"; import { usePlatformOS } from "@/hooks/use-platform-os";
// hooks
// ui
// components
// icons
// helper
import { IssueAttachmentDeleteModal } from "./delete-attachment-confirmation-modal";
// types // types
import { TAttachmentOperations } from "./root"; import { TAttachmentOperations } from "./root";
@ -36,24 +36,24 @@ export const IssueAttachmentsDetail: FC<TIssueAttachmentsDetail> = observer((pro
isDeleteAttachmentModalOpen, isDeleteAttachmentModalOpen,
toggleDeleteAttachmentModal, toggleDeleteAttachmentModal,
} = useIssueDetail(); } = useIssueDetail();
// states // derived values
const attachment = attachmentId ? getAttachmentById(attachmentId) : undefined;
// hooks
const { isMobile } = usePlatformOS(); const { isMobile } = usePlatformOS();
const attachment = attachmentId && getAttachmentById(attachmentId);
if (!attachment) return <></>; if (!attachment) return <></>;
return ( return (
<> <>
{isDeleteAttachmentModalOpen === attachment.id && (
<IssueAttachmentDeleteModal <IssueAttachmentDeleteModal
isOpen={isDeleteAttachmentModalOpen} isOpen={!!isDeleteAttachmentModalOpen}
setIsOpen={() => toggleDeleteAttachmentModal(false)} onClose={() => toggleDeleteAttachmentModal(null)}
handleAttachmentOperations={handleAttachmentOperations} handleAttachmentOperations={handleAttachmentOperations}
data={attachment} data={attachment}
/> />
)}
<div <div className="flex h-[60px] items-center justify-between gap-1 rounded-md border-[2px] border-custom-border-200 bg-custom-background-100 px-4 py-2 text-sm">
key={attachmentId}
className="flex h-[60px] items-center justify-between gap-1 rounded-md border-[2px] border-custom-border-200 bg-custom-background-100 px-4 py-2 text-sm"
>
<Link href={attachment.asset} target="_blank" rel="noopener noreferrer"> <Link href={attachment.asset} target="_blank" rel="noopener noreferrer">
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<div className="h-7 w-7">{getFileIcon(getFileExtension(attachment.asset))}</div> <div className="h-7 w-7">{getFileIcon(getFileExtension(attachment.asset))}</div>
@ -83,7 +83,7 @@ export const IssueAttachmentsDetail: FC<TIssueAttachmentsDetail> = observer((pro
</Link> </Link>
{!disabled && ( {!disabled && (
<button onClick={() => toggleDeleteAttachmentModal(true)}> <button type="button" onClick={() => toggleDeleteAttachmentModal(attachment.id)}>
<X className="h-4 w-4 text-custom-text-200 hover:text-custom-text-100" /> <X className="h-4 w-4 text-custom-text-200 hover:text-custom-text-100" />
</button> </button>
)} )}

View File

@ -1,4 +1,4 @@
import { FC, Fragment, Dispatch, SetStateAction, useState } from "react"; import { FC, Fragment, useState } from "react";
import { AlertTriangle } from "lucide-react"; import { AlertTriangle } from "lucide-react";
import { Dialog, Transition } from "@headlessui/react"; import { Dialog, Transition } from "@headlessui/react";
import type { TIssueAttachment } from "@plane/types"; import type { TIssueAttachment } from "@plane/types";
@ -14,18 +14,18 @@ export type TAttachmentOperationsRemoveModal = Exclude<TAttachmentOperations, "c
type Props = { type Props = {
isOpen: boolean; isOpen: boolean;
setIsOpen: Dispatch<SetStateAction<boolean>>; onClose: () => void;
data: TIssueAttachment; data: TIssueAttachment;
handleAttachmentOperations: TAttachmentOperationsRemoveModal; handleAttachmentOperations: TAttachmentOperationsRemoveModal;
}; };
export const IssueAttachmentDeleteModal: FC<Props> = (props) => { export const IssueAttachmentDeleteModal: FC<Props> = (props) => {
const { isOpen, setIsOpen, data, handleAttachmentOperations } = props; const { isOpen, onClose, data, handleAttachmentOperations } = props;
// state // states
const [loader, setLoader] = useState(false); const [loader, setLoader] = useState(false);
const handleClose = () => { const handleClose = () => {
setIsOpen(false); onClose();
setLoader(false); setLoader(false);
}; };

View File

@ -1,7 +1,5 @@
export * from "./root";
export * from "./attachment-upload";
export * from "./delete-attachment-confirmation-modal";
export * from "./attachments-list";
export * from "./attachment-detail"; export * from "./attachment-detail";
export * from "./attachment-upload";
export * from "./attachments-list";
export * from "./delete-attachment-modal";
export * from "./root";

View File

@ -51,7 +51,7 @@ export interface IIssueDetail
isArchiveIssueModalOpen: boolean; isArchiveIssueModalOpen: boolean;
isRelationModalOpen: TIssueRelationTypes | null; isRelationModalOpen: TIssueRelationTypes | null;
isSubIssuesModalOpen: boolean; isSubIssuesModalOpen: boolean;
isDeleteAttachmentModalOpen: boolean; isDeleteAttachmentModalOpen: string | null;
// computed // computed
isAnyModalOpen: boolean; isAnyModalOpen: boolean;
// helper actions // helper actions
@ -65,7 +65,7 @@ export interface IIssueDetail
toggleArchiveIssueModal: (value: boolean) => void; toggleArchiveIssueModal: (value: boolean) => void;
toggleRelationModal: (relationType: TIssueRelationTypes | null) => void; toggleRelationModal: (relationType: TIssueRelationTypes | null) => void;
toggleSubIssuesModal: (value: boolean) => void; toggleSubIssuesModal: (value: boolean) => void;
toggleDeleteAttachmentModal: (value: boolean) => void; toggleDeleteAttachmentModal: (attachmentId: string | null) => void;
// store // store
rootIssueStore: IIssueRootStore; rootIssueStore: IIssueRootStore;
issue: IIssueStore; issue: IIssueStore;
@ -90,7 +90,7 @@ export class IssueDetail implements IIssueDetail {
isArchiveIssueModalOpen: boolean = false; isArchiveIssueModalOpen: boolean = false;
isRelationModalOpen: TIssueRelationTypes | null = null; isRelationModalOpen: TIssueRelationTypes | null = null;
isSubIssuesModalOpen: boolean = false; isSubIssuesModalOpen: boolean = false;
isDeleteAttachmentModalOpen: boolean = false; isDeleteAttachmentModalOpen: string | null = null;
// store // store
rootIssueStore: IIssueRootStore; rootIssueStore: IIssueRootStore;
issue: IIssueStore; issue: IIssueStore;
@ -154,7 +154,7 @@ export class IssueDetail implements IIssueDetail {
this.isArchiveIssueModalOpen || this.isArchiveIssueModalOpen ||
!!this.isRelationModalOpen || !!this.isRelationModalOpen ||
this.isSubIssuesModalOpen || this.isSubIssuesModalOpen ||
this.isDeleteAttachmentModalOpen !!this.isDeleteAttachmentModalOpen
); );
} }
@ -170,7 +170,7 @@ export class IssueDetail implements IIssueDetail {
toggleArchiveIssueModal = (value: boolean) => (this.isArchiveIssueModalOpen = value); toggleArchiveIssueModal = (value: boolean) => (this.isArchiveIssueModalOpen = value);
toggleRelationModal = (relationType: TIssueRelationTypes | null) => (this.isRelationModalOpen = relationType); toggleRelationModal = (relationType: TIssueRelationTypes | null) => (this.isRelationModalOpen = relationType);
toggleSubIssuesModal = (value: boolean) => (this.isSubIssuesModalOpen = value); toggleSubIssuesModal = (value: boolean) => (this.isSubIssuesModalOpen = value);
toggleDeleteAttachmentModal = (value: boolean) => (this.isDeleteAttachmentModalOpen = value); toggleDeleteAttachmentModal = (attachmentId: string | null) => (this.isDeleteAttachmentModalOpen = attachmentId);
// issue // issue
fetchIssue = async ( fetchIssue = async (