Files
bodyshop/client/src/components/partner-ping/partner-ping.component.jsx
2022-02-07 15:04:07 -08:00

66 lines
2.0 KiB
JavaScript

import { notification } from "antd";
import axios from "axios";
import React, { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { setPartnerVersion } from "../../redux/application/application.actions";
import { selectBodyshop } from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser
bodyshop: selectBodyshop,
});
const mapDispatchToProps = (dispatch) => ({
//setUserLanguage: language => dispatch(setUserLanguage(language))
setPartnerVersion: (version) => dispatch(setPartnerVersion(version)),
});
export default connect(
mapStateToProps,
mapDispatchToProps
)(PartnerPingComponent);
export function PartnerPingComponent({ bodyshop, setPartnerVersion }) {
const { t } = useTranslation();
useEffect(() => {
// Create an scoped async function in the hook
async function checkPartnerStatus() {
if (!bodyshop) return;
try {
//if (process.env.NODE_ENV === "development") return;
const PartnerResponse = await axios.post("http://localhost:1337/ping/");
const { appver, qbpath } = PartnerResponse.data;
setPartnerVersion(appver);
console.log({ appver, qbpath });
if (
!qbpath &&
!(
bodyshop &&
(bodyshop.cdk_dealerid ||
bodyshop.pbs_serialnumber ||
bodyshop.accountingconfig.qbo)
)
) {
notification["error"]({
title: "",
message: t("general.messages.noacctfilepath"),
});
}
} catch (error) {
console.log(error);
notification["error"]({
title: "",
message: t("general.messages.partnernotrunning"),
});
}
}
// Execute the created function directly
checkPartnerStatus();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [bodyshop]);
return <></>;
}