updated costcenterselector
This commit is contained in:
@@ -5,12 +5,9 @@ import { Dropdown } from "react-native-element-dropdown";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
|
||||
import {
|
||||
selectCurrentTimeTicketJob,
|
||||
selectCurrentTimeTicketJobId,
|
||||
} from "../../redux/app/app.selectors";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { QUERY_EMPLOYEE_BY_ID } from "../../graphql/employees.queries";
|
||||
import { useEffect } from "react";
|
||||
|
||||
const data = [
|
||||
{ label: "Item 1", value: "1" },
|
||||
@@ -26,20 +23,27 @@ const data = [
|
||||
|
||||
// const mapDispatchToProps = {};
|
||||
|
||||
export function SelectCostCenter(props) {
|
||||
export function CostCenterSelect(props) {
|
||||
const currentRatesNCostCenters = props.currentRatesNCostCenters;
|
||||
|
||||
const [value, setValue] = useState(null);
|
||||
const [isFocus, setIsFocus] = useState(false);
|
||||
const [costCenters, setCostCenters] = useState([]);
|
||||
|
||||
const [selectorData, setSelectorData] = useState([]);
|
||||
const [value, setValue] = useState(null);
|
||||
const [isFocus, setIsFocus] = useState(false);
|
||||
|
||||
|
||||
// const { loading, error, data } = useQuery(QUERY_EMPLOYEE_BY_ID, {
|
||||
// variables: { id: technician.id,},
|
||||
// fetchPolicy: "network-only",
|
||||
// nextFetchPolicy: "network-only",
|
||||
// }
|
||||
// );
|
||||
useEffect(() => {
|
||||
if (typeof currentRatesNCostCenters !== "undefined") {
|
||||
var count = Object.keys(currentRatesNCostCenters).length;
|
||||
let selectDataArray = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
selectDataArray.push({
|
||||
value: currentRatesNCostCenters[i].cost_center,
|
||||
label: currentRatesNCostCenters[i].cost_center,
|
||||
rate: currentRatesNCostCenters[i].rate,
|
||||
});
|
||||
}
|
||||
setCostCenters(selectDataArray);
|
||||
}
|
||||
}, [currentRatesNCostCenters]);
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
@@ -49,18 +53,19 @@ export function SelectCostCenter(props) {
|
||||
selectedTextStyle={styles.selectedTextStyle}
|
||||
inputSearchStyle={styles.inputSearchStyle}
|
||||
iconStyle={styles.iconStyle}
|
||||
data={props.selectorData}
|
||||
data={costCenters}
|
||||
search
|
||||
maxHeight={300}
|
||||
labelField="label"
|
||||
valueField="value"
|
||||
placeholder={!isFocus ? "Select Cost Center" : "..."}
|
||||
searchPlaceholder="Search..."
|
||||
value={value}
|
||||
value={props.currentValue?.value}
|
||||
onFocus={() => setIsFocus(true)}
|
||||
onBlur={() => setIsFocus(false)}
|
||||
onChange={(item) => {
|
||||
setValue(item.value);
|
||||
props.onValueSelected(item);
|
||||
//setValue(item.value);
|
||||
setIsFocus(false);
|
||||
}}
|
||||
/>
|
||||
@@ -68,7 +73,7 @@ export function SelectCostCenter(props) {
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(null, null)(SelectCostCenter);
|
||||
export default connect(null, null)(CostCenterSelect);
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
|
||||
Reference in New Issue
Block a user