Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
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
42 changes: 21 additions & 21 deletions web/components/issues/attachment/attachment-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { FC } from "react";
import { observer } from "mobx-react";
import Link from "next/link";
import { AlertCircle, X } from "lucide-react";
// 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 { renderFormattedDate } from "@/helpers/date-time.helper";
import { truncateText } from "@/helpers/string.helper";
// hooks
import { useIssueDetail, useMember } from "@/hooks/store";
import { usePlatformOS } from "@/hooks/use-platform-os";
// hooks
// ui
// components
// icons
// helper
import { IssueAttachmentDeleteModal } from "./delete-attachment-confirmation-modal";
// types
import { TAttachmentOperations } from "./root";

Expand All @@ -36,24 +36,24 @@ export const IssueAttachmentsDetail: FC<TIssueAttachmentsDetail> = observer((pro
isDeleteAttachmentModalOpen,
toggleDeleteAttachmentModal,
} = useIssueDetail();
// states
// derived values
const attachment = attachmentId ? getAttachmentById(attachmentId) : undefined;
// hooks
const { isMobile } = usePlatformOS();
const attachment = attachmentId && getAttachmentById(attachmentId);

if (!attachment) return <></>;

return (
<>
<IssueAttachmentDeleteModal
isOpen={isDeleteAttachmentModalOpen}
setIsOpen={() => toggleDeleteAttachmentModal(false)}
handleAttachmentOperations={handleAttachmentOperations}
data={attachment}
/>

<div
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"
>
{isDeleteAttachmentModalOpen === attachment.id && (
<IssueAttachmentDeleteModal
isOpen={!!isDeleteAttachmentModalOpen}
onClose={() => toggleDeleteAttachmentModal(null)}
handleAttachmentOperations={handleAttachmentOperations}
data={attachment}
/>
)}
<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">
<Link href={attachment.asset} target="_blank" rel="noopener noreferrer">
<div className="flex items-center gap-3">
<div className="h-7 w-7">{getFileIcon(getFileExtension(attachment.asset))}</div>
Expand Down Expand Up @@ -83,7 +83,7 @@ export const IssueAttachmentsDetail: FC<TIssueAttachmentsDetail> = observer((pro
</Link>

{!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" />
</button>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, Fragment, Dispatch, SetStateAction, useState } from "react";
import { FC, Fragment, useState } from "react";
import { AlertTriangle } from "lucide-react";
import { Dialog, Transition } from "@headlessui/react";
import type { TIssueAttachment } from "@plane/types";
Expand All @@ -14,18 +14,18 @@ export type TAttachmentOperationsRemoveModal = Exclude<TAttachmentOperations, "c

type Props = {
isOpen: boolean;
setIsOpen: Dispatch<SetStateAction<boolean>>;
onClose: () => void;
data: TIssueAttachment;
handleAttachmentOperations: TAttachmentOperationsRemoveModal;
};

export const IssueAttachmentDeleteModal: FC<Props> = (props) => {
const { isOpen, setIsOpen, data, handleAttachmentOperations } = props;
// state
const { isOpen, onClose, data, handleAttachmentOperations } = props;
// states
const [loader, setLoader] = useState(false);

const handleClose = () => {
setIsOpen(false);
onClose();
setLoader(false);
};

Expand Down
8 changes: 3 additions & 5 deletions web/components/issues/attachment/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export * from "./root";

export * from "./attachment-detail";
export * from "./attachment-upload";
export * from "./delete-attachment-confirmation-modal";

export * from "./attachments-list";
export * from "./attachment-detail";
export * from "./delete-attachment-modal";
export * from "./root";
10 changes: 5 additions & 5 deletions web/store/issue/issue-details/root.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface IIssueDetail
isArchiveIssueModalOpen: boolean;
isRelationModalOpen: TIssueRelationTypes | null;
isSubIssuesModalOpen: boolean;
isDeleteAttachmentModalOpen: boolean;
isDeleteAttachmentModalOpen: string | null;
// computed
isAnyModalOpen: boolean;
// helper actions
Expand All @@ -65,7 +65,7 @@ export interface IIssueDetail
toggleArchiveIssueModal: (value: boolean) => void;
toggleRelationModal: (relationType: TIssueRelationTypes | null) => void;
toggleSubIssuesModal: (value: boolean) => void;
toggleDeleteAttachmentModal: (value: boolean) => void;
toggleDeleteAttachmentModal: (attachmentId: string | null) => void;
// store
rootIssueStore: IIssueRootStore;
issue: IIssueStore;
Expand All @@ -90,7 +90,7 @@ export class IssueDetail implements IIssueDetail {
isArchiveIssueModalOpen: boolean = false;
isRelationModalOpen: TIssueRelationTypes | null = null;
isSubIssuesModalOpen: boolean = false;
isDeleteAttachmentModalOpen: boolean = false;
isDeleteAttachmentModalOpen: string | null = null;
// store
rootIssueStore: IIssueRootStore;
issue: IIssueStore;
Expand Down Expand Up @@ -154,7 +154,7 @@ export class IssueDetail implements IIssueDetail {
this.isArchiveIssueModalOpen ||
!!this.isRelationModalOpen ||
this.isSubIssuesModalOpen ||
this.isDeleteAttachmentModalOpen
!!this.isDeleteAttachmentModalOpen
);
}

Expand All @@ -170,7 +170,7 @@ export class IssueDetail implements IIssueDetail {
toggleArchiveIssueModal = (value: boolean) => (this.isArchiveIssueModalOpen = value);
toggleRelationModal = (relationType: TIssueRelationTypes | null) => (this.isRelationModalOpen = relationType);
toggleSubIssuesModal = (value: boolean) => (this.isSubIssuesModalOpen = value);
toggleDeleteAttachmentModal = (value: boolean) => (this.isDeleteAttachmentModalOpen = value);
toggleDeleteAttachmentModal = (attachmentId: string | null) => (this.isDeleteAttachmentModalOpen = attachmentId);

// issue
fetchIssue = async (
Expand Down
Loading