From 2eed3a518c6e6197f873efeb6f6524d06d2eb425 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 29 Nov 2025 01:21:27 +0000 Subject: [PATCH] Add CustomSelect component for enhanced selection functionality with option change handling --- .../Dashboard/common/CustomSelect.jsx | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/components/Dashboard/common/CustomSelect.jsx diff --git a/src/components/Dashboard/common/CustomSelect.jsx b/src/components/Dashboard/common/CustomSelect.jsx new file mode 100644 index 0000000..ec69b29 --- /dev/null +++ b/src/components/Dashboard/common/CustomSelect.jsx @@ -0,0 +1,56 @@ +import { useEffect, useRef } from 'react' +import { Select } from 'antd' +import PropTypes from 'prop-types' + +const CustomSelect = ({ + placeholder, + disabled, + options = [], + value, + onChange, + ...rest +}) => { + const prevOptionsRef = useRef(options) + + useEffect(() => { + // Check if options have changed + const optionsChanged = + JSON.stringify(prevOptionsRef.current) !== JSON.stringify(options) + + if (optionsChanged && value !== undefined && value !== null) { + // Check if current value exists in new options + const valueExists = + Array.isArray(options) && + options.some((option) => option.value === value) + + // If value doesn't exist in new options, clear it + if (!valueExists && onChange) { + onChange(undefined) + } + } + + // Update the ref with current options + prevOptionsRef.current = options + }, [options, value, onChange]) + + return ( +