Android_Retail/src/Pages/BookingScreen/Components/UtillComponents/MultipleSearch.jsx

121 lines
3.4 KiB
React
Raw Normal View History

2026-01-28 17:32:54 +05:30
import React, { useEffect, useState } from "react";
import { getSession } from "../../../../Services/Others";
2026-02-09 15:43:03 +05:30
import { shallowEqual, useDispatch, useSelector } from "react-redux";
2026-01-30 16:11:37 +05:30
import {
getmultipleSearch,
2026-02-09 15:43:03 +05:30
GlobalGetmultipleSearchDatas,
2026-01-30 16:11:37 +05:30
PostProductSearch,
} from "../../../../Features/BookingScreen/BookingData/BookingData";
2026-01-28 17:32:54 +05:30
import Buttons from "../../../../Components/Forms/Buttons";
const MultipleSearch = ({ close }) => {
2026-01-30 16:11:37 +05:30
const CompId = getSession("CompId");
const BranchId = getSession("BranchId");
const AppId = getSession("AppId");
const dispatch = useDispatch();
2026-02-09 15:43:03 +05:30
const GetmultipleSearchDatas = useSelector(GlobalGetmultipleSearchDatas, shallowEqual)
2026-01-30 16:11:37 +05:30
const options = [
{ label: "Product Name", value: "ProdName" },
{ label: "Product Variant Name", value: "ProdVariantName" },
// { label: "Product ID", value: "ProdId" },
{ label: "One Piece QR", value: "OnePcQR" },
{ label: "QR Code", value: "QrCode" },
{ label: "Product Name Code", value: "ProdNameCode" },
{ label: "Category Name", value: "CategoryName" },
{ label: "Sub Category Name", value: "SubCategoryName" },
{ label: "Brand Name", value: "BrandName" },
];
const [selectedValues, setSelectedValues] = useState([]);
console.log(selectedValues, "selectedValuesselectedValues");
useEffect(() => {
2026-02-09 15:43:03 +05:30
// GetmultipleSearchData();
setSelectedValues(GetmultipleSearchDatas)
2026-01-30 16:11:37 +05:30
}, []);
const postMultipleSearch = async () => {
if (selectedValues.length === 0) {
alert("Please select at least one option!");
return;
}
const data = {
CompId: CompId,
BranchId: BranchId,
AppId: AppId,
SearchTerms: selectedValues,
2026-01-28 17:32:54 +05:30
};
2026-01-30 16:11:37 +05:30
try {
const response = await dispatch(PostProductSearch(data)).unwrap();
console.log("Search Response:", response);
if (response?.data?.statusCode == 1) {
2026-02-09 15:43:03 +05:30
GetmultipleSearchData();
2026-01-30 16:11:37 +05:30
setSelectedValues("");
close(false);
}
} catch (error) {
console.error("Search Error:", error);
}
};
2026-02-09 15:43:03 +05:30
const GetmultipleSearchData = async () => {
2026-01-30 16:11:37 +05:30
const data = {
AppId,
CompId,
BranchId,
2026-01-28 17:32:54 +05:30
};
2026-01-30 16:11:37 +05:30
try {
2026-02-09 15:43:03 +05:30
const response = await dispatch(getmultipleSearch(data))
2026-01-30 16:11:37 +05:30
} catch (error) {
console.error("Get Search Terms Error:", error);
}
};
return (
<>
<div
style={{ fontFamily: "Poppins", fontWeight: "500", marginTop: "10px" }}
>
{options.map((item) => (
<label
key={item.value}
style={{
display: "block",
marginBottom: "6px",
cursor: "pointer",
fontSize: "14px",
color: "#333",
margin: "6px 0",
}}
>
<input
type="checkbox"
checked={selectedValues.includes(item.value)}
onChange={() => {
setSelectedValues((prev) =>
prev.includes(item.value)
? prev.filter((i) => i !== item.value)
: [...prev, item.value],
);
}}
style={{ marginRight: "8px" }}
/>
{item.label}
</label>
))}
</div>
<div style={{ display: "flex", width: "100%", marginTop: "2rem" }}>
<Buttons
buttonText={"Submit"}
handleSubmit={postMultipleSearch}
2026-02-09 15:43:03 +05:30
color="901D77"
2026-01-30 16:11:37 +05:30
/>
</div>
</>
);
2026-01-28 17:32:54 +05:30
};
export default MultipleSearch;