diff --git a/client/src/components/time-ticket-shift-form/time-ticket-shift-form.container.jsx b/client/src/components/time-ticket-shift-form/time-ticket-shift-form.container.jsx index 9831b0961..72e331867 100644 --- a/client/src/components/time-ticket-shift-form/time-ticket-shift-form.container.jsx +++ b/client/src/components/time-ticket-shift-form/time-ticket-shift-form.container.jsx @@ -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, diff --git a/client/src/components/time-ticket-shift/time-ticket-shift.container.jsx b/client/src/components/time-ticket-shift/time-ticket-shift.container.jsx index 6faa0aec1..a3f27c3c1 100644 --- a/client/src/components/time-ticket-shift/time-ticket-shift.container.jsx +++ b/client/src/components/time-ticket-shift/time-ticket-shift.container.jsx @@ -1,10 +1,13 @@ -import React from "react"; import { useQuery } from "@apollo/client"; +import React, { useMemo } from "react"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; import { QUERY_ACTIVE_SHIFT_TIME_TICKETS } 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 AlertComponent from "../alert/alert.component"; import LoadingSpinner from "../loading-spinner/loading-spinner.component"; import TimeTicketShiftActive from "../time-ticket-shift-active/time-ticket-shift-active.component"; @@ -13,6 +16,7 @@ import TimeTicketShiftFormContainer from "../time-ticket-shift-form/time-ticket- const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, technician: selectTechnician, + currentUser: selectCurrentUser, }); const mapDispatchToProps = (dispatch) => ({ //setUserLanguage: language => dispatch(setUserLanguage(language)) @@ -21,15 +25,22 @@ const mapDispatchToProps = (dispatch) => ({ export function TimeTicketShiftContainer({ bodyshop, technician, + currentUser, isTechConsole, }) { + 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]); + const { loading, error, data, refetch } = useQuery( QUERY_ACTIVE_SHIFT_TIME_TICKETS, { variables: { - employeeId: isTechConsole - ? technician.id - : bodyshop.associations[0].user.employee.id, + employeeId: isTechConsole ? technician && technician.id : employeeId, }, } ); diff --git a/client/src/firebase/firebase.utils.js b/client/src/firebase/firebase.utils.js index 22fefaf0e..02e832909 100644 --- a/client/src/firebase/firebase.utils.js +++ b/client/src/firebase/firebase.utils.js @@ -58,7 +58,12 @@ export const logImEXEvent = (eventName, additionalParams, stateProp = null) => { null, ...additionalParams, }; - console.log("%c[Analytics]", "background: tomato", eventName, eventParams); + console.log( + "%c[Analytics]", + "background-color: green ;font-weight:bold;", + eventName, + eventParams + ); analytics.logEvent(eventName, eventParams); }; diff --git a/client/src/index.js b/client/src/index.js index 5f0335e6d..286155d7d 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -28,7 +28,7 @@ Sentry.init({ "https://fd7e89369b6b4bdc9c6c4c9f22fa4ee4@o492140.ingest.sentry.io/5651027", integrations: [new Integrations.BrowserTracing()], environment: process.env || "development", - + enabled: process.env !== "development", // We recommend adjusting this value in production, or using tracesSampler // for finer control tracesSampleRate: 0.5,