@daeryun/dr_components 1.2.85 → 1.2.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 로그인 완료 후 URL에 uuid(idx)를 추가하고 GA 이벤트를 발생시키는 훅
3
+ * - 로그인된 상태이고, URL에 uuid가 없으면 uuid를 추가
4
+ * - 로그인 완료 GA 이벤트 발생
5
+ */
6
+ export declare const useLoginUuidSync: () => void;
7
+ export default useLoginUuidSync;
@@ -0,0 +1,79 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { useEffect, useRef } from 'react';
11
+ import * as gtag from '../../lib/gtag';
12
+ /**
13
+ * 로그인 완료 후 URL에 uuid(idx)를 추가하고 GA 이벤트를 발생시키는 훅
14
+ * - 로그인된 상태이고, URL에 uuid가 없으면 uuid를 추가
15
+ * - 로그인 완료 GA 이벤트 발생
16
+ */
17
+ export const useLoginUuidSync = () => {
18
+ const hasProcessed = useRef(false);
19
+ console.log('useLoginUuidSync 훅 호출됨');
20
+ useEffect(() => {
21
+ console.log('useLoginUuidSync useEffect 실행, hasProcessed:', hasProcessed.current);
22
+ // 이미 처리했으면 스킵
23
+ if (hasProcessed.current) {
24
+ console.log('useLoginUuidSync: 이미 처리됨, 스킵');
25
+ return;
26
+ }
27
+ const syncUuid = () => __awaiter(void 0, void 0, void 0, function* () {
28
+ var _a, _b, _c;
29
+ console.log('useLoginUuidSync syncUuid 함수 시작');
30
+ try {
31
+ // URL에 이미 uuid가 있으면 스킵
32
+ const urlParams = new URLSearchParams(window.location.search);
33
+ console.log('useLoginUuidSync 현재 URL:', window.location.href);
34
+ if (urlParams.has('uuid')) {
35
+ console.log('useLoginUuidSync: URL에 이미 uuid 있음');
36
+ return;
37
+ }
38
+ // 로그인 상태 및 idx 조회
39
+ const result = yield fetch(`/api/lawfirm/app/user`, {
40
+ method: 'GET',
41
+ headers: { 'Content-Type': 'application/json' },
42
+ credentials: 'include'
43
+ }).then(res => res.json());
44
+ console.log('useLoginUuidSync result:', result);
45
+ // 로그인 안 됨
46
+ if (!((_a = result.data) === null || _a === void 0 ? void 0 : _a.email) || !((_b = result.data) === null || _b === void 0 ? void 0 : _b.name) || !((_c = result.data) === null || _c === void 0 ? void 0 : _c.phone_number)) {
47
+ console.log('useLoginUuidSync: 로그인 안 됨');
48
+ return;
49
+ }
50
+ const idx = result.data.idx;
51
+ if (!idx) {
52
+ console.log('useLoginUuidSync: idx 없음');
53
+ return;
54
+ }
55
+ console.log('useLoginUuidSync: 로그인 확인, idx:', idx);
56
+ // URL에 uuid 추가
57
+ const url = new URL(window.location.href);
58
+ url.searchParams.set('uuid', String(idx));
59
+ const newUrl = url.pathname + url.search;
60
+ // GA 이벤트: 로그인 완료
61
+ gtag.event({
62
+ action: 'login_complete',
63
+ category: 'login',
64
+ label: `로그인 완료 - ${idx}`,
65
+ value: '1'
66
+ });
67
+ hasProcessed.current = true;
68
+ // URL 업데이트 (히스토리에 추가하지 않고 교체)
69
+ window.history.replaceState({}, '', newUrl);
70
+ console.log('useLoginUuidSync: URL 업데이트 완료', newUrl);
71
+ }
72
+ catch (error) {
73
+ console.error('useLoginUuidSync 에러:', error);
74
+ }
75
+ });
76
+ syncUuid();
77
+ }, []);
78
+ };
79
+ export default useLoginUuidSync;
@@ -0,0 +1,84 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import * as gtag from '../../lib/gtag';
3
+
4
+ /**
5
+ * 로그인 완료 후 URL에 uuid(idx)를 추가하고 GA 이벤트를 발생시키는 훅
6
+ * - 로그인된 상태이고, URL에 uuid가 없으면 uuid를 추가
7
+ * - 로그인 완료 GA 이벤트 발생
8
+ */
9
+ export const useLoginUuidSync = () => {
10
+ const hasProcessed = useRef(false);
11
+
12
+ console.log('useLoginUuidSync 훅 호출됨');
13
+
14
+ useEffect(() => {
15
+ console.log('useLoginUuidSync useEffect 실행, hasProcessed:', hasProcessed.current);
16
+
17
+ // 이미 처리했으면 스킵
18
+ if (hasProcessed.current) {
19
+ console.log('useLoginUuidSync: 이미 처리됨, 스킵');
20
+ return;
21
+ }
22
+
23
+ const syncUuid = async () => {
24
+ console.log('useLoginUuidSync syncUuid 함수 시작');
25
+ try {
26
+ // URL에 이미 uuid가 있으면 스킵
27
+ const urlParams = new URLSearchParams(window.location.search);
28
+ console.log('useLoginUuidSync 현재 URL:', window.location.href);
29
+ if (urlParams.has('uuid')) {
30
+ console.log('useLoginUuidSync: URL에 이미 uuid 있음');
31
+ return;
32
+ }
33
+
34
+ // 로그인 상태 및 idx 조회
35
+ const result = await fetch(`/api/lawfirm/app/user`, {
36
+ method: 'GET',
37
+ headers: { 'Content-Type': 'application/json' },
38
+ credentials: 'include'
39
+ }).then(res => res.json());
40
+
41
+ console.log('useLoginUuidSync result:', result);
42
+
43
+ // 로그인 안 됨
44
+ if (!result.data?.email || !result.data?.name || !result.data?.phone_number) {
45
+ console.log('useLoginUuidSync: 로그인 안 됨');
46
+ return;
47
+ }
48
+
49
+ const idx = result.data.idx;
50
+ if (!idx) {
51
+ console.log('useLoginUuidSync: idx 없음');
52
+ return;
53
+ }
54
+
55
+ console.log('useLoginUuidSync: 로그인 확인, idx:', idx);
56
+
57
+ // URL에 uuid 추가
58
+ const url = new URL(window.location.href);
59
+ url.searchParams.set('uuid', String(idx));
60
+ const newUrl = url.pathname + url.search;
61
+
62
+ // GA 이벤트: 로그인 완료
63
+ gtag.event({
64
+ action: 'login_complete',
65
+ category: 'login',
66
+ label: `로그인 완료 - ${idx}`,
67
+ value: '1'
68
+ });
69
+
70
+ hasProcessed.current = true;
71
+
72
+ // URL 업데이트 (히스토리에 추가하지 않고 교체)
73
+ window.history.replaceState({}, '', newUrl);
74
+ console.log('useLoginUuidSync: URL 업데이트 완료', newUrl);
75
+ } catch (error) {
76
+ console.error('useLoginUuidSync 에러:', error);
77
+ }
78
+ };
79
+
80
+ syncUuid();
81
+ }, []);
82
+ };
83
+
84
+ export default useLoginUuidSync;
@@ -81,3 +81,5 @@ export * from '../components/common/types/strength_new';
81
81
  export { default as PaginationForGroup } from './PaginationForGroup/PaginationForGroup';
