@daeryun/dr_components 1.1.48 → 1.1.49

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.
@@ -3,7 +3,13 @@
3
3
  import ContentList from './components/ContentList';
4
4
  import { useEffect, useRef, useState } from 'react';
5
5
  import useBrowser from '../../hook/useBrowser';
6
- import { ILawyerTypes, ISuccessTypes, ILegalDocumentImageObjectTypes, ISuccessNewPageTypes } from './SuccessNewType';
6
+ import {
7
+ ILawyerTypes,
8
+ ISuccessTypes,
9
+ ILegalDocumentImageObjectTypes,
10
+ ISuccessNewPageTypes,
11
+ ISeoTemplateTypes
12
+ } from './SuccessNewType';
7
13
  import { htmlUrlDecode } from '../../../lib';
8
14
  import H2Contents from './components/H2Contents';
9
15
  import H3Contents from './components/H3Contents';
@@ -38,7 +44,8 @@ const SuccessNewView = ({ data, tel }: ISuccessNewPageTypes) => {
38
44
  shortsLinkList,
39
45
  youtubeLinkList,
40
46
  pn,
41
- initialData
47
+ initialData,
48
+ faqElementMaxCountInContents
42
49
  } = data;
43
50
  const { width } = useBrowser(true);
44
51
  const [relatedCaseLawyerList, setRelatedCaseLawyerList] = useState<ILawyerTypes[]>(lawyerData);
@@ -81,6 +88,44 @@ const SuccessNewView = ({ data, tel }: ISuccessNewPageTypes) => {
81
88
  window.scrollTo({ top: imgLocation + (width > 680 ? 300 : 200), behavior: 'smooth' });
82
89
  };
83
90
 
91
+ const handleFaqItemType = (isFaqActive: boolean, faqElementMaxCountInContents?: number): string | undefined => {
92
+ if (isFaqActive && faqElementMaxCountInContents === 0) {
93
+ return undefined;
94
+ }
95
+
96
+ if (isFaqActive && (faqElementMaxCountInContents as number) >= 2) {
97
+ return 'https://schema.org/FAQPage';
98
+ }
99
+
100
+ return 'https://schema.org/FAQPage';
101
+ };
102
+
103
+ const handleFaqItemScope = (isFaqActive: boolean, faqElementMaxCountInContents?: number): true | undefined => {
104
+ if (isFaqActive && faqElementMaxCountInContents === 0) {
105
+ return undefined;
106
+ }
107
+
108
+ if (isFaqActive && (faqElementMaxCountInContents as number) >= 2) {
109
+ return true;
110
+ }
111
+
112
+ return true;
113
+ };
114
+
115
+ const convertFaqItemType = (template: ISeoTemplateTypes): ISeoTemplateTypes => {
116
+ if ((faqElementMaxCountInContents as number) >= 2) {
117
+ // faqElementMaxCountInContents가 두 개 이상일 경우, template 내부에 FAQPage itemtype을 지운다. FAQPage 중복 이슈로 인한 코드임
118
+ template.description = template.description.replaceAll(
119
+ '&lt;div itemscope="" itemtype="https://schema.org/FAQPage"&gt;',
120
+ '&lt;div&gt;'
121
+ );
122
+
123
+ return template;
124
+ }
125
+
126
+ return template;
127
+ };
128
+
84
129
  // 변호사 6명 맞추기
85
130
  useEffect(() => {
86
131
  const originLawyerLength = lawyerData.length;
@@ -115,11 +160,25 @@ const SuccessNewView = ({ data, tel }: ISuccessNewPageTypes) => {
115
160
  }
116
161
  }, [template]);
117
162
 
163
+ useEffect(() => {
164
+ if (template) {
165
+ // 초기화
166
+ setIsFaqActive(false);
167
+
168
+ for (const data of template) {
169
+ // console.log("faq 활성화: ", data['active_faq']);
170
+ if (data['active_faq']) {
171
+ setIsFaqActive(true);
172
+ }
173
+ }
174
+ }
175
+ }, [template]);
176
+
118
177
  return (
119
178
  <div
120
179
  id="sub_contents"
121
- itemScope={!isFaqActive}
122
- itemType={!isFaqActive ? 'https://schema.org/FAQPage' : ''}
180
+ itemScope={handleFaqItemScope(isFaqActive, faqElementMaxCountInContents as number)}
181
+ itemType={handleFaqItemType(isFaqActive, faqElementMaxCountInContents as number)}
123
182
  ref={printRef}
124
183
  >
125
184
  <SuccessWrapper>
@@ -159,10 +218,14 @@ const SuccessNewView = ({ data, tel }: ISuccessNewPageTypes) => {
159
218
  className="mt-[52px] sm:mt-[62px] lg:mt-[75px]"
160
219
  key={'h2영역' + h2Template.idx}
161
220
  >
162
- <H2Contents h2Template={h2Template} index={index} />
221
+ <H2Contents
222
+ h2Template={convertFaqItemType(h2Template)}
223
+ index={index}
224
+ faqCount={h2Template?.faqCount}
225
+ />
163
226
  {template
164
227
  .filter(t => t.parent === h2Template.idx)
165
- .map((h3Template, h3Index) => {
228
+ .map(h3Template => {
166
229
  const refer_is_use = h3Template.reference_is_use;
167
230
  const refer_length = referenceLinkList.length;
168
231
  const refer_content_length = referenceLinkList.filter(
@@ -178,8 +241,9 @@ const SuccessNewView = ({ data, tel }: ISuccessNewPageTypes) => {
178
241
  return (
179
242
  <>
180
243
  <H3Contents
181
- h3Template={h3Template}
244
+ h3Template={convertFaqItemType(h3Template)}
182
245
  key={'h3영역' + h3Template.idx}
246
+ faqCount={h3Template?.faqCount}
183
247
  />
184
248
  {(refer_is_use && refer_length > 0 && refer_content_length > 0) ||
185
249
  (news_is_use && news_length > 0 && news_content_length > 0) ? (