diff --git a/src/admin/components/ResourceTabs/PolygonReviewTab/components/PolygonStatus/StatusDisplay .tsx b/src/admin/components/ResourceTabs/PolygonReviewTab/components/PolygonStatus/StatusDisplay .tsx deleted file mode 100644 index 8213eefd4..000000000 --- a/src/admin/components/ResourceTabs/PolygonReviewTab/components/PolygonStatus/StatusDisplay .tsx +++ /dev/null @@ -1,304 +0,0 @@ -import { useState } from "react"; -import { useShowContext } from "react-admin"; - -import Button from "@/components/elements/Button/Button"; -import Notification from "@/components/elements/Notification/Notification"; -import Text from "@/components/elements/Text/Text"; -import ModalConfirm from "@/components/extensive/Modal/ModalConfirm"; -import { useModalContext } from "@/context/modal.provider"; - -const menuPolygonOptions = [ - { - title: "Draft", - status: "draft", - value: 1, - viewPd: false - }, - { - title: "Submitted", - status: "submitted", - value: 2, - viewPd: true - }, - { - title: "Needs More Information", - status: "needs-more-information", - value: 3, - viewPd: false - }, - { - title: "Approved", - status: "approved", - value: 4, - viewPd: false - } -]; -const menuSiteOptions = [ - { - title: "Draft", - status: "draft", - value: 1, - viewPd: true - }, - { - title: "Awaiting Approval", - status: "awaiting-approval", - value: 2, - viewPd: true - }, - { - title: "Needs More Information", - status: "needs-more-information", - value: 3, - viewPd: false - }, - { - title: "Planting in Progress", - status: "planting-in-progress", - value: 4, - viewPd: false - }, - { - title: "Approved", - status: "approved", - value: 5, - viewPd: false - } -]; -const menuProjectOptions = [ - { - title: "Draft", - status: "draft", - value: 1, - viewPd: true - }, - { - title: "Awaiting Approval", - status: "awaiting-approval", - value: 2, - viewPd: true - }, - { - title: "Needs More Information", - status: "needs-more-information", - value: 3, - viewPd: false - }, - { - title: "Approved", - status: "approved", - value: 4, - viewPd: false - } -]; - -export interface StatusProps { - titleStatus: "Site" | "Project" | "Polygon"; - mutate?: any; - record?: any; - refresh?: () => void; - name: any; - refetchPolygon?: () => void; - tab?: string; - checkPolygonsSite?: boolean | undefined; - viewPD?: boolean; -} - -const menuOptionsMap = { - Polygon: menuPolygonOptions, - Site: menuSiteOptions, - Project: menuProjectOptions -}; - -const DescriptionStatusMap = { - Polygon: "Are you sure you want to change the polygon status to", - Site: "Are you sure you want to change the site status to", - Project: "Are you sure you want to change the project status to" -}; - -const DescriptionRequestMap = { - Polygon: "Provide an explanation for your change request for the polygon", - Site: "Provide an explanation for your change request for the site", - Project: "Provide an explanation for your change request for the project" -}; - -const StatusDisplay = ({ - titleStatus = "Polygon", - mutate, - refresh, - name, - record, - checkPolygonsSite, - tab, - viewPD -}: StatusProps) => { - const { refetch: reloadEntity } = useShowContext(); - const [notificationStatus, setNotificationStatus] = useState<{ - open: boolean; - message: string; - type: "success" | "error" | "warning"; - title: string; - }>({ - open: false, - message: "", - type: "success", - title: "Success!" - }); - - const { openModal, closeModal } = useModalContext(); - const contentStatus = ( - - {DescriptionStatusMap[titleStatus]} {name}? - - ); - const contentRequest = ( - - {DescriptionRequestMap[titleStatus]} {name}? - - ); - const filterViewPd = viewPD - ? menuOptionsMap[titleStatus].filter(option => option.viewPd === true) - : menuOptionsMap[titleStatus]; - const openFormModalHandlerStatus = () => { - openModal( - { - const option = menuOptionsMap[titleStatus].find(option => option.value === opt[0]); - try { - await mutate({ - pathParams: { uuid: record?.uuid }, - body: { - status: option?.status, - comment: text, - type: "status" - } - }); - setNotificationStatus({ - open: true, - message: "Your Status Update was just saved!", - type: "success", - title: "Success!" - }); - setTimeout(() => { - setNotificationStatus({ - open: false, - message: "", - type: "success", - title: "Success!" - }); - }, 3000); - } catch (e) { - setNotificationStatus({ - open: true, - message: "The request encountered an issue, or the comment exceeds 255 characters.", - type: "error", - title: "Error!" - }); - setTimeout(() => { - setNotificationStatus({ - open: false, - message: "", - type: "error", - title: "Error!" - }); - }, 3000); - console.error(e); - } finally { - refresh && refresh(); - reloadEntity && reloadEntity(); - closeModal; - } - }} - /> - ); - }; - - const openFormModalHandlerRequest = () => { - openModal( - { - const option = menuOptionsMap[titleStatus].find(option => option.value === opt[0]); - try { - await mutate({ - pathParams: { uuid: record?.uuid }, - body: { - status: option?.status, - comment: text, - type: "change-request", - is_active: true, - request_removed: false - } - }); - setNotificationStatus({ - open: true, - message: "Your Change Request was just added!", - type: "success", - title: "Success!" - }); - setTimeout(() => { - setNotificationStatus({ - open: false, - message: "", - type: "success", - title: "Success!" - }); - }, 3000); - } catch (e) { - setNotificationStatus({ - open: true, - message: "The request encountered an issue, or the comment exceeds 255 characters.", - type: "error", - title: "Error!" - }); - setTimeout(() => { - setNotificationStatus({ - open: false, - message: "", - type: "error", - title: "Error!" - }); - }, 3000); - console.error(e); - } finally { - refresh?.(); - reloadEntity?.(); - closeModal; - } - }} - /> - ); - }; - return ( - <> -
-
- - -
-
- - - ); -}; - -export default StatusDisplay;