82
82
  export { default as SuccessList } from './page/Success/SuccessList';
83
83
  export { default as GlobalOfficeSection } from './GlobalOfficeSection/GlobalOfficeSection';
84
+ // Hooks
85
+ export { useLoginUuidSync } from './hook/useLoginUuidSync';
@@ -81,3 +81,6 @@ export * from '../components/common/types/strength_new';
81
81
  export { default as PaginationForGroup } from './PaginationForGroup/PaginationForGroup';
82
82
  export { default as SuccessList } from './page/Success/SuccessList';
83
83
  export { default as GlobalOfficeSection } from './GlobalOfficeSection/GlobalOfficeSection';
84
+
85
+ // Hooks
86
+ export { useLoginUuidSync } from './hook/useLoginUuidSync';
@@ -115,11 +115,13 @@ const LoginContainer = ({ layoutClassName = ' relative h-[100vh] max-h-[1200px]
115
115
  checkLogoutLogAction();
116
116
  }, []);
117
117
  useEffect(() => {
118
+ console.log('로그인 체크 useEffect 시작');
118
119
  let attemptCount = 0; // 시도 횟수
119
120
  const maxAttempts = 3; // 최대 4번
120
121
  const intervalTime = 3000; // 3초
121
122
  const interval = setInterval(() => __awaiter(void 0, void 0, void 0, function* () {
122
123
  attemptCount++;
124
+ console.log(`로그인 체크 시도 ${attemptCount}/${maxAttempts}`);
123
125
  try {
124
126
  const { isLogin, idx } = yield fetchUserWithIdx();
125
127
  if (isLogin) {
@@ -123,12 +123,14 @@ const LoginContainer = ({
123
123
  }, []);
124
124
 
125
125
  useEffect(() => {
126
+ console.log('로그인 체크 useEffect 시작');
126
127
  let attemptCount = 0; // 시도 횟수
127
128
  const maxAttempts = 3; // 최대 4번
128
129
  const intervalTime = 3000; // 3초
129
130
 
130
131
  const interval = setInterval(async () => {
131
132
  attemptCount++;
133
+ console.log(`로그인 체크 시도 ${attemptCount}/${maxAttempts}`);
132
134
 
133
135
  try {
134
136
  const { isLogin, idx } = await fetchUserWithIdx();