Add working call for clock in to timeticketbrowser
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useCallback, useEffect, useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { View, Text } from "react-native";
|
import { View, Text } from "react-native";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
@@ -26,6 +26,10 @@ import moment from "moment";
|
|||||||
import { EmployeeClockedInList } from "../time-ticket-lists/employee-clockedin-list.component";
|
import { EmployeeClockedInList } from "../time-ticket-lists/employee-clockedin-list.component";
|
||||||
import { useNavigation } from "@react-navigation/native";
|
import { useNavigation } from "@react-navigation/native";
|
||||||
|
|
||||||
|
import { INSERT_NEW_TIME_TICKET } from "../../graphql/timetickets.queries";
|
||||||
|
import { useMutation } from "@apollo/client";
|
||||||
|
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentEmployee: selectCurrentEmployee,
|
currentEmployee: selectCurrentEmployee,
|
||||||
loaderGettingRates: selectGettingRates,
|
loaderGettingRates: selectGettingRates,
|
||||||
@@ -54,9 +58,12 @@ export function ScreenTimeTicketBrowser({
|
|||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
//const employeeId = currentEmployee.technician.id;
|
//const employeeId = currentEmployee.technician.id;
|
||||||
const [currentSCC, setCurrentSCC] = useState(null);
|
const [currentSCC, setCurrentSCC] = useState(null);
|
||||||
// const [currentSJob, setCurrentSJob] = useState(null);
|
|
||||||
const [currentSJobId, setCurrentSJobId] = useState(null);
|
const [currentSJobId, setCurrentSJobId] = useState(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
const [insertTimeTicket] = useMutation(INSERT_NEW_TIME_TICKET, {
|
||||||
|
refetchQueries: ["QUERY_ACTIVE_TIME_TICKETS"],
|
||||||
|
});
|
||||||
// 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 },
|
||||||
// });
|
// });
|
||||||
@@ -69,78 +76,81 @@ export function ScreenTimeTicketBrowser({
|
|||||||
// },
|
// },
|
||||||
// [setCurrentSJobId]
|
// [setCurrentSJobId]
|
||||||
// );
|
// );
|
||||||
|
const handleFinish = async (values) => {
|
||||||
|
console.log("handleFinish called in ScreenTimeTicketBrowser");
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
//do stuff...
|
||||||
|
|
||||||
const getRates = (currentEmployee) => {
|
|
||||||
employeeGetRatesStart(currentEmployee.technician.id);
|
|
||||||
};
|
|
||||||
const createTheTimeTicketOBJ = async (
|
|
||||||
currentEmployee,
|
|
||||||
currentBodyshop,
|
|
||||||
currentSCC,
|
|
||||||
currentSJobId
|
|
||||||
) => {
|
|
||||||
const theTime = (await axios.post("/utils/time")).data;
|
const theTime = (await axios.post("/utils/time")).data;
|
||||||
if (currentBodyshop) console.log("bodyshopid", currentBodyshop?.id);
|
|
||||||
if (currentEmployee) console.log("employeeid", currentEmployee?.technician.id);
|
|
||||||
if (theTime) console.log("date", moment(theTime).format("YYYY-MM-DD"));
|
|
||||||
// if (currentSJob) console.log("currentSJob", currentSJob?.value);
|
|
||||||
if (currentSJobId) console.log("jobid or currentSJobId", currentSJobId?.value);
|
|
||||||
if (currentSCC) console.log("cost_center or currentSCC", currentSCC?.value);
|
|
||||||
//if(currentBodyshop)console.log(currentBodyshop);
|
|
||||||
if (currentBodyshop)
|
|
||||||
console.log(
|
|
||||||
"ciecacode",
|
|
||||||
currentBodyshop?.cdk_dealerid || currentBodyshop?.pbs_serialnumber
|
|
||||||
? currentSCC?.value
|
|
||||||
: Object.keys(
|
|
||||||
currentBodyshop.md_responsibility_centers.defaults.costs
|
|
||||||
).find((key) => {
|
|
||||||
return (
|
|
||||||
currentBodyshop.md_responsibility_centers.defaults.costs[
|
|
||||||
key
|
|
||||||
] === currentSCC?.value
|
|
||||||
);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
if (currentEmployee)
|
|
||||||
console.log("flat_rate", currentEmployee?.technician?.flat_rate);
|
|
||||||
|
|
||||||
if (currentSCC) console.log("rate or currentSCC", currentSCC?.rate);
|
if (!!currentSCC?.value && !!currentSJobId?.value) {
|
||||||
// const temp = {
|
setError(null);
|
||||||
// timeTicketInput: [
|
console.log("have all values");
|
||||||
// {
|
} else {
|
||||||
//have bodyshopid: currentBodyshop?.id,
|
console.log("missing values!");
|
||||||
//have employeeid: currentEmployee?.technician?.id,
|
setLoading(false);
|
||||||
//have date: "2023-05-11", //moment(theTime).format("YYYY-MM-DD"),
|
setError({ message: "Please make sure all fields have a value." });
|
||||||
// //clockon: moment(theTime),
|
return;
|
||||||
// jobid: "temp",//values.jobid,
|
}
|
||||||
//have cost_center: "temp",//values.cost_center,
|
|
||||||
//have ciecacode: currentBodyshop?.cdk_dealerid || currentBodyshop?.pbs_serialnumber
|
if (currentSJobId)
|
||||||
// ? values.cost_center
|
console.log("jobid or currentSJobId", currentSJobId?.value);
|
||||||
// : Object.keys(currentBodyshop.md_responsibility_centers.defaults.costs).find((key) => {
|
|
||||||
// return (currentBodyshop.md_responsibility_centers.defaults.costs[key] === "temp");//values.cost_center);
|
|
||||||
// }),
|
const tempVariablesObj = {
|
||||||
//have flat_rate: currentEmployee.technician.flat_rate,
|
variables: {
|
||||||
//have rate: 1,
|
timeTicketInput: [
|
||||||
// },
|
{
|
||||||
// ],
|
bodyshopid: currentBodyshop.id,
|
||||||
// };
|
employeeid: currentEmployee?.technician?.id,
|
||||||
// console.log(temp);
|
date: moment(theTime).format("YYYY-MM-DD"),
|
||||||
//employeeGetRatesStart(currentEmployee.technician.id);
|
clockon: moment(theTime),
|
||||||
|
jobid: currentSJobId?.value,
|
||||||
|
cost_center: currentSCC?.value,
|
||||||
|
ciecacode:
|
||||||
|
currentBodyshop?.cdk_dealerid || currentBodyshop?.pbs_serialnumber
|
||||||
|
? currentSCC?.value
|
||||||
|
: Object.keys(
|
||||||
|
currentBodyshop.md_responsibility_centers.defaults.costs
|
||||||
|
).find((key) => {
|
||||||
|
return (
|
||||||
|
currentBodyshop.md_responsibility_centers.defaults.costs[
|
||||||
|
key
|
||||||
|
] === currentSCC?.value
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
console.info(
|
||||||
|
"INSERT_NEW_TIME_TICKET, variables for clockin. : ",
|
||||||
|
tempVariablesObj?.variables?.timeTicketInput[0]
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
const result = await insertTimeTicket(tempVariablesObj);
|
||||||
|
console.log("insertTimeTicket, result :", result);
|
||||||
|
|
||||||
|
if (!!result.errors) {
|
||||||
|
console.log("insertTimeTicket, result.error :", result.errors);
|
||||||
|
setError(JSON.stringify(result.errors));
|
||||||
|
} else {
|
||||||
|
console.log("insertTimeTicket, result. :", result.data);
|
||||||
|
//show success
|
||||||
|
//clear fields
|
||||||
|
|
||||||
|
setCurrentSJobId(null);
|
||||||
|
setCurrentSCC(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<View style={{flex:1}}>
|
||||||
{/* <Button
|
|
||||||
mode="outlined"
|
|
||||||
loading={loaderGettingRates}
|
|
||||||
//onPress={() => getRates(currentEmployee)}
|
|
||||||
onPress={() =>
|
|
||||||
createTheTimeTicketOBJ(currentEmployee, currentBodyshop, currentSCC, currentSJobId)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Text>createTheTimeTicketOBJTest</Text>
|
|
||||||
</Button> */}
|
|
||||||
{/* {signingErrorMsg} */}
|
|
||||||
<JobIdSearchSelect
|
<JobIdSearchSelect
|
||||||
currentValue={currentSJobId}
|
currentValue={currentSJobId}
|
||||||
onJobSelected={setCurrentSJobId}
|
onJobSelected={setCurrentSJobId}
|
||||||
@@ -152,13 +162,12 @@ export function ScreenTimeTicketBrowser({
|
|||||||
currentRatesNCostCenters={currentRatesNCostCenters}
|
currentRatesNCostCenters={currentRatesNCostCenters}
|
||||||
onValueSelected={setCurrentSCC}
|
onValueSelected={setCurrentSCC}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button mode="outlined" loading={loading} onPress={handleFinish}>
|
||||||
mode="outlined"
|
|
||||||
//loading={loaderClockIn}
|
|
||||||
//onPress={() => clockIn()}
|
|
||||||
>
|
|
||||||
<Text>Clock In</Text>
|
<Text>Clock In</Text>
|
||||||
</Button>
|
</Button>
|
||||||
|
{error && error?.message ? (
|
||||||
|
<ErrorDisplay errorMessage={error.message} />
|
||||||
|
) : null}
|
||||||
|
|
||||||
<EmployeeClockedInList technician={currentEmployee} />
|
<EmployeeClockedInList technician={currentEmployee} />
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
export function EmployeeClockedInList({ technician }) {
|
export function EmployeeClockedInList({ technician }) {
|
||||||
|
console.info("EmployeeClockedInList, QUERY_ACTIVE_TIME_TICKETS called.");
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { loading, error, data, refetch } = useQuery(
|
const { loading, error, data, refetch } = useQuery(
|
||||||
@@ -39,15 +41,12 @@ export function EmployeeClockedInList({ technician }) {
|
|||||||
if (loading) return <ActivityIndicator color="dodgerblue" size="large" />;
|
if (loading) return <ActivityIndicator color="dodgerblue" size="large" />;
|
||||||
if (error) return <ErrorDisplay errorMessage={error.message} />;
|
if (error) return <ErrorDisplay errorMessage={error.message} />;
|
||||||
|
|
||||||
console.log("EmployeeClockedInList, QUERY_ACTIVE_TIME_TICKETS data:", data);
|
|
||||||
// if (data) () => {setTmTicketJobId(data)}
|
|
||||||
|
|
||||||
const onRefresh = async () => {
|
const onRefresh = async () => {
|
||||||
return refetch();
|
return refetch();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<View style={{ flex:1, flexGrow:1 }} >
|
||||||
{data.timetickets.length > 0 ? (
|
{data.timetickets.length > 0 ? (
|
||||||
<View>
|
<View>
|
||||||
<Text style={{ paddingLeft: 12, paddingTop: 14 }}>
|
<Text style={{ paddingLeft: 12, paddingTop: 14 }}>
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import axios from "axios";
|
|||||||
import { useNavigation } from "@react-navigation/native";
|
import { useNavigation } from "@react-navigation/native";
|
||||||
// import { selectCurrentTimeTicketJobId } from "../../redux/timetickets/timetickets.selectors";
|
// import { selectCurrentTimeTicketJobId } from "../../redux/timetickets/timetickets.selectors";
|
||||||
|
|
||||||
//TODO add props needed for call
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentEmployee: selectCurrentEmployee,
|
currentEmployee: selectCurrentEmployee,
|
||||||
currentRatesNCostCenters: selectRates,
|
currentRatesNCostCenters: selectRates,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Formik } from "formik";
|
import { Formik } from "formik";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { StyleSheet, Text, View, ScrollView } from "react-native";
|
import { StyleSheet, Text, View, ScrollView } from "react-native";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
@@ -50,7 +50,6 @@ export function TimeTicketCreate({
|
|||||||
// const [currentSJob, setCurrentSJob] = useState(null);
|
// const [currentSJob, setCurrentSJob] = useState(null);
|
||||||
const [currentSJobId, setCurrentSJobId] = useState(null);
|
const [currentSJobId, setCurrentSJobId] = useState(null);
|
||||||
|
|
||||||
|
|
||||||
// const wrapperSetCurrentSJobState = useCallback(
|
// const wrapperSetCurrentSJobState = useCallback(
|
||||||
// (val) => {
|
// (val) => {
|
||||||
// setCurrentSJob(val);
|
// setCurrentSJob(val);
|
||||||
@@ -70,13 +69,14 @@ export function TimeTicketCreate({
|
|||||||
hideDatePicker();
|
hideDatePicker();
|
||||||
};
|
};
|
||||||
|
|
||||||
const [insertTimeTicket] = useMutation(INSERT_NEW_TIME_TICKET);
|
const [insertTicket] = useMutation(INSERT_NEW_TIME_TICKET);
|
||||||
|
|
||||||
const handleFinish = async (values) => {
|
const handleFinish = async (values) => {
|
||||||
const theTime = (await axios.post("/utils/time")).data;
|
logImEXEvent("handleFinish_called_in_TimeTicketCreate");
|
||||||
|
console.log("handleFinish called in TimeTicketCreate");
|
||||||
|
setError(null);
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
logImEXEvent("insertTimeTicket_handleFinish");
|
|
||||||
// console.log("insertTimeTicket, currentSCC :", currentSCC);
|
// console.log("insertTimeTicket, currentSCC :", currentSCC);
|
||||||
// console.log("insertTimeTicket, currentSCC :", currentSJobId);
|
// console.log("insertTimeTicket, currentSCC :", currentSJobId);
|
||||||
// console.log("insertTimeTicket, values :", values);
|
// console.log("insertTimeTicket, values :", values);
|
||||||
@@ -85,89 +85,60 @@ export function TimeTicketCreate({
|
|||||||
!!currentSCC?.value &&
|
!!currentSCC?.value &&
|
||||||
!!currentSJobId?.value &&
|
!!currentSJobId?.value &&
|
||||||
!!values.productivehours &&
|
!!values.productivehours &&
|
||||||
!!values.actualhours &&
|
!!currentBodyshop.id &&
|
||||||
!!values.productivehours
|
!!currentEmployee?.technician?.id &&
|
||||||
|
!!date2
|
||||||
) {
|
) {
|
||||||
setError(null);
|
setError(null);
|
||||||
console.log("all have values:");
|
console.log("have all values");
|
||||||
} else {
|
} else {
|
||||||
console.log("missing values!");
|
console.log("missing values!");
|
||||||
|
setLoading(false);
|
||||||
setError({ message: "Please make sure all fields have a value." });
|
setError({ message: "Please make sure all fields have a value." });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentSJobId)
|
if (date2) console.log("rate :", currentRatesNCostCenters && currentSCC?.value ? currentRatesNCostCenters.filter((r) => r.cost_center === currentSCC?.value)[0].rate : null);//2023-05-16T16:45:27.154Z
|
||||||
console.log("jobid or currentSJobId", currentSJobId?.value);
|
if (date2) console.log("bodyshopid : ", currentBodyshop.id);
|
||||||
|
if (date2) console.log("moment(date2).format(YYYY-MM-DD)", moment(date2).format("YYYY-MM-DD"));
|
||||||
const tempVariablesObj = {
|
const tempVariablesObj = {
|
||||||
variables: {
|
variables: {
|
||||||
timeTicketInput: [
|
timeTicketInput: [
|
||||||
{
|
{
|
||||||
|
actualhrs: values?.actualhours ? values?.actualhours : null,
|
||||||
bodyshopid: currentBodyshop.id,
|
bodyshopid: currentBodyshop.id,
|
||||||
employeeid: currentEmployee?.technician?.id,
|
ciecacode: currentBodyshop?.cdk_dealerid || currentBodyshop?.pbs_serialnumber ? currentSCC?.value : Object.keys(currentBodyshop.md_responsibility_centers.defaults.costs).find((key) => {return (currentBodyshop.md_responsibility_centers.defaults.costs[key] === currentSCC?.value);}),
|
||||||
date: moment(theTime).format("YYYY-MM-DD"),
|
|
||||||
clockon: moment(theTime),
|
|
||||||
jobid: currentSJobId?.value,
|
|
||||||
cost_center: currentSCC?.value,
|
cost_center: currentSCC?.value,
|
||||||
ciecacode: currentBodyshop?.cdk_dealerid || currentBodyshop?.pbs_serialnumber ? currentSCC?.value :
|
date: moment(date2).format("YYYY-MM-DD"),
|
||||||
Object.keys(currentBodyshop.md_responsibility_centers.defaults.costs).find(
|
employeeid: currentEmployee?.technician?.id,
|
||||||
(key) => {
|
flat_rate: currentEmployee && currentEmployee.technician && currentEmployee.technician?.flat_rate,
|
||||||
return (currentBodyshop.md_responsibility_centers.defaults.costs[key] === currentSCC?.value);
|
jobid: currentSJobId?.value,
|
||||||
}),
|
productivehrs: values?.productivehours,
|
||||||
}
|
rate: currentRatesNCostCenters && currentSCC?.value ? currentRatesNCostCenters.filter((r) => r.cost_center === currentSCC?.value)[0].rate : null,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
// const tempcallobj = {
|
// clockoff: undefined,
|
||||||
// variables: {
|
// clockon: undefined,
|
||||||
// timeticketId: timeTicketId,
|
// memo: undefined,
|
||||||
// timeticket: {
|
|
||||||
// actualhrs: values?.actualhours,
|
console.log("insertTimeTicket, tempVariablesObj. :", tempVariablesObj?.variables?.timeTicketInput[0]);
|
||||||
// ciecacode:
|
|
||||||
// currentBodyshop?.cdk_dealerid || currentBodyshop?.pbs_serialnumber
|
|
||||||
// ? currentSCC?.value
|
|
||||||
// : Object.keys(
|
|
||||||
// currentBodyshop.md_responsibility_centers.defaults.costs
|
|
||||||
// ).find((key) => {
|
|
||||||
// return (
|
|
||||||
// currentBodyshop.md_responsibility_centers.defaults.costs[
|
|
||||||
// key
|
|
||||||
// ] === currentSCC?.value
|
|
||||||
// );
|
|
||||||
// }),
|
|
||||||
// clockoff: (await axios.post("/utils/time")).data,
|
|
||||||
// cost_center: currentSCC?.value,
|
|
||||||
// flat_rate:
|
|
||||||
// currentEmployee &&
|
|
||||||
// currentEmployee.technician &&
|
|
||||||
// currentEmployee.technician?.flat_rate,
|
|
||||||
// productivehrs: values?.productivehours,
|
|
||||||
// rate:
|
|
||||||
// currentRatesNCostCenters &&
|
|
||||||
// currentSCC?.value &&
|
|
||||||
// currentRatesNCostCenters.filter(
|
|
||||||
// (r) => r.cost_center === currentSCC?.value
|
|
||||||
// )[0]?.rate,
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// };
|
|
||||||
console.log("insertTimeTicket, tempVariablesObj :", tempVariablesObj?.variables?.timeTicketInput[0]);
|
|
||||||
|
|
||||||
//after obj is good add below to make call
|
//after obj is good add below to make call
|
||||||
|
|
||||||
const result = await insertTimeTicket(tempVariablesObj);
|
const result = await insertTicket(tempVariablesObj);
|
||||||
|
|
||||||
//after call results are retuning add handling below for cases
|
// //after call results are retuning add handling below for cases
|
||||||
console.log("insertTimeTicket, result :", result);
|
console.log("insertTimeTicket, result :", result);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
// if (!!result.errors) {
|
||||||
if (!!result.errors) {
|
// console.log("insertTimeTicket, result.error :", result.errors);
|
||||||
console.log("insertTimeTicket, result.error :", result.errors);
|
// setError(JSON.stringify(result.errors));
|
||||||
setError(SON.stringify(result.errors));
|
// } else {
|
||||||
} else {
|
// console.log("insertTimeTicket, result. :", result.data);
|
||||||
console.log("insertTimeTicket, result. :", result.data);
|
// navigation.goBack();
|
||||||
navigation.goBack();
|
// }
|
||||||
}
|
|
||||||
// if (completedCallback) completedCallback();
|
// if (completedCallback) completedCallback();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -248,6 +219,7 @@ export function TimeTicketCreate({
|
|||||||
<Button
|
<Button
|
||||||
style={localStyles.input}
|
style={localStyles.input}
|
||||||
onPress={handleSubmit}
|
onPress={handleSubmit}
|
||||||
|
loading={loading}
|
||||||
title="Submit"
|
title="Submit"
|
||||||
>
|
>
|
||||||
<Text style={{ fontSize: 12 }}>Create Ticket</Text>
|
<Text style={{ fontSize: 12 }}>Create Ticket</Text>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import gql from "graphql-tag";
|
import gql from "graphql-tag";
|
||||||
|
|
||||||
//TODO: find out if cdk_dealerid, pbs_serialnumber and md_responsibility_centers.defaults.costs need to be added to this
|
|
||||||
export const QUERY_BODYSHOP = gql`
|
export const QUERY_BODYSHOP = gql`
|
||||||
query QUERY_BODYSHOP {
|
query QUERY_BODYSHOP {
|
||||||
bodyshops(where: { associations: { active: { _eq: true } } }) {
|
bodyshops(where: { associations: { active: { _eq: true } } }) {
|
||||||
|
|||||||
Reference in New Issue
Block a user