added nav
This commit is contained in:
@@ -18,6 +18,12 @@ import { useCallback } from "react";
|
|||||||
import LaborAllocationsTable from "../labor-allocations-table/labor-allocations-table.component";
|
import LaborAllocationsTable from "../labor-allocations-table/labor-allocations-table.component";
|
||||||
|
|
||||||
import ErrorDisplay from "../error-display/error-display.component";
|
import ErrorDisplay from "../error-display/error-display.component";
|
||||||
|
import { INSERT_NEW_TIME_TICKET } from "../../graphql/timetickets.queries";
|
||||||
|
import { useMutation } from "@apollo/client";
|
||||||
|
import axios from "axios";
|
||||||
|
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
||||||
|
import moment from "moment";
|
||||||
|
import { useNavigation } from "@react-navigation/native";
|
||||||
|
|
||||||
//TODO add props needed for call
|
//TODO add props needed for call
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
@@ -32,7 +38,10 @@ export function TimeTicketCreate({
|
|||||||
currentRatesNCostCenters,
|
currentRatesNCostCenters,
|
||||||
currentBodyshop,
|
currentBodyshop,
|
||||||
}) {
|
}) {
|
||||||
|
const navigation = useNavigation();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
const [isDatePickerVisible, setDatePickerVisibility] = useState(false);
|
const [isDatePickerVisible, setDatePickerVisibility] = useState(false);
|
||||||
const [date2, setDate2] = useState(new Date());
|
const [date2, setDate2] = useState(new Date());
|
||||||
@@ -41,6 +50,7 @@ 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);
|
||||||
@@ -59,10 +69,106 @@ export function TimeTicketCreate({
|
|||||||
//console.war1n("A date has been picked: ", date);
|
//console.war1n("A date has been picked: ", date);
|
||||||
hideDatePicker();
|
hideDatePicker();
|
||||||
};
|
};
|
||||||
const formSubmit = (values) => {
|
|
||||||
console.log("values", values);
|
const [insertTimeTicket] = useMutation(INSERT_NEW_TIME_TICKET);
|
||||||
//Dialog.alert({ content: <pre>{JSON.stringify(values, null, 2)}</pre> });
|
|
||||||
//TODO update with start call for create time ticket
|
const handleFinish = async (values) => {
|
||||||
|
const theTime = (await axios.post("/utils/time")).data;
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
logImEXEvent("insertTimeTicket_handleFinish");
|
||||||
|
// console.log("insertTimeTicket, currentSCC :", currentSCC);
|
||||||
|
// console.log("insertTimeTicket, currentSCC :", currentSJobId);
|
||||||
|
// console.log("insertTimeTicket, values :", values);
|
||||||
|
|
||||||
|
if (
|
||||||
|
!!currentSCC?.value &&
|
||||||
|
!!currentSJobId?.value &&
|
||||||
|
!!values.productivehours &&
|
||||||
|
!!values.actualhours &&
|
||||||
|
!!values.productivehours
|
||||||
|
) {
|
||||||
|
setError(null);
|
||||||
|
console.log("all have values:");
|
||||||
|
} else {
|
||||||
|
console.log("missing values!");
|
||||||
|
setError({ message: "Please make sure all fields have a value." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentSJobId)
|
||||||
|
console.log("jobid or currentSJobId", currentSJobId?.value);
|
||||||
|
|
||||||
|
const tempVariablesObj = {
|
||||||
|
variables: {
|
||||||
|
timeTicketInput: [
|
||||||
|
{
|
||||||
|
bodyshopid: currentBodyshop.id,
|
||||||
|
employeeid: currentEmployee?.technician?.id,
|
||||||
|
date: moment(theTime).format("YYYY-MM-DD"),
|
||||||
|
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);
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
// 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]);
|
||||||
|
|
||||||
|
//after obj is good add below to make call
|
||||||
|
|
||||||
|
const result = await insertTimeTicket(tempVariablesObj);
|
||||||
|
|
||||||
|
//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 (completedCallback) completedCallback();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -70,14 +176,14 @@ export function TimeTicketCreate({
|
|||||||
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
|
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
|
||||||
<Formik
|
<Formik
|
||||||
initialValues={{
|
initialValues={{
|
||||||
jobid: {currentSJobId},
|
jobid: { currentSJobId },
|
||||||
ticketdate: date2.toLocaleDateString(),
|
ticketdate: date2.toLocaleDateString(),
|
||||||
employee: currentEmployee.technician.first_name,
|
employee: currentEmployee.technician.first_name,
|
||||||
costcenter: {currentSCC},
|
costcenter: { currentSCC },
|
||||||
productivehours: "",
|
productivehours: "",
|
||||||
actualhours: "",
|
actualhours: "",
|
||||||
}}
|
}}
|
||||||
onSubmit={formSubmit}
|
onSubmit={handleFinish}
|
||||||
>
|
>
|
||||||
{({ handleChange, handleBlur, handleSubmit, values }) => (
|
{({ handleChange, handleBlur, handleSubmit, values }) => (
|
||||||
<View style={localStyles.topTimeTicketContainer}>
|
<View style={localStyles.topTimeTicketContainer}>
|
||||||
@@ -146,17 +252,15 @@ export function TimeTicketCreate({
|
|||||||
>
|
>
|
||||||
<Text style={{ fontSize: 12 }}>Create Ticket</Text>
|
<Text style={{ fontSize: 12 }}>Create Ticket</Text>
|
||||||
</Button>
|
</Button>
|
||||||
|
{error ? <ErrorDisplay errorMessage={error.message} /> : null}
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</Formik>
|
</Formik>
|
||||||
|
|
||||||
{/* Below is for list of jobs/tickets */}
|
{/* Below is for list of jobs/tickets */}
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<View style={{ flexGrow: 1 }}>
|
<View style={{ flexGrow: 1 }}>
|
||||||
|
<LaborAllocationsTable jobId={currentSJobId?.value} />
|
||||||
<LaborAllocationsTable jobId={currentSJobId?.value} />
|
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user