90 lines
1.9 KiB
JavaScript
90 lines
1.9 KiB
JavaScript
import axios from "axios";
|
|
|
|
import { getUrl } from "./apiConfig";
|
|
// import { clearLaunchParams, getLaunchParams } from "../utils/helperMethods";
|
|
import { createQueryString } from "../utils/helperMethods";
|
|
|
|
export const TLogEvent = (
|
|
dispatch,
|
|
getState,
|
|
type,
|
|
baseUrl,
|
|
urlParams = {},
|
|
params = {},
|
|
onSuccess,
|
|
onFail
|
|
) => {
|
|
const httpHeader = getState().common.httpHeader;
|
|
const appStatus = getState().common.appStatus;
|
|
const AUTHORIZATION = { headers: { ...httpHeader } };
|
|
|
|
const { cntry_cd: cntryCd, plat_cd: platCd, prod_cd: prodCd } = httpHeader;
|
|
const { deviceId: dvcId } = appStatus;
|
|
const dvcTp = "tv";
|
|
|
|
if (typeof window === "object") {
|
|
let url = Array.isArray(baseUrl)
|
|
? getUrl(getState, baseUrl[0])
|
|
: getUrl(getState, baseUrl);
|
|
|
|
if (!url) {
|
|
return;
|
|
}
|
|
|
|
if (type === "get") {
|
|
const _urlparams = createQueryString(urlParams);
|
|
url += _urlparams ? `?${_urlparams}` : "";
|
|
}
|
|
|
|
// let linkTpCd = "";
|
|
|
|
// if (httpHeader) {
|
|
// const launchParams = getLaunchParams();
|
|
|
|
// if (launchParams?.contentTarget) {
|
|
// const tokens = launchParams.contentTarget.split("_");
|
|
|
|
// if (tokens[0] === "V3") {
|
|
// linkTpCd = tokens[1];
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
const model = {
|
|
...params,
|
|
cntryCd,
|
|
dvcId,
|
|
dvcTp,
|
|
// linkTpCd,
|
|
platCd,
|
|
prodCd,
|
|
};
|
|
|
|
let axiosInstance;
|
|
|
|
switch (type) {
|
|
case "get":
|
|
axiosInstance = axios.get(url, AUTHORIZATION);
|
|
break;
|
|
case "post":
|
|
axiosInstance = axios.post(url, model, AUTHORIZATION);
|
|
break;
|
|
}
|
|
|
|
if (axiosInstance) {
|
|
axiosInstance
|
|
.then((res) => {
|
|
if (onSuccess) {
|
|
onSuccess(res);
|
|
}
|
|
})
|
|
.catch((error) => {
|
|
if (onFail) {
|
|
onFail(error);
|
|
}
|
|
});
|
|
// .finally(clearLaunchParams);
|
|
}
|
|
}
|
|
};
|