Add working call for clock in to timeticketbrowser
This commit is contained in:
@@ -22,7 +22,6 @@ import axios from "axios";
|
||||
import { useNavigation } from "@react-navigation/native";
|
||||
// import { selectCurrentTimeTicketJobId } from "../../redux/timetickets/timetickets.selectors";
|
||||
|
||||
//TODO add props needed for call
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
currentEmployee: selectCurrentEmployee,
|
||||
currentRatesNCostCenters: selectRates,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Formik } from "formik";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useState } from "react";
|
||||
import { StyleSheet, Text, View, ScrollView } from "react-native";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
@@ -50,7 +50,6 @@ export function TimeTicketCreate({
|
||||
// const [currentSJob, setCurrentSJob] = useState(null);
|
||||
const [currentSJobId, setCurrentSJobId] = useState(null);
|
||||
|
||||
|
||||
// const wrapperSetCurrentSJobState = useCallback(
|
||||
// (val) => {
|
||||
// setCurrentSJob(val);
|
||||
@@ -70,13 +69,14 @@ export function TimeTicketCreate({
|
||||
hideDatePicker();
|
||||
};
|
||||
|
||||
const [insertTimeTicket] = useMutation(INSERT_NEW_TIME_TICKET);
|
||||
const [insertTicket] = useMutation(INSERT_NEW_TIME_TICKET);
|
||||
|
||||
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);
|
||||
|
||||
logImEXEvent("insertTimeTicket_handleFinish");
|
||||
// console.log("insertTimeTicket, currentSCC :", currentSCC);
|
||||
// console.log("insertTimeTicket, currentSCC :", currentSJobId);
|
||||
// console.log("insertTimeTicket, values :", values);
|
||||
@@ -85,89 +85,60 @@ export function TimeTicketCreate({
|
||||
!!currentSCC?.value &&
|
||||
!!currentSJobId?.value &&
|
||||
!!values.productivehours &&
|
||||
!!values.actualhours &&
|
||||
!!values.productivehours
|
||||
!!currentBodyshop.id &&
|
||||
!!currentEmployee?.technician?.id &&
|
||||
!!date2
|
||||
) {
|
||||
setError(null);
|
||||
console.log("all have values:");
|
||||
console.log("have all values");
|
||||
} else {
|
||||
console.log("missing values!");
|
||||
setLoading(false);
|
||||
setError({ message: "Please make sure all fields have a value." });
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentSJobId)
|
||||
console.log("jobid or currentSJobId", currentSJobId?.value);
|
||||
|
||||
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
|
||||
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 = {
|
||||
variables: {
|
||||
timeTicketInput: [
|
||||
{
|
||||
actualhrs: values?.actualhours ? values?.actualhours : null,
|
||||
bodyshopid: currentBodyshop.id,
|
||||
employeeid: currentEmployee?.technician?.id,
|
||||
date: moment(theTime).format("YYYY-MM-DD"),
|
||||
clockon: moment(theTime),
|
||||
jobid: currentSJobId?.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);}),
|
||||
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);
|
||||
}),
|
||||
}
|
||||
date: moment(date2).format("YYYY-MM-DD"),
|
||||
employeeid: currentEmployee?.technician?.id,
|
||||
flat_rate: currentEmployee && currentEmployee.technician && currentEmployee.technician?.flat_rate,
|
||||
jobid: currentSJobId?.value,
|
||||
productivehrs: values?.productivehours,
|
||||
rate: currentRatesNCostCenters && currentSCC?.value ? currentRatesNCostCenters.filter((r) => r.cost_center === currentSCC?.value)[0].rate : null,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
// const tempcallobj = {
|
||||
// variables: {
|
||||
// timeticketId: timeTicketId,
|
||||
// timeticket: {
|
||||
// actualhrs: values?.actualhours,
|
||||
// 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]);
|
||||
// clockoff: undefined,
|
||||
// clockon: undefined,
|
||||
// memo: undefined,
|
||||
|
||||
console.log("insertTimeTicket, tempVariablesObj. :", tempVariablesObj?.variables?.timeTicketInput[0]);
|
||||
|
||||
//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);
|
||||
setLoading(false);
|
||||
|
||||
if (!!result.errors) {
|
||||
console.log("insertTimeTicket, result.error :", result.errors);
|
||||
setError(SON.stringify(result.errors));
|
||||
} else {
|
||||
console.log("insertTimeTicket, result. :", result.data);
|
||||
navigation.goBack();
|
||||
}
|
||||
// if (!!result.errors) {
|
||||
// console.log("insertTimeTicket, result.error :", result.errors);
|
||||
// setError(JSON.stringify(result.errors));
|
||||
// } else {
|
||||
// console.log("insertTimeTicket, result. :", result.data);
|
||||
// navigation.goBack();
|
||||
// }
|
||||
// if (completedCallback) completedCallback();
|
||||
};
|
||||
|
||||
@@ -248,6 +219,7 @@ export function TimeTicketCreate({
|
||||
<Button
|
||||
style={localStyles.input}
|
||||
onPress={handleSubmit}
|
||||
loading={loading}
|
||||
title="Submit"
|
||||
>
|
||||
<Text style={{ fontSize: 12 }}>Create Ticket</Text>
|
||||
|
||||
Reference in New Issue
Block a user