diff --git a/.eslintrc.cjs b/.eslintrc.cjs
index f9f0638..51ff6c1 100644
--- a/.eslintrc.cjs
+++ b/.eslintrc.cjs
@@ -1,8 +1,12 @@
module.exports = {
+ globals: {
+ process: true,
+ },
root: true,
env: {
browser: true,
es2021: true,
+ node: true,
},
extends: [
'eslint:recommended',
diff --git a/package.json b/package.json
index 721a6c5..9d0d8cb 100644
--- a/package.json
+++ b/package.json
@@ -38,7 +38,7 @@
"react-router-dom": "^6.21.3"
},
"devDependencies": {
- "@types/react": "^18.2.43",
+ "@types/react": "^18.2.55",
"@types/react-dom": "^18.2.17",
"@types/react-router-dom": "^5.3.3",
"@typescript-eslint/eslint-plugin": "^6.14.0",
diff --git a/src/Logger.ts b/src/Logger.ts
index 458f317..e059874 100644
--- a/src/Logger.ts
+++ b/src/Logger.ts
@@ -1,4 +1,5 @@
-import { LogPayloadParams } from './types/LogType';
+import { postLog } from './apis/postLog';
+import { LogPayloadParams, LogType } from './types/LogType';
const createHashedId = (userId: string) => {
// Todo: create hashedId
@@ -11,34 +12,62 @@ const createTimestamp = () => {
return now.toISOString();
};
+const setLocalStorageClear = () => {
+ const list: any[] = [];
+ localStorage.setItem('yls-web', JSON.stringify(list));
+};
+
+const setLocalStorage = async (logger: LogType) => {
+ if (window.localStorage.getItem('yls-web') == undefined) {
+ const list: any[] = [];
+ list.push(logger);
+ localStorage.setItem('yls-web', JSON.stringify(list));
+ } else {
+ const remainList: any[] = JSON.parse(localStorage.getItem('yls-web') as string) || [];
+ if (remainList.length < 10) {
+ const updateList = [...remainList, logger];
+ localStorage.setItem('yls-web', JSON.stringify(updateList));
+ } else {
+ setLocalStorageClear();
+ const res = await postLog();
+ }
+ }
+};
+
export const useYLSLogger = () => {
- const screen = ({ userId, serviceName, name }: LogPayloadParams) => {
- //사용자에서 userId, name, message(선택) 등을 넣어줌
+ const screen = ({ userId, serviceName, name, path }: LogPayloadParams) => {
const loggerType: LogPayloadParams = {
userId: userId,
path: '/',
serviceName: serviceName,
name: '',
- message: '/',
+ message: '',
};
const logger = Logger(loggerType);
- console.log(`Logging screen information for screen: ${serviceName}`);
+ console.log(`Logging screen information for path: ${serviceName}`);
logger.event.name = name;
+ logger.event.path = path;
+
+ setLocalStorage(logger);
};
- const click = ({ userId, name }: LogPayloadParams) => {
- //사용자에서 userId, name, message(선택) 등을 넣어줌
+ const click = ({ userId, serviceName, name, path }: LogPayloadParams) => {
+ console.log(`Logging click information for button: ${name}`);
+ //사용자에서 path,name,message를 넣어줌
const loggerType: LogPayloadParams = {
userId: userId,
path: '/',
- serviceName: 'home',
+ serviceName: serviceName,
name: '',
- message: '/',
+ message: '',
};
const logger = Logger(loggerType);
- console.log(`Logging click information for button: ${name}`);
+
logger.event.name = name;
+ logger.event.path = path;
+ setLocalStorage(logger);
};
+ // todo: 로컬스토리지 로그 개수가 10개 넘어가면 postLog.ts호출
return {
screen,
diff --git a/src/apis/customedAxios.ts b/src/apis/customedAxios.ts
new file mode 100644
index 0000000..362c3d2
--- /dev/null
+++ b/src/apis/customedAxios.ts
@@ -0,0 +1,11 @@
+import axios from 'axios';
+
+export const customedAxios = axios.create({
+ baseURL: import.meta.env.VITE_API_URL,
+ headers: {
+ 'Content-Type': 'application/json',
+ withCredentials: true,
+ },
+});
+
+export default customedAxios;
diff --git a/src/apis/postLog.ts b/src/apis/postLog.ts
index 473ae2a..31bd9a2 100644
--- a/src/apis/postLog.ts
+++ b/src/apis/postLog.ts
@@ -1 +1,6 @@
-export const postLog = async () => {};
+import customedAxios from './customedAxios';
+
+export const postLog = async () => {
+ const res = await customedAxios.put('');
+ return res.data;
+};
diff --git a/src/demo/App.tsx b/src/demo/App.tsx
index bcaea40..bdcad57 100644
--- a/src/demo/App.tsx
+++ b/src/demo/App.tsx
@@ -1,12 +1,14 @@
import { BrowserRouter } from 'react-router-dom';
import { Routes, Route } from 'react-router-dom';
import { Home } from './Home';
+import { Drawer } from './Drawer';
export const App = () => {
return (
<>