diff --git a/src/components/mui/SnackbarNotification/index.js b/src/components/mui/SnackbarNotification/index.js index 5b46ccf..2c268e3 100644 --- a/src/components/mui/SnackbarNotification/index.js +++ b/src/components/mui/SnackbarNotification/index.js @@ -19,6 +19,7 @@ import CheckCircleIcon from "@mui/icons-material/CheckCircle"; import ErrorIcon from "@mui/icons-material/Error"; import SnackbarNotificationContext from "./Context"; import { NOTIFICATION_TIMEOUT } from "../../../utils/constants"; +import { empty } from "../../../utils/methods"; import { clearSnackbarMessage } from "../../../utils/actions"; /* @@ -50,14 +51,16 @@ const SnackbarNotification = ({ }; useEffect(() => { - if (msgData.html) { + if (!empty(msgData.html)) { setOpen(true); + } else { + setOpen(false); } }, [msgData]); // when snackbarMessage changes in base-reducer, we trigger the snackbar useEffect(() => { - if (snackbarMessage?.html) { + if (!empty(snackbarMessage?.html)) { setMsgData(snackbarMessage); } }, [snackbarMessage]); diff --git a/src/components/mui/dropdown-checkbox.js b/src/components/mui/dropdown-checkbox.js index dc99c56..be7c64d 100644 --- a/src/components/mui/dropdown-checkbox.js +++ b/src/components/mui/dropdown-checkbox.js @@ -29,10 +29,16 @@ const DropdownCheckbox = ({ allLabel, value = [], options, - onChange + onChange, + ...rest }) => { const handleChange = (ev) => { - const selected = ev.target.value; + const rawValue = ev.target.value; + const selected = Array.isArray(rawValue) + ? rawValue + : typeof rawValue === "string" + ? rawValue.split(",") + : []; if (selected.includes("all")) { if (!value.includes("all")) { @@ -43,6 +49,8 @@ const DropdownCheckbox = ({ onChange({ target: { name, value: selected.filter((v) => v !== "all") } }); + } else { + onChange({ target: { name, value: ["all"] } }); } } else { // else if "all" is not selected we just send selection @@ -59,6 +67,7 @@ const DropdownCheckbox = ({ multiple value={value} onChange={handleChange} + {...rest} input={} renderValue={(selected) => { if (selected.includes("all")) { diff --git a/src/utils/methods.js b/src/utils/methods.js index 1b88802..20c1a24 100644 --- a/src/utils/methods.js +++ b/src/utils/methods.js @@ -297,3 +297,15 @@ export const convertSVGtoImg = async (svgUrl) => { export const isRateEnabled = (value) => value !== null && value !== undefined && value !== ""; + +/** + * Returns true if value is null, undefined, empty/whitespace string, + * empty array, or empty object. + */ +export const empty = (value) => { + if (value === null || value === undefined) return true; + if (typeof value === "string") return value.trim().length === 0; + if (Array.isArray(value)) return value.length === 0; + if (typeof value === "object") return Object.keys(value).length === 0; + return false; +};