diff --git a/components/Buttons/tech-clock-out-button.component.jsx b/components/Buttons/tech-clock-out-button.component.jsx deleted file mode 100644 index 19fd1ae..0000000 --- a/components/Buttons/tech-clock-out-button.component.jsx +++ /dev/null @@ -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 ( - - ); -} -export default connect(null, mapDispatchToProps)(SignOutButton); diff --git a/components/labor-allocations-table/labor-allocations-table.component.jsx b/components/labor-allocations-table/labor-allocations-table.component.jsx index 31c3e53..b9d9ba1 100644 --- a/components/labor-allocations-table/labor-allocations-table.component.jsx +++ b/components/labor-allocations-table/labor-allocations-table.component.jsx @@ -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(() => { diff --git a/components/time-ticket/screen-time-ticket-clockoff.component.jsx b/components/time-ticket/screen-time-ticket-clockoff.component.jsx index cd0bd41..4505f11 100644 --- a/components/time-ticket/screen-time-ticket-clockoff.component.jsx +++ b/components/time-ticket/screen-time-ticket-clockoff.component.jsx @@ -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:
{JSON.stringify(values, null, 2)}
}); - //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 ; - -// // 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 ( @@ -205,12 +131,6 @@ console.log("TimeTicketClockOff, currentTmTicketJobId :", currentTmTicketJobId); > {({ handleChange, handleBlur, handleSubmit, values }) => ( - {/* */} + {error ? : null} )}