From 1b4e9d29e8f87f4488dc12eac333060f3a8aa3c7 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 6 Jun 2024 17:42:53 -0400 Subject: [PATCH 01/17] update components --- .../GoalProgressCard/GoalProgressCard.tsx | 4 +- .../GoalProgressCard/GoalProgressCardItem.tsx | 4 +- .../ItemMonitoringCards.tsx | 4 +- .../Cards/UserRoleCard/UserRoleCard.tsx | 6 +- .../elements/Commentary/Commentary.tsx | 16 +- .../elements/CommentaryBox/CommentaryBox.tsx | 143 +++++++- .../elements/Inputs/Checkbox/Checkbox.tsx | 20 +- .../elements/Inputs/Dropdown/Dropdown.tsx | 11 +- .../Inputs/Dropdown/constants/colorMap.ts | 6 +- .../elements/Inputs/Input/Input.tsx | 19 +- .../Inputs/InputElements/InputWrapper.tsx | 4 +- src/components/elements/Inputs/Map/RHFMap.tsx | 6 +- .../elements/Inputs/textArea/TextArea.tsx | 13 +- .../__snapshots__/TextArea.stories.storyshot | 1 + src/components/elements/Map-mapbox/Map.tsx | 325 ++++++++++++------ .../Map-mapbox/MapControls/EditControl.tsx | 216 +++--------- .../MapControls/FeatureDetailCard.tsx | 170 --------- .../Map-mapbox/MapControls/StyleControl.tsx | 44 ++- .../Map-mapbox/MapControls/ZoomControl.tsx | 21 +- .../elements/Map-mapbox/MapControls/types.ts | 4 +- .../Map-mapbox/MapLayers/GeoJsonLayer.tsx | 16 +- .../Map-mapbox/MapLayers/ImagesLayer.tsx | 180 ---------- .../Map-mapbox/components/ControlGroup.tsx | 8 +- .../Map-mapbox/hooks/useOnHoverFeature.ts | 38 -- src/components/elements/Map-mapbox/utils.ts | 276 ++++++++++++++- .../MapSidePanel/MapSidePanel.stories.tsx | 31 +- .../elements/MapSidePanel/MapSidePanel.tsx | 168 ++++++++- .../MapSidePanel/MapSidePanelItem.tsx | 93 ++++- src/components/elements/Menu/Menu.tsx | 1 - .../Notification/Notification.stories.tsx | 9 +- .../elements/Notification/Notification.tsx | 76 ++-- src/components/elements/Status/Status.tsx | 43 ++- .../elements/TooltipMap/TooltipMap.tsx | 101 ++++-- .../EntityMapAndGalleryCard.tsx | 36 +- src/components/extensive/Icon/Icon.tsx | 7 + src/components/extensive/Modal/ModalAdd.tsx | 17 +- .../extensive/Modal/ModalApprove.tsx | 18 +- .../extensive/Modal/ModalConfirm.tsx | 16 +- .../extensive/Modal/ModalSubmit.tsx | 48 ++- .../extensive/Modal/ModalWithClose.tsx | 10 + .../extensive/Modal/ModalWithLogo.tsx | 8 +- .../extensive/Modal/ModalWithMap.tsx | 44 ++- .../PageElements/Footer/PageFooter.tsx | 6 +- .../extensive/WizardForm/FormSummaryRow.tsx | 70 +++- 44 files changed, 1475 insertions(+), 882 deletions(-) delete mode 100644 src/components/elements/Map-mapbox/MapControls/FeatureDetailCard.tsx delete mode 100644 src/components/elements/Map-mapbox/MapLayers/ImagesLayer.tsx delete mode 100644 src/components/elements/Map-mapbox/hooks/useOnHoverFeature.ts diff --git a/src/components/elements/Cards/GoalProgressCard/GoalProgressCard.tsx b/src/components/elements/Cards/GoalProgressCard/GoalProgressCard.tsx index 786f72bdc..a70dfff02 100644 --- a/src/components/elements/Cards/GoalProgressCard/GoalProgressCard.tsx +++ b/src/components/elements/Cards/GoalProgressCard/GoalProgressCard.tsx @@ -42,9 +42,9 @@ const GoalProgressCard: FC = ({ {label} - {value}  + {value?.toLocaleString()}  - of {limit} + of {limit?.toLocaleString()} {labelValue} diff --git a/src/components/elements/Cards/GoalProgressCard/GoalProgressCardItem.tsx b/src/components/elements/Cards/GoalProgressCard/GoalProgressCardItem.tsx index 44a678433..639de32e1 100644 --- a/src/components/elements/Cards/GoalProgressCard/GoalProgressCardItem.tsx +++ b/src/components/elements/Cards/GoalProgressCard/GoalProgressCardItem.tsx @@ -20,9 +20,7 @@ const GoalProgressCardItem: FC = ({ iconName, label, {label} - - {value} - + {value?.toLocaleString()} ); }; diff --git a/src/components/elements/Cards/ItemMonitoringCard/ItemMonitoringCards.tsx b/src/components/elements/Cards/ItemMonitoringCard/ItemMonitoringCards.tsx index ae04b0601..34ea663d7 100644 --- a/src/components/elements/Cards/ItemMonitoringCard/ItemMonitoringCards.tsx +++ b/src/components/elements/Cards/ItemMonitoringCard/ItemMonitoringCards.tsx @@ -9,7 +9,7 @@ import ToolTip from "@/components/elements/Tooltip/Tooltip"; import Icon, { IconNames } from "../../../extensive/Icon/Icon"; -export interface LeyendItemMonitoringCardsProps { +export interface LegendItemMonitoringCardsProps { title: string; color: string; } @@ -27,7 +27,7 @@ export interface ItemMonitoringCardsProps className?: string; img?: IconNames; type?: "graph" | "map" | "graph-button"; - legends?: LeyendItemMonitoringCardsProps[]; + legends?: LegendItemMonitoringCardsProps[]; } const ItemMonitoringCards = ({ diff --git a/src/components/elements/Cards/UserRoleCard/UserRoleCard.tsx b/src/components/elements/Cards/UserRoleCard/UserRoleCard.tsx index 8ffd30709..4a07c5d73 100644 --- a/src/components/elements/Cards/UserRoleCard/UserRoleCard.tsx +++ b/src/components/elements/Cards/UserRoleCard/UserRoleCard.tsx @@ -18,6 +18,7 @@ export interface UserRoleCardProps { setSelectedOption?: any; refContentCard?: React.RefObject; selectedOption?: string; + icon?: IconNames; } const UserRoleCard: React.FC = ({ @@ -29,7 +30,8 @@ const UserRoleCard: React.FC = ({ setSelectedOption, refContentCard, selectedOption, - menu + menu, + icon }) => { const t = useT(); const MenuOption: MenuItemProps[] = options ?? [ @@ -64,7 +66,7 @@ const UserRoleCard: React.FC = ({ })} >
- +
diff --git a/src/components/elements/Commentary/Commentary.tsx b/src/components/elements/Commentary/Commentary.tsx index 9230e11a7..cd0eca3b5 100644 --- a/src/components/elements/Commentary/Commentary.tsx +++ b/src/components/elements/Commentary/Commentary.tsx @@ -10,7 +10,7 @@ export interface CommentaryProps { lastName: string; date: string; commentary: string; - status?: "draft" | "submitted"; + status?: string; files?: CommentaryFilesProps[]; } @@ -21,14 +21,15 @@ const statusStyle = { const Commentary = (props: CommentaryProps) => { const { name, lastName, date, commentary, files = [], status } = props; + const statusKey = status as keyof typeof statusStyle; return (
- {name[0]} - {lastName[0]} + {name?.[0]} + {lastName?.[0]}
@@ -43,16 +44,15 @@ const Commentary = (props: CommentaryProps) => {
- + {status}
- { {commentary}
- {files.map(file => ( + {files?.map((file: any) => (
- {file.file} + {file?.attachment}
))} diff --git a/src/components/elements/CommentaryBox/CommentaryBox.tsx b/src/components/elements/CommentaryBox/CommentaryBox.tsx index 8385e66fe..4527a4822 100644 --- a/src/components/elements/CommentaryBox/CommentaryBox.tsx +++ b/src/components/elements/CommentaryBox/CommentaryBox.tsx @@ -1,32 +1,115 @@ import { useT } from "@transifex/react"; +import { useState } from "react"; import { When } from "react-if"; import Button from "@/components/elements/Button/Button"; import TextArea from "@/components/elements/Inputs/textArea/TextArea"; import Text from "@/components/elements/Text/Text"; import Icon, { IconNames } from "@/components/extensive/Icon/Icon"; +import { usePostV2AuditStatus } from "@/generated/apiComponents"; + +import Notification from "../Notification/Notification"; export interface CommentaryBoxProps { name: string; lastName: string; buttonSendOnBox?: boolean; mutate?: any; - refresh?: any; + refresh?: () => void; record?: any; entity?: string; } const CommentaryBox = (props: CommentaryBoxProps) => { - const { name, lastName, buttonSendOnBox } = props; + const { name, lastName, buttonSendOnBox, refresh, record, entity } = props; + const { mutate: sendCommentary } = usePostV2AuditStatus(); + const [files, setFiles] = useState([]); + const [comment, setComment] = useState(""); + const [error, setError] = useState(""); + const [charCount, setCharCount] = useState(0); + const [showNotification, setShowNotification] = useState(false); + const [loading, setLoading] = useState(false); + const [warning, setWarning] = useState(""); const t = useT(); + const validFileTypes = [ + "application/pdf", + "application/vnd.ms-excel", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "application/msword", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "image/jpeg", + "image/png", + "image/tiff" + ]; + const maxFileSize = 10 * 1024 * 1024; + const maxFiles = 5; + const handleFileChange = (e: React.ChangeEvent) => { + if (e.target.files) { + const file = e.target.files[0]; + if (files.length >= maxFiles) { + setError("You can upload a maximum of 5 files."); + return; + } + if (!validFileTypes.includes(file?.type)) { + setError("Invalid file type. Only PDF, XLS, DOC, XLSX, DOCX, JPG, PNG, and TIFF are allowed."); + return; + } + if (file.size > maxFileSize) { + setError("File size must be less than 10MB."); + return; + } + setFiles(prevFiles => [...prevFiles, file]); + setError(""); + } + }; + const submitComment = () => { + const body = new FormData(); + body.append("entity_uuid", record?.uuid); + body.append("status", record?.status); + body.append("entity", entity as string); + body.append("comment", comment); + body.append("type", "comment"); + files.forEach((element: File, index: number) => { + body.append(`file[${index}]`, element); + }); + setLoading(true); + sendCommentary?.( + { + //@ts-ignore swagger issue + body + }, + { + onSuccess: () => { + setShowNotification(true); + setTimeout(() => { + setShowNotification(false); + }, 3000); + setComment(""); + setError(""); + setFiles([]); + refresh && refresh(); + setLoading(false); + } + } + ); + }; + const handleCommentChange = (e: any) => { + setComment(e.target.value); + setCharCount(e.target.value.length); + if (charCount >= 255) { + setWarning("Your comment exceeds 255 characters."); + } else { + setWarning(""); + } + }; return (
- {name[0]} - {lastName[0]} + {name?.[0]} + {lastName?.[0]}