Add clockoutcall + grab vals to TimeTicketClockOff
This commit is contained in:
@@ -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);
|
|
||||||
@@ -38,7 +38,7 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician }) {
|
|||||||
const [totals, setTotals] = useState([]);
|
const [totals, setTotals] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("LaborAllocationsTable useEffect on data change");
|
// console.log("LaborAllocationsTable useEffect on data change");
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Formik } from "formik";
|
import { Formik } from "formik";
|
||||||
import React, { useState } from "react";
|
import React, { useEffect, 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";
|
||||||
@@ -18,6 +18,8 @@ import { selectCurrentTmTicketJobId } from "../../redux/app/app.selectors";
|
|||||||
import ErrorDisplay from "../error-display/error-display.component";
|
import ErrorDisplay from "../error-display/error-display.component";
|
||||||
import { timeTicketClockOutStart } from "../../redux/timetickets/timetickets.actions";
|
import { timeTicketClockOutStart } from "../../redux/timetickets/timetickets.actions";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
||||||
|
import axios from "axios";
|
||||||
|
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
|
//TODO add props needed for call
|
||||||
@@ -26,13 +28,10 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
currentRatesNCostCenters: selectRates,
|
currentRatesNCostCenters: selectRates,
|
||||||
currentBodyshop: selectBodyshop,
|
currentBodyshop: selectBodyshop,
|
||||||
currentTmTicketJobId: selectCurrentTmTicketJobId,
|
currentTmTicketJobId: selectCurrentTmTicketJobId,
|
||||||
|
|
||||||
//add way to get timeTicketId
|
|
||||||
// currentJobId: selectCurrentTimeTicketJobId
|
|
||||||
});
|
});
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
timeTicketClockOutStart
|
timeTicketClockOutStart,
|
||||||
});
|
});
|
||||||
|
|
||||||
export function TimeTicketClockOff({
|
export function TimeTicketClockOff({
|
||||||
currentEmployee,
|
currentEmployee,
|
||||||
@@ -41,157 +40,84 @@ export function TimeTicketClockOff({
|
|||||||
currentTmTicketJobId,
|
currentTmTicketJobId,
|
||||||
route,
|
route,
|
||||||
}) {
|
}) {
|
||||||
|
const navigation = useNavigation();
|
||||||
const { timeTicketId } = route.params;
|
const { timeTicketId } = route.params;
|
||||||
console.log("TimeTicketClockOff, timeTicketId :", timeTicketId);
|
// console.log("TimeTicketClockOff, timeTicketId :", timeTicketId);
|
||||||
//console.log("TimeTicketClockOff, currentRatesNCostCenters :", currentRatesNCostCenters );
|
// console.log( "TimeTicketClockOff, currentTmTicketJobId :", currentTmTicketJobId );
|
||||||
// console.log("TimeTicketClockOff, currentBodyshop :", currentBodyshop);
|
|
||||||
|
|
||||||
console.log("TimeTicketClockOff, currentTmTicketJobId :", currentTmTicketJobId);
|
|
||||||
// console.log("TimeTicketClockOff, jobId :", jobId);
|
|
||||||
// console.log("TimeTicketClockOff, timeTicketId :", timeTicketId);
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
const [currentSCC, setCurrentSCC] = 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 [updateTimeticket] = useMutation(UPDATE_TIME_TICKET);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const handleFinish = async (values) => {
|
const handleFinish = async (values) => {
|
||||||
logImEXEvent("TimeTicketClockOff_handleFinish");
|
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 = {
|
const tempcallobj = {
|
||||||
variables: {
|
variables: {
|
||||||
timeticketId: timeTicketId,
|
timeticketId: timeTicketId,
|
||||||
timeticket: {
|
timeticket: {
|
||||||
clockoff: (await axios.post("/utils/time")).data,
|
actualhrs: values?.actualhours,
|
||||||
...values,
|
|
||||||
rate:
|
|
||||||
emps &&
|
|
||||||
emps.rates.filter((r) => r.cost_center === values.cost_center)[0]
|
|
||||||
?.rate,
|
|
||||||
flat_rate: emps && emps.flat_rate,
|
|
||||||
ciecacode:
|
ciecacode:
|
||||||
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber
|
currentBodyshop?.cdk_dealerid || currentBodyshop?.pbs_serialnumber
|
||||||
? values.cost_center
|
? currentSCC?.value
|
||||||
: Object.keys(
|
: Object.keys(
|
||||||
bodyshop.md_responsibility_centers.defaults.costs
|
currentBodyshop.md_responsibility_centers.defaults.costs
|
||||||
).find((key) => {
|
).find((key) => {
|
||||||
return (
|
return (
|
||||||
bodyshop.md_responsibility_centers.defaults.costs[key] ===
|
currentBodyshop.md_responsibility_centers.defaults.costs[
|
||||||
values.cost_center
|
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
|
//after call results are retuning add handling below for cases
|
||||||
//setLoading(true);
|
// console.log("updateTimeticket, result :", result);
|
||||||
//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"),
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
// if (completedCallback) completedCallback();
|
if (!!result.errors) {
|
||||||
};
|
// console.log("updateTimeticket, result.error :", result.errors);
|
||||||
|
setError(SON.stringify(result.errors));
|
||||||
|
} else {
|
||||||
// const handleFinish = async (values) => {
|
console.log("updateTimeticket, result. :", result.data);
|
||||||
// //logImEXEvent("tech_clock_out_job");
|
navigation.goBack();
|
||||||
|
}
|
||||||
// setLoading(true);
|
//if (completedCallback) completedCallback();
|
||||||
// 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();
|
|
||||||
// };
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={localStyles.content}>
|
<View style={localStyles.content}>
|
||||||
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
|
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
|
||||||
@@ -205,12 +131,6 @@ console.log("TimeTicketClockOff, currentTmTicketJobId :", currentTmTicketJobId);
|
|||||||
>
|
>
|
||||||
{({ handleChange, handleBlur, handleSubmit, values }) => (
|
{({ handleChange, handleBlur, handleSubmit, values }) => (
|
||||||
<View style={localStyles.topTimeTicketContainer}>
|
<View style={localStyles.topTimeTicketContainer}>
|
||||||
{/* <JobIdSearchSelect
|
|
||||||
currentValue={currentSJobId}
|
|
||||||
onJobSelected={setCurrentSJobId}
|
|
||||||
convertedOnly={!currentBodyshop.tt_allow_post_to_invoiced}
|
|
||||||
notExported={!currentBodyshop.tt_allow_post_to_invoiced}
|
|
||||||
/> */}
|
|
||||||
<TextInput
|
<TextInput
|
||||||
style={localStyles.inputStyle}
|
style={localStyles.inputStyle}
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
@@ -234,11 +154,12 @@ console.log("TimeTicketClockOff, currentTmTicketJobId :", currentTmTicketJobId);
|
|||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
style={localStyles.input}
|
style={localStyles.input}
|
||||||
onPress={handleSubmit}
|
onPress={handleSubmit}
|
||||||
title="Submit"
|
title="Submit"
|
||||||
>
|
>
|
||||||
<Text style={{ fontSize: 12 }}>Clock Off</Text>
|
<Text style={{ fontSize: 12 }}>Clock Off</Text>
|
||||||
</Button>
|
</Button>
|
||||||
|
{error ? <ErrorDisplay errorMessage={error.message} /> : null}
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</Formik>
|
</Formik>
|
||||||
|
|||||||
Reference in New Issue
Block a user