import { timeTicketCreateFailure, timeTicketCreateSuccess, timeTicketClockInSuccess, timeTicketClockInFailure, timeTicketClockOutSuccess, timeTicketClockOutFailure, } from "./timetickets.actions"; import TimeTicketsActionTypes from "./timetickets.types"; import { client } from "../../graphql/client"; import { all, call, put, select, takeLatest } from "redux-saga/effects"; import { logImEXEvent } from "../../firebase/firebase.analytics"; import { selectCurrentTimeTicket } from "./timetickets.selectors"; import { INSERT_NEW_TIME_TICKET } from "../../graphql/timetickets.queries"; export function* onCreateTimeTicketStart() { yield takeLatest( TimeTicketsActionTypes.TIME_TICKET_CREATE_START, insertNewTimeTicket ); } export function* insertNewTimeTicket({ payload: { timeTicketInput } }) { try { logImEXEvent("redux_insertnewtimeticket_attempt"); // console.log("Saga, TIME_TICKET_CREATE_START :", timeTicketInput); //console.loging // console.log("Saga", employeeId, pin, pin); const timeTicket = yield select(selectCurrentTimeTicket); // const response = yield call(axios.post, "/tech/login", { // shopid: bodyshop.id, // employeeid: employeeId, // pin: pin, // }); // const { valid, data, error } = response.data; // const result = yield client.mutate({ // mutation: INSERT_NEW_TIME_TICKET, // variables: { // timeTicketInput: [ // // { // // bodyshopid: bodyshop.id, // // employeeid: technician.id, // // date: moment(theTime).format("YYYY-MM-DD"), // // clockon: moment(theTime), // // jobid: values.jobid, // // cost_center: values.cost_center, // // ciecacode: // // bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber // // ? values.cost_center // // : Object.keys( // // bodyshop.md_responsibility_centers.defaults.costs // // ).find((key) => { // // return ( // // bodyshop.md_responsibility_centers.defaults.costs[key] === // // values.cost_center // // ); // // }), // // }, // ], // }, // }); // console.log(result); // const { valid, data, error } = result.data; // if (valid) { // yield put(timeTicketCreateSuccess(data)); // } else { // yield put(timeTicketCreateFailure(error)); // } } catch (error) { yield put(timeTicketCreateFailure(error)); } } export function* onClockOutStart() { yield takeLatest( TimeTicketsActionTypes.TIME_TICKET_CLOCKOUT_START, clockOutStart ); } export function* clockOutStart({ payload: { timeTicketInput } }) { try { logImEXEvent("redux_clockOutStart_attempt"); //console.loging // console.log("Saga, clockOutStart :", timeTicketInput); // const timeTicket = yield select(selectCurrentTimeTicket); // const response = yield call(axios.post, "/tech/login", { // shopid: bodyshop.id, // employeeid: employeeId, // pin: pin, // }); // const { valid, data, error } = response.data; // const result = yield client.mutate({ // mutation: INSERT_NEW_TIME_TICKET, // variables: { // timeTicketInput: [ // // { // // bodyshopid: bodyshop.id, // // employeeid: technician.id, // // date: moment(theTime).format("YYYY-MM-DD"), // // clockon: moment(theTime), // // jobid: values.jobid, // // cost_center: values.cost_center, // // ciecacode: // // bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber // // ? values.cost_center // // : Object.keys( // // bodyshop.md_responsibility_centers.defaults.costs // // ).find((key) => { // // return ( // // bodyshop.md_responsibility_centers.defaults.costs[key] === // // values.cost_center // // ); // // }), // // }, // ], // }, // }); // console.log(result); // const { valid, data, error } = result.data; // if (valid) { // yield put(timeTicketCreateSuccess(data)); // } else { // yield put(timeTicketCreateFailure(error)); // } } catch (error) { yield put(timeTicketClockOutFailure(error)); } } export function* onClockInStart() { yield takeLatest( TimeTicketsActionTypes.TIME_TICKET_CLOCKIN_START, clockInStart ); } export function* clockInStart({ payload: { timeTicketInput } }) { try { logImEXEvent("redux_clockInStart_attempt"); // console.log("Saga, clockInStart :", timeTicketInput); } catch (error) { yield put(timeTicketClockInFailure(error)); } } export function* timeTicketsSagas() { yield all([ call(onCreateTimeTicketStart), call(onClockOutStart), call(onClockInStart), ]); }