Add clockoutcall + grab vals to TimeTicketClockOff

This commit is contained in:
jfrye122
2023-05-15 23:44:37 -04:00
parent b13e84b8e1
commit da6464e624
3 changed files with 60 additions and 167 deletions

View File

@@ -1,28 +0,0 @@
import React from "react";
import { Text } from "react-native";
import { Button } from "react-native-paper";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { employeeSignOut } from "../../redux/employee/employee.actions";
import { setTmTicketJobId } from "../../redux/app/app.actions";
const mapDispatchToProps = (dispatch) => ({
signOut:(jobId) => dispatch(setTmTicketJobId()),
});
export function TechClockOffButton({ setTmTicketJobId,
jobId,
timeTicketId, }) {
const { t } = useTranslation();
return (
<Button
mode="text"
compact={true}
onPress={() => signOut()}
icon="logout"
>
<Text style={{fontSize: 12}}>{t("general.actions.logout")}</Text>
</Button>
);
}
export default connect(null, mapDispatchToProps)(SignOutButton);

View File

@@ -38,7 +38,7 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician }) {
const [totals, setTotals] = useState([]);
useEffect(() => {
console.log("LaborAllocationsTable useEffect on data change");
// console.log("LaborAllocationsTable useEffect on data change");
}, [data]);
useEffect(() => {

View File

@@ -1,5 +1,5 @@
import { Formik } from "formik";
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { StyleSheet, Text, View, ScrollView } from "react-native";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
@@ -18,6 +18,8 @@ import { selectCurrentTmTicketJobId } from "../../redux/app/app.selectors";
import ErrorDisplay from "../error-display/error-display.component";
import { timeTicketClockOutStart } from "../../redux/timetickets/timetickets.actions";
import { logImEXEvent } from "../../firebase/firebase.analytics";
import axios from "axios";
import { useNavigation } from "@react-navigation/native";
// import { selectCurrentTimeTicketJobId } from "../../redux/timetickets/timetickets.selectors";
//TODO add props needed for call
@@ -26,13 +28,10 @@ const mapStateToProps = createStructuredSelector({
currentRatesNCostCenters: selectRates,
currentBodyshop: selectBodyshop,
currentTmTicketJobId: selectCurrentTmTicketJobId,
//add way to get timeTicketId
// currentJobId: selectCurrentTimeTicketJobId
});
const mapDispatchToProps = (dispatch) => ({
timeTicketClockOutStart
});
const mapDispatchToProps = (dispatch) => ({
timeTicketClockOutStart,
});
export function TimeTicketClockOff({
currentEmployee,
@@ -41,157 +40,84 @@ export function TimeTicketClockOff({
currentTmTicketJobId,
route,
}) {
const navigation = useNavigation();
const { timeTicketId } = route.params;
console.log("TimeTicketClockOff, timeTicketId :", timeTicketId);
//console.log("TimeTicketClockOff, currentRatesNCostCenters :", currentRatesNCostCenters );
// console.log("TimeTicketClockOff, currentBodyshop :", currentBodyshop);
// console.log("TimeTicketClockOff, timeTicketId :", timeTicketId);
// console.log( "TimeTicketClockOff, currentTmTicketJobId :", currentTmTicketJobId );
console.log("TimeTicketClockOff, currentTmTicketJobId :", currentTmTicketJobId);
// console.log("TimeTicketClockOff, jobId :", jobId);
// console.log("TimeTicketClockOff, timeTicketId :", timeTicketId);
const { t } = useTranslation();
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const [currentSCC, setCurrentSCC] = useState(null);
// const [currentSJob, setCurrentSJob] = useState(null);
const [currentSJobId, setCurrentSJobId] = useState(currentTmTicketJobId ? currentTmTicketJobId : null);
// const [updateTimeticket] = useMutation(UPDATE_TIME_TICKET);
// const wrapperSetCurrentSJobState = useCallback(
// (val) => {
// setCurrentSJob(val);
// },
// [setCurrentSJob]
// );
// const showDatePicker = () => {
// setDatePickerVisibility(true);
// };
// const hideDatePicker = () => {
// setDatePickerVisibility(false);
// };
// const handleConfirm = (date) => {
// setDate2(date);
// //console.war1n("A date has been picked: ", date);
// hideDatePicker();
// };
const formSubmit = (values) => {
console.log("values", values);
//Dialog.alert({ content: <pre>{JSON.stringify(values, null, 2)}</pre> });
//TODO update with start call for create time ticket
};
const [updateTimeticket] = useMutation(UPDATE_TIME_TICKET);
const handleFinish = async (values) => {
logImEXEvent("TimeTicketClockOff_handleFinish");
// console.log("TimeTicketClockOff, values.cost_center?.value :", currentSCC);
//build obj
if (
!!values.actualhours &&
!!values.productivehours &&
!!currentSCC?.value
) {
setError(null);
console.log("all have values:");
} else {
console.log("missing values!");
setError({ message: "Please make sure all fields have a value." });
}
const tempcallobj = {
variables: {
timeticketId: timeTicketId,
timeticket: {
clockoff: (await axios.post("/utils/time")).data,
...values,
rate:
emps &&
emps.rates.filter((r) => r.cost_center === values.cost_center)[0]
?.rate,
flat_rate: emps && emps.flat_rate,
actualhrs: values?.actualhours,
ciecacode:
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber
? values.cost_center
currentBodyshop?.cdk_dealerid || currentBodyshop?.pbs_serialnumber
? currentSCC?.value
: Object.keys(
bodyshop.md_responsibility_centers.defaults.costs
currentBodyshop.md_responsibility_centers.defaults.costs
).find((key) => {
return (
bodyshop.md_responsibility_centers.defaults.costs[key] ===
values.cost_center
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("TimeTicketClockOff, tempcallobj :", tempcallobj);
console.log("TimeTicketClockOff, tempcallobj :",tempcallobj);
//after obj is good add below to make call
setLoading(true);
const result = await updateTimeticket(tempcallobj);
//after obj is good add below to make call
//setLoading(true);
//const result = await updateTimeticket();
//after call results are retuning add handling below for cases
// if (!!result.errors) {
// notification["error"]({
// message: t("timetickets.errors.clockingout", {
// message: JSON.stringify(result.errors),
// }),
// });
// } else {
// notification["success"]({
// message: t("timetickets.successes.clockedout"),
// });
// }
//after call results are retuning add handling below for cases
// console.log("updateTimeticket, result :", result);
setLoading(false);
// if (completedCallback) completedCallback();
};
// const handleFinish = async (values) => {
// //logImEXEvent("tech_clock_out_job");
// setLoading(true);
// const result = await updateTimeticket({
// variables: {
// timeticketId: timeTicketId,
// timeticket: {
// clockoff: (await axios.post("/utils/time")).data,
// ...values,
// rate: currentSCC?.rate,
// // emps &&
// // emps.rates.filter((r) => r.cost_center === values.cost_center)[0]
// // ?.rate,
// flat_rate: currentEmployee && currentEmployee?.technician?.flat_rate,
// 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 (!!result.errors) {
// console.log("Error handleFinish clock off");
// //if (error) return <ErrorDisplay errorMessage={error.message} />;
// // notification["error"]({
// // message: t("timetickets.errors.clockingout", {
// // message: JSON.stringify(result.errors),
// // }),
// // });
// } else {
// console.log("success");
// // notification["success"]({
// // message: t("timetickets.successes.clockedout"),
// // });
// }
// setLoading(false);
// if (completedCallback) completedCallback();
// };
if (!!result.errors) {
// console.log("updateTimeticket, result.error :", result.errors);
setError(SON.stringify(result.errors));
} else {
console.log("updateTimeticket, result. :", result.data);
navigation.goBack();
}
//if (completedCallback) completedCallback();
};
return (
<View style={localStyles.content}>
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
@@ -205,12 +131,6 @@ console.log("TimeTicketClockOff, currentTmTicketJobId :", currentTmTicketJobId);
>
{({ handleChange, handleBlur, handleSubmit, values }) => (
<View style={localStyles.topTimeTicketContainer}>
{/* <JobIdSearchSelect
currentValue={currentSJobId}
onJobSelected={setCurrentSJobId}
convertedOnly={!currentBodyshop.tt_allow_post_to_invoiced}
notExported={!currentBodyshop.tt_allow_post_to_invoiced}
/> */}
<TextInput
style={localStyles.inputStyle}
mode="outlined"
@@ -234,11 +154,12 @@ console.log("TimeTicketClockOff, currentTmTicketJobId :", currentTmTicketJobId);
/>
<Button
style={localStyles.input}
onPress={handleSubmit}
onPress={handleSubmit}
title="Submit"
>
<Text style={{ fontSize: 12 }}>Clock Off</Text>
</Button>
{error ? <ErrorDisplay errorMessage={error.message} /> : null}
</View>
)}
</Formik>