updated costcenterselector
This commit is contained in:
@@ -5,12 +5,9 @@ import { Dropdown } from "react-native-element-dropdown";
|
|||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
|
|
||||||
import {
|
|
||||||
selectCurrentTimeTicketJob,
|
|
||||||
selectCurrentTimeTicketJobId,
|
|
||||||
} from "../../redux/app/app.selectors";
|
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import { QUERY_EMPLOYEE_BY_ID } from "../../graphql/employees.queries";
|
import { QUERY_EMPLOYEE_BY_ID } from "../../graphql/employees.queries";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
const data = [
|
const data = [
|
||||||
{ label: "Item 1", value: "1" },
|
{ label: "Item 1", value: "1" },
|
||||||
@@ -26,20 +23,27 @@ const data = [
|
|||||||
|
|
||||||
// const mapDispatchToProps = {};
|
// 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([]);
|
useEffect(() => {
|
||||||
const [value, setValue] = useState(null);
|
if (typeof currentRatesNCostCenters !== "undefined") {
|
||||||
const [isFocus, setIsFocus] = useState(false);
|
var count = Object.keys(currentRatesNCostCenters).length;
|
||||||
|
let selectDataArray = [];
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
// const { loading, error, data } = useQuery(QUERY_EMPLOYEE_BY_ID, {
|
selectDataArray.push({
|
||||||
// variables: { id: technician.id,},
|
value: currentRatesNCostCenters[i].cost_center,
|
||||||
// fetchPolicy: "network-only",
|
label: currentRatesNCostCenters[i].cost_center,
|
||||||
// nextFetchPolicy: "network-only",
|
rate: currentRatesNCostCenters[i].rate,
|
||||||
// }
|
});
|
||||||
// );
|
}
|
||||||
|
setCostCenters(selectDataArray);
|
||||||
|
}
|
||||||
|
}, [currentRatesNCostCenters]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
@@ -49,18 +53,19 @@ export function SelectCostCenter(props) {
|
|||||||
selectedTextStyle={styles.selectedTextStyle}
|
selectedTextStyle={styles.selectedTextStyle}
|
||||||
inputSearchStyle={styles.inputSearchStyle}
|
inputSearchStyle={styles.inputSearchStyle}
|
||||||
iconStyle={styles.iconStyle}
|
iconStyle={styles.iconStyle}
|
||||||
data={props.selectorData}
|
data={costCenters}
|
||||||
search
|
search
|
||||||
maxHeight={300}
|
maxHeight={300}
|
||||||
labelField="label"
|
labelField="label"
|
||||||
valueField="value"
|
valueField="value"
|
||||||
placeholder={!isFocus ? "Select Cost Center" : "..."}
|
placeholder={!isFocus ? "Select Cost Center" : "..."}
|
||||||
searchPlaceholder="Search..."
|
searchPlaceholder="Search..."
|
||||||
value={value}
|
value={props.currentValue?.value}
|
||||||
onFocus={() => setIsFocus(true)}
|
onFocus={() => setIsFocus(true)}
|
||||||
onBlur={() => setIsFocus(false)}
|
onBlur={() => setIsFocus(false)}
|
||||||
onChange={(item) => {
|
onChange={(item) => {
|
||||||
setValue(item.value);
|
props.onValueSelected(item);
|
||||||
|
//setValue(item.value);
|
||||||
setIsFocus(false);
|
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({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { View, Text } from "react-native";
|
import { View, Text } from "react-native";
|
||||||
|
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
@@ -15,13 +15,22 @@ import { Button } from "react-native-paper";
|
|||||||
//temp
|
//temp
|
||||||
import { useQuery } from "@apollo/client";
|
import { useQuery } from "@apollo/client";
|
||||||
import ErrorDisplay from "../error-display/error-display.component";
|
import ErrorDisplay from "../error-display/error-display.component";
|
||||||
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
|
import { JobSearchSelect } from "../Selects/select-job-name";
|
||||||
|
import { CostCenterSelect } from "../Selects/select-cost-center";
|
||||||
|
import {
|
||||||
|
selectCurrentTimeTicketJob,
|
||||||
|
selectCurrentTimeTicketJobId,
|
||||||
|
} from "../../redux/timetickets/timetickets.selectors";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentEmployee: selectCurrentEmployee,
|
currentEmployee: selectCurrentEmployee,
|
||||||
theRates: selectRates,
|
|
||||||
loaderGettingRates: selectGettingRates,
|
loaderGettingRates: selectGettingRates,
|
||||||
signingError: selectSignInError,
|
signingError: selectSignInError,
|
||||||
|
currentBodyshop: selectBodyshop,
|
||||||
|
currentRatesNCostCenters: selectRates,
|
||||||
|
currentSelectedTimeTicketJobId: selectCurrentTimeTicketJobId,
|
||||||
|
currentSelectedTimeTicketJob: selectCurrentTimeTicketJob,
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
@@ -33,33 +42,83 @@ export function ScreenTimeTicketBrowser({
|
|||||||
loaderGettingRates,
|
loaderGettingRates,
|
||||||
currentEmployee,
|
currentEmployee,
|
||||||
employeeGetRatesStart,
|
employeeGetRatesStart,
|
||||||
signingError
|
signingError,
|
||||||
|
currentBodyshop,
|
||||||
|
currentRatesNCostCenters,
|
||||||
|
currentSelectedTimeTicketJob,
|
||||||
|
currentSelectedTimeTicketJobId,
|
||||||
}) {
|
}) {
|
||||||
const employeeId = currentEmployee.technician.id;
|
//const employeeId = currentEmployee.technician.id;
|
||||||
|
const [currentCC, setCurrentCC] = useState(null);
|
||||||
|
|
||||||
// const { error, data } = useQuery(QUERY_EMPLOYEE_BY_ID, {
|
// const { error, data } = useQuery(QUERY_EMPLOYEE_BY_ID, {
|
||||||
// variables: { id: currentEmployee.technician.id },
|
// variables: { id: currentEmployee.technician.id },
|
||||||
// });
|
// });
|
||||||
// const signingErrorMsg = error ? (<ErrorDisplay errorMessage={error.message} />) : null;
|
// const signingErrorMsg = error ? (<ErrorDisplay errorMessage={error.message} />) : null;
|
||||||
// const signingErrorMsg = signingError ? (<ErrorDisplay errorMessage={signingError} />) : null;
|
// const signingErrorMsg = signingError ? (<ErrorDisplay errorMessage={signingError} />) : null;
|
||||||
|
|
||||||
const getRates = (currentEmployee) => {
|
const getRates = (currentEmployee) => {
|
||||||
employeeGetRatesStart(currentEmployee.technician.id);
|
employeeGetRatesStart(currentEmployee.technician.id);
|
||||||
};
|
};
|
||||||
|
const createTheTimeTicketOBJ = (
|
||||||
|
currentEmployee,
|
||||||
|
currentBodyshop,
|
||||||
|
currentCC
|
||||||
|
) => {
|
||||||
|
console.log("currentCC", currentCC.value);
|
||||||
|
console.log("bodyshopid", currentBodyshop.id);
|
||||||
|
console.log("employeeid", currentEmployee.technician.id);
|
||||||
|
console.log(currentBodyshop);
|
||||||
|
// const temp = {
|
||||||
|
// timeTicketInput: [
|
||||||
|
// {
|
||||||
|
// bodyshopid: currentBodyshop?.id,
|
||||||
|
// employeeid: currentEmployee?.technician?.id,
|
||||||
|
// date: "2023-05-11", //moment(theTime).format("YYYY-MM-DD"),
|
||||||
|
// //clockon: moment(theTime),
|
||||||
|
// jobid: "temp",//values.jobid,
|
||||||
|
// cost_center: "temp",//values.cost_center,
|
||||||
|
// ciecacode: currentBodyshop?.cdk_dealerid || currentBodyshop?.pbs_serialnumber
|
||||||
|
// ? values.cost_center
|
||||||
|
// : Object.keys(currentBodyshop.md_responsibility_centers.defaults.costs).find((key) => {
|
||||||
|
// return (currentBodyshop.md_responsibility_centers.defaults.costs[key] === "temp");//values.cost_center);
|
||||||
|
// }),
|
||||||
|
// flat_rate: currentEmployee.technician.flat_rate,
|
||||||
|
// rate: 1,
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// };
|
||||||
|
// console.log(temp);
|
||||||
|
//employeeGetRatesStart(currentEmployee.technician.id);
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<Text>Time Ticket List goes here</Text>
|
<Text>Time Ticket List goes here</Text>
|
||||||
<Button
|
<Button
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
loading={loaderGettingRates}
|
loading={loaderGettingRates}
|
||||||
onPress={() => getRates(currentEmployee)}
|
//onPress={() => getRates(currentEmployee)}
|
||||||
>
|
onPress={() =>
|
||||||
<Text>text here</Text>
|
createTheTimeTicketOBJ(currentEmployee, currentBodyshop, currentCC)
|
||||||
</Button>
|
}
|
||||||
{/* {signingErrorMsg} */}
|
>
|
||||||
|
<Text>text here</Text>
|
||||||
|
</Button>
|
||||||
|
{/* {signingErrorMsg} */}
|
||||||
|
<JobSearchSelect
|
||||||
|
convertedOnly={!currentBodyshop.tt_allow_post_to_invoiced}
|
||||||
|
notExported={!currentBodyshop.tt_allow_post_to_invoiced}
|
||||||
|
/>
|
||||||
|
<CostCenterSelect
|
||||||
|
currentValue={currentCC}
|
||||||
|
currentRatesNCostCenters={currentRatesNCostCenters}
|
||||||
|
onValueSelected={setCurrentCC}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(ScreenTimeTicketBrowser);
|
export default connect(
|
||||||
|
mapStateToProps,
|
||||||
|
mapDispatchToProps
|
||||||
|
)(ScreenTimeTicketBrowser);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { Button, Dialog, TextInput } from "react-native-paper";
|
import { Button, Dialog, TextInput } from "react-native-paper";
|
||||||
import { SelectCostCenter } from "../Selects/select-cost-center";
|
import { CostCenterSelect } from "../Selects/select-cost-center";
|
||||||
import { JobSearchSelect } from "../Selects/select-job-name";
|
import { JobSearchSelect } from "../Selects/select-job-name";
|
||||||
import DateTimePickerModal from "react-native-modal-datetime-picker";
|
import DateTimePickerModal from "react-native-modal-datetime-picker";
|
||||||
import {
|
import {
|
||||||
@@ -31,7 +31,8 @@ export function TimeTicketCreate({
|
|||||||
|
|
||||||
const [isDatePickerVisible, setDatePickerVisibility] = useState(false);
|
const [isDatePickerVisible, setDatePickerVisibility] = useState(false);
|
||||||
const [date2, setDate2] = useState(new Date());
|
const [date2, setDate2] = useState(new Date());
|
||||||
const [costCenters, setCostCenters] = useState([]);
|
|
||||||
|
const [currentCC, setCurrentCC] = useState(null);
|
||||||
|
|
||||||
const showDatePicker = () => {
|
const showDatePicker = () => {
|
||||||
setDatePickerVisibility(true);
|
setDatePickerVisibility(true);
|
||||||
@@ -49,20 +50,6 @@ export function TimeTicketCreate({
|
|||||||
//TODO update with start call for create time ticket
|
//TODO update with start call for create time ticket
|
||||||
};
|
};
|
||||||
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
setCostCenters(selectDataArray);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={localStyles.content}>
|
<View style={localStyles.content}>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
@@ -106,8 +93,7 @@ export function TimeTicketCreate({
|
|||||||
label={"Employee"}
|
label={"Employee"}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SelectCostCenter selectorData={costCenters} />
|
<CostCenterSelect currentRatesNCostCenters={currentRatesNCostCenters} currentValue={currentCC} onValueSelected={setCurrentCC}/>
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
style={localStyles.inputStyle}
|
style={localStyles.inputStyle}
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
|
|||||||
Reference in New Issue
Block a user