2023-05-29 21:00:15 +00:00
|
|
|
import saveAs from "file-saver";
|
2024-02-28 09:58:21 +00:00
|
|
|
import { deviceDetect } from "react-device-detect";
|
2023-05-29 21:00:15 +00:00
|
|
|
|
2024-02-08 14:13:57 +00:00
|
|
|
export const getCrashReport = (
|
|
|
|
userId: string,
|
|
|
|
version: string,
|
|
|
|
language?: string,
|
|
|
|
error?: Error,
|
|
|
|
) => {
|
2023-05-25 11:50:09 +00:00
|
|
|
const currentTime = new Date();
|
2023-08-28 09:24:34 +00:00
|
|
|
const reportTime = currentTime.toUTCString();
|
2023-05-25 11:50:09 +00:00
|
|
|
const lsObject = JSON.stringify(window.localStorage) || "";
|
2023-05-24 12:08:09 +00:00
|
|
|
|
2023-05-24 12:09:41 +00:00
|
|
|
const report = {
|
2023-05-24 12:08:09 +00:00
|
|
|
url: window.origin,
|
2024-02-08 14:13:57 +00:00
|
|
|
userId,
|
|
|
|
version,
|
2023-05-24 11:47:05 +00:00
|
|
|
platform: navigator?.platform,
|
|
|
|
userAgent: navigator?.userAgent,
|
2023-05-25 11:50:09 +00:00
|
|
|
language: language || "en",
|
2023-05-24 12:08:09 +00:00
|
|
|
errorMessage: error?.message,
|
|
|
|
errorStack: error?.stack,
|
2023-05-25 11:50:09 +00:00
|
|
|
localStorage: lsObject,
|
2024-02-08 14:13:57 +00:00
|
|
|
reportTime,
|
2024-02-28 09:58:21 +00:00
|
|
|
deviceInfo: deviceDetect(),
|
2023-05-24 11:47:05 +00:00
|
|
|
};
|
2023-05-25 11:50:09 +00:00
|
|
|
|
|
|
|
return report;
|
2023-05-24 11:47:05 +00:00
|
|
|
};
|
2023-05-29 13:54:21 +00:00
|
|
|
|
2024-02-09 09:07:14 +00:00
|
|
|
export const downloadJson = <T>(json: T, fileName: string) => {
|
2023-05-29 13:54:21 +00:00
|
|
|
const cleanJson = JSON.stringify(json);
|
|
|
|
const data = new Blob([cleanJson], { type: "application/json" });
|
|
|
|
const url = window.URL.createObjectURL(data);
|
2023-05-29 21:00:15 +00:00
|
|
|
saveAs(url, `${fileName}.json`);
|
2023-05-29 13:54:21 +00:00
|
|
|
};
|
2023-05-29 21:02:29 +00:00
|
|
|
|
|
|
|
export const getCurrentDate = () => {
|
|
|
|
const now = new Date();
|
|
|
|
const year = now.getFullYear();
|
|
|
|
const month = now.getMonth() + 1;
|
|
|
|
const day = now.getDate();
|
|
|
|
return `${day}.${month}.${year}`;
|
|
|
|
};
|