Files
imexrps/src/components/molecules/estimate-scrubber-button/estimate-scrubber-button.molecule.jsx
2025-07-11 16:13:45 -07:00

53 lines
1.7 KiB
JavaScript

import { Button, message } from "antd";
import { useState } from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import ipcTypes from "../../../ipc.types";
import { selectBodyshop } from "../../../redux/user/user.selectors";
import { useApolloClient } from "@apollo/client";
import { QUERY_JOB_ESTIMATE_SCRUBBER } from "../../../graphql/jobs.queries";
import _ from "lodash";
const { ipcRenderer } = window;
const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser
bodyshop: selectBodyshop
});
const mapDispatchToProps = (dispatch) => ({
//setUserLanguage: language => dispatch(setUserLanguage(language))
});
export default connect(mapStateToProps, mapDispatchToProps)(EstimateScrubberButton);
export function EstimateScrubberButton({ bodyshop, jobid, job }) {
const [loading, setLoading] = useState(false);
const client = useApolloClient();
const handleScrub = async () => {
try {
ipcRenderer.send(ipcTypes.app.toMain.track, {
event: "SCRUB_ESTIMATE",
jobId: jobid
});
setLoading(true);
const jobData = await client.query({
query: QUERY_JOB_ESTIMATE_SCRUBBER,
variables: { jobId: jobid },
fetchPolicy: "network-only"
});
const result = await ipcRenderer.invoke(ipcTypes.app.toMain.scrubEstimate, {
job: jobData.data.jobs_by_pk
});
} catch (error) {
message.error("Error scrubbing estimate: " + error.message);
console.error("Error scrubbing estimate:", error);
}
setLoading(false);
};
return (
<Button onClick={handleScrub} disabled={job?.g_bett_amt == null} loading={loading}>
Scrub Estimate with Estimate Scrubber
</Button>
);
}