ebanutsya
This commit is contained in:
@@ -7,16 +7,15 @@ import SelectProductModal from "../Modals/SelectProductModal/SelectProductModal"
|
||||
import {SupplierProduct} from "../../types/supplierProduct";
|
||||
import barcodeApi from "../../api/barcodeApi";
|
||||
import {useDispatch, useSelector} from "react-redux";
|
||||
import {openScanModal} from "../../features/scanModal/scanModalSlice";
|
||||
import {openScanModal, setScannedData} from "../../features/scanModal/scanModalSlice";
|
||||
import {RootState} from "../../redux/store";
|
||||
|
||||
type Props = {
|
||||
onSearch: (text: string) => void;
|
||||
onSearch?: (text: string) => void;
|
||||
onSupplierProductSelected?: (supplierProduct: SupplierProduct) => void
|
||||
}
|
||||
const SearchBar: FC<Props> = ({onSearch, onSupplierProductSelected}) => {
|
||||
// const [isScanModalVisible, setIsScanModalVisible] = useState<boolean>(false);
|
||||
// const [, setSelectProductModalVisible] = useState(false);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const [searchInput, setSearchInput] = useState<string>("");
|
||||
const textInputRef = useRef<TextInput>(null);
|
||||
@@ -26,19 +25,19 @@ const SearchBar: FC<Props> = ({onSearch, onSupplierProductSelected}) => {
|
||||
useEffect(() => {
|
||||
if (!scannedData) return;
|
||||
barcodeApi.searchProducts(scannedData).then((response) => {
|
||||
console.log("Response: " + response);
|
||||
setProducts(response)
|
||||
});
|
||||
}, [scannedData]);
|
||||
const selectProductModalVisible = products.length > 0;
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
|
||||
<SelectProductModal visible={selectProductModalVisible} products={products} onSelected={(product) => {
|
||||
if (onSupplierProductSelected) onSupplierProductSelected(product);
|
||||
setProducts([]);
|
||||
dispatch(setScannedData(undefined));
|
||||
}}/>
|
||||
<BasicButton onPress={() => {
|
||||
if (!onSearch) return;
|
||||
onSearch(searchInput);
|
||||
if (textInputRef.current) {
|
||||
textInputRef.current.clear();
|
||||
@@ -77,7 +76,7 @@ const styles = StyleSheet.create({
|
||||
borderTopRightRadius: responsiveWidth(1),
|
||||
borderBottomRightRadius: responsiveWidth(1),
|
||||
paddingHorizontal: responsiveWidth(5),
|
||||
height:'100%'
|
||||
height: '100%'
|
||||
},
|
||||
scanImageWrapper: {
|
||||
paddingHorizontal: responsiveWidth(1),
|
||||
|
||||
Reference in New Issue
Block a user