From 4ec0d4b3de601a4553ba69653780def1a8766f44 Mon Sep 17 00:00:00 2001 From: Tania Date: Thu, 22 Sep 2022 14:30:47 +1000 Subject: [PATCH 1/2] feat: add a popup to confirm cancel assigning --- app/javascript/api/action-items-api.ts | 2 +- .../action-items/action-items-container.tsx | 75 +++++++++++++------ .../pages/action-items/style.module.less | 25 +++++++ .../action/action-item/action-item.tsx | 49 +++++++++++- .../columns/card/card-body/style.module.less | 11 +++ .../shared/modal-confirm/confirm-comment.tsx | 17 +++++ .../modal-confirm/modal-confirm.module.less | 14 ++++ .../shared/modal-confirm/modal-confirm.tsx | 46 ++++++++++++ .../components/shared/modal/modal.module.less | 60 +++++++++++++++ .../components/shared/modal/modal.tsx | 31 ++++++++ app/javascript/components/style.less | 4 + app/javascript/constants/constants.ts | 9 +++ app/javascript/less/variables.less | 1 + package.json | 2 + yarn.lock | 5 ++ 15 files changed, 325 insertions(+), 26 deletions(-) create mode 100644 app/javascript/components/shared/modal-confirm/confirm-comment.tsx create mode 100644 app/javascript/components/shared/modal-confirm/modal-confirm.module.less create mode 100644 app/javascript/components/shared/modal-confirm/modal-confirm.tsx create mode 100644 app/javascript/components/shared/modal/modal.module.less create mode 100644 app/javascript/components/shared/modal/modal.tsx create mode 100644 app/javascript/constants/constants.ts diff --git a/app/javascript/api/action-items-api.ts b/app/javascript/api/action-items-api.ts index 9bae47f8..503d43bc 100644 --- a/app/javascript/api/action-items-api.ts +++ b/app/javascript/api/action-items-api.ts @@ -22,7 +22,7 @@ export const actionItemsApi = { return actionItems.data; }, - async updateActionItems(id: number, body?: string, assigneeId?: string, status?: string) { + async updateActionItems(id: number, assigneeId?: string, body?: string, status?: string) { const actionItems = await api.patch>( `action_items/${id}`, { body, assigneeId, status } diff --git a/app/javascript/components/pages/action-items/action-items-container.tsx b/app/javascript/components/pages/action-items/action-items-container.tsx index d0e78661..3d2469e2 100644 --- a/app/javascript/components/pages/action-items/action-items-container.tsx +++ b/app/javascript/components/pages/action-items/action-items-container.tsx @@ -15,6 +15,10 @@ import { import { ActionItem } from "./action/action-item"; import { actionItemsApi } from "../../../api/action-items-api"; import "../../style.less"; +import {CommentValues, TextModal} from "../../../constants/constants"; +import Modal from "../../shared/modal/modal"; +import ModalConfirm from "../../shared/modal-confirm/modal-confirm"; +import {cardApi} from "../../../api/card-api"; import style from "./style.module.less"; @@ -26,6 +30,8 @@ const ActionItemsContainer: React.FC = () => { const [isModalOpen, setModalOpen] = useState(false); const [cardId, setCardId] = useState(null); + const [confirmComment, setConfirmComment] = useState(""); + const [isError, setIsError] = useState(false); const columns = [ ACTION_ITEM_STATUS.ToDo, ACTION_ITEM_STATUS.InProgress, @@ -48,6 +54,10 @@ const ActionItemsContainer: React.FC = () => { getActionItems(); }, []); + + const isShort = confirmComment.length <= CommentValues.MinLength; + const isLong = confirmComment.length > CommentValues.MaxLength; + const handleOnDragEnd = (items: Array) => (result: DropResult) => { const { destination, draggableId } = result; @@ -72,18 +82,41 @@ const ActionItemsContainer: React.FC = () => { changeStatus(); }; - const handleDeleteItem = async () => { - setModalOpen(false); + const handleDeleteAssignment = async () => { dispatch(actions.pending()); try { - const response = await actionItemsApi.changeActionItemStatus(Number(cardId), ACTION_ITEM_STATUS.Closed) + const response = await actionItemsApi.updateActionItems(Number(cardId), ' '); dispatch(actions.setActionItems(response)); + setIsError(false); } catch (error) { dispatch(actions.rejected()); - alert(`Something went wrong. Error ${error}`); + setIsError(true); + throw new Error(`Something went wrong. Error ${error}`); + } + }; + + const handleAddConfirmComment = async () => { + if (cardId) { + try { + await cardApi.addComment({ + cardId: cardId, + content: confirmComment, + }); + setIsError(false); + } catch (error) { + setIsError(true); + throw new Error(`Something went wrong. Error ${error}`); + } } }; + const handleSubmit = () => { + setConfirmComment(""); + setModalOpen(false); + handleDeleteAssignment(); + //handleAddConfirmComment(); + } + const getColumnName = (name: string) => { switch (name) { case ACTION_ITEM_STATUS.ToDo: @@ -142,25 +175,21 @@ const ActionItemsContainer: React.FC = () => { ))}
-
-
-

Delete file permanently?

-
-
- - -
-
+ setModalOpen(false)} > + setModalOpen(false)} + disabledButton={isShort || isLong} + > +