diff --git a/src/components/grid/Grid.js b/src/components/grid/Grid.js index 7a0fbcc..d8a1013 100644 --- a/src/components/grid/Grid.js +++ b/src/components/grid/Grid.js @@ -1,6 +1,6 @@ import React, { useState, useRef, useEffect } from "react"; import Grid2 from "@mui/material/Unstable_Grid2"; -import { PropTypes } from "prop-types"; +import PropTypes from "prop-types"; import { styled } from "@mui/material/styles"; import Button from "@mui/material/Button"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; @@ -23,8 +23,17 @@ const ToggleButton = styled(Button)({ zIndex: 100, }); -const StyledGrid = styled(Grid2)( - ({ theme, isDashboard, isPolicy, isLocked, isExpanded }) => ({ +const StyledGrid = styled(Grid2, { + shouldForwardProp: (prop) => + !["isDashboard", "isPolicy", "isLocked", "isExpanded"].includes(prop), +})( + ({ + theme, + isDashboard = false, + isPolicy = false, + isLocked = false, + isExpanded = false, + }) => ({ ...(isDashboard ? { position: "relative", @@ -47,9 +56,7 @@ const StyledGrid = styled(Grid2)( : isPolicy && { padding: "10px", color: "#727272", - borderStyle: "solid", - borderColor: "#B0B0B0", - borderWidth: "1px", + border: "1px solid #B0B0B0", borderRadius: "8px", width: "270px", background: isLocked ? "#EAEFFF" : "white", @@ -64,7 +71,14 @@ const StyledGrid = styled(Grid2)( ); export const Grid = (props) => { - const { children, isDashboard, isPolicy, ...rest } = props; + const { + children, + isDashboard = false, + isPolicy = false, + isLocked = false, + ...rest + } = props; + const [isExpanded, setIsExpanded] = useState(false); const [showToggle, setShowToggle] = useState(false); const [isFirstRender, setIsFirstRender] = useState(true); @@ -77,36 +91,43 @@ export const Grid = (props) => { } }, [children, isPolicy]); - setTimeout(() => { - setIsFirstRender(false); - }, 3000); + useEffect(() => { + const timer = setTimeout(() => { + setIsFirstRender(false); + }, 3000); - const toggleExpand = () => { - setIsExpanded(!isExpanded); - }; + return () => clearTimeout(timer); + }, []); useEffect(() => { - if (contentRef.current) { - const contentHeight = contentRef.current.scrollHeight; - if (contentHeight > 120) { - if (!isFirstRender) { - setIsExpanded(true); - } - } else { - setIsExpanded(false); + if (!contentRef.current) return; + + const contentHeight = contentRef.current.scrollHeight; + + if (contentHeight > 120) { + if (!isFirstRender) { + setIsExpanded(true); } + } else { + setIsExpanded(false); } - }, [contentRef?.current?.scrollHeight]); + }, [children, isFirstRender]); + + const toggleExpand = () => { + setIsExpanded((prev) => !prev); + }; return ( {children} + {isPolicy && showToggle && ( {isExpanded ? : } @@ -122,9 +143,3 @@ Grid.propTypes = { isPolicy: PropTypes.bool, isLocked: PropTypes.bool, }; - -Grid.defaultProps = { - isDashboard: false, - isPolicy: false, - isLocked: false, -}; diff --git a/src/features/inspector/components/inspector-add-vet-to-kill-house/InspectorAddVetToKillHouse.js b/src/features/inspector/components/inspector-add-vet-to-kill-house/InspectorAddVetToKillHouse.js index 58fdf19..c4b9bf2 100644 --- a/src/features/inspector/components/inspector-add-vet-to-kill-house/InspectorAddVetToKillHouse.js +++ b/src/features/inspector/components/inspector-add-vet-to-kill-house/InspectorAddVetToKillHouse.js @@ -26,11 +26,12 @@ export const InspectorAddVetToKillHouse = ({ userKey, item }) => { }, []); useEffect(() => { - const d = inspectorGetKillHouses - ?.filter((item) => item.killer === false) - .map((item) => { - return { title: item.name, value: item.key }; - }); + const d = + inspectorGetKillHouses + ?.filter((item) => item.killer === false) + .map((item) => { + return { title: item.name, value: item.key }; + }) || []; setKillhouses(d); }, [inspectorGetKillHouses]); diff --git a/src/features/province/components/create-guilds/CreateGuilds.js b/src/features/province/components/create-guilds/CreateGuilds.js index 32fe136..3b33f63 100644 --- a/src/features/province/components/create-guilds/CreateGuilds.js +++ b/src/features/province/components/create-guilds/CreateGuilds.js @@ -443,14 +443,19 @@ export const CreateGuilds = ({ guild, updateTable }) => { {shouldShowUpdateButton && ( { function renderSkeletonCards(count = 6) { return ( - + {Array.from({ length: count }).map((_, i) => ( - + { > { )} - + {renderContent()} @@ -672,7 +666,7 @@ const AccessDashboardV2 = () => { if (!poultryRoles || poultryRoles.length === 0) { return ( - + { } return ( - + {sortRoles(poultryRoles)?.map((item, i) => ( - + { if (!livestockRoles || livestockRoles.length === 0) { return ( - + { } return ( - + {sortRoles(livestockRoles)?.map((item, i) => ( { if (!barSquareRoles || barSquareRoles.length === 0) { return ( - + { } return ( - + {sortRoles(barSquareRoles)?.map((item, i) => ( - + { ? ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_TRUE : isProvinceOperator ? ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_TRUE + : isSlaughter + ? ROUTE_SLAUGHTER_MANAGE_STEWARDS_IN_PROVINCE_TRUE : ""; const STEWARDS_OUT_PROVINCE_TRUE = isAdminX @@ -90,6 +97,8 @@ const ProvinceManageStewards = () => { ? ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_TRUE : isProvinceOperator ? ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_TRUE + : isSlaughter + ? ROUTE_SLAUGHTER_MANAGE_STEWARDS_OUT_PROVINCE_TRUE : ""; const STEWARDS_IN_PROVINCE_LEGAL = isAdminX @@ -98,6 +107,8 @@ const ProvinceManageStewards = () => { ? ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_LEGAL : isProvinceOperator ? ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_LEGAL + : isSlaughter + ? ROUTE_SLAUGHTER_MANAGE_STEWARDS_IN_PROVINCE_LEGAL : ""; const STEWARDS_OUT_PROVINCE_LEGAL = isAdminX @@ -106,6 +117,8 @@ const ProvinceManageStewards = () => { ? ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_LEGAL : isProvinceOperator ? ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_LEGAL + : isSlaughter + ? ROUTE_SLAUGHTER_MANAGE_STEWARDS_OUT_PROVINCE_LEGAL : ""; return ( @@ -123,7 +136,8 @@ const ProvinceManageStewards = () => { {(ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS === pathname || ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS === pathname || - ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS === pathname) && ( + ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS === pathname || + ROUTE_SLAUGHTER_MANAGE_STEWARDS === pathname) && ( <> { }, { text: "مدیریت مباشرین", - route: ROUTES.ROUTE_SLAUGHTER_ROUTE_MANAGE_STEWARDS, + route: ROUTES.ROUTE_SLAUGHTER_MANAGE_STEWARDS, icon: , }, // {