73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
import {
|
|
timeTicketCreateFailure,
|
|
timeTicketCreateSuccess,
|
|
} 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.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* timeTicketsSagas() {
|
|
yield all([call(onCreateTimeTicketStart)]);
|
|
}
|