Resolve shift clock issues. IO-699

This commit is contained in:
Patrick Fic
2021-02-24 14:41:01 -08:00
parent 970fe5f9b7
commit 24fb9fd0a0
4 changed files with 45 additions and 15 deletions

View File

@@ -1,17 +1,20 @@
import { useMutation } from "@apollo/client";
import { Button, Form, notification } from "antd";
import React, { useState } from "react";
import axios from "axios";
import moment from "moment";
import React, { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { INSERT_NEW_TIME_TICKET } from "../../graphql/timetickets.queries";
import { selectTechnician } from "../../redux/tech/tech.selectors";
import { selectBodyshop } from "../../redux/user/user.selectors";
import {
selectBodyshop,
selectCurrentUser,
} from "../../redux/user/user.selectors";
import TimeTicektShiftComponent from "./time-ticket-shift-form.component";
import axios from "axios";
import moment from "moment";
const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser
currentUser: selectCurrentUser,
bodyshop: selectBodyshop,
technician: selectTechnician,
});
@@ -22,6 +25,7 @@ const mapDispatchToProps = (dispatch) => ({
export function TimeTicektShiftContainer({
bodyshop,
technician,
currentUser,
isTechConsole,
}) {
const [form] = Form.useForm();
@@ -29,6 +33,18 @@ export function TimeTicektShiftContainer({
const { t } = useTranslation();
const [loading, setLoading] = useState(false);
const employeeId = useMemo(() => {
const assoc = bodyshop.associations.filter(
(a) => a.useremail === currentUser.email
)[0];
return assoc && assoc.user && assoc.user.employee && assoc.user.employee.id;
}, [bodyshop, currentUser.email]);
console.log(
"🚀 ~ file: time-ticket-shift-form.container.jsx ~ line 42 ~ employeeId",
employeeId
);
const handleFinish = async (values) => {
setLoading(true);
const theTime = moment((await axios.post("/utils/time")).data);
@@ -38,9 +54,7 @@ export function TimeTicektShiftContainer({
timeTicketInput: [
{
bodyshopid: bodyshop.id,
employeeid: isTechConsole
? technician.id
: bodyshop.associations[0].user.employee.id,
employeeid: isTechConsole ? technician.id : employeeId,
cost_center: "timetickets.labels.shift",
clockon: theTime,
date: theTime,