11import React from 'react' ;
22
3- import { useTranslations } from 'next-intl' ;
4-
53import { EuiFlexGrid , EuiFlexItem } from '@elastic/eui' ;
64
7- import { WfoJsonCodeBlock } from '@/components' ;
8- import { WfoCustomerDescriptionsField } from '@/components/WfoSubscription/WfoCustomerDescriptionsField' ;
9- import { useSubscriptionDetailGeneralSectionConfigurationOverride } from '@/components/WfoSubscription/overrides/useSubscriptionDetailGeneralSectionConfigurationOverride' ;
5+ import {
6+ WfoSubscriptionDetailSection ,
7+ WfoSubscriptionFixedInputSection ,
8+ WfoSubscriptionMetadataSection ,
9+ WfoSubscriptionProductInfoSection ,
10+ useSubscriptionDetailGeneralSectionConfigurationOverride ,
11+ } from '@/components' ;
1012import { WfoSubscriptionDetailGeneralConfiguration } from '@/rtk' ;
1113import { SubscriptionDetail } from '@/types' ;
12- import { camelToHuman , formatDate , toOptionalArrayEntry } from '@/utils' ;
13-
14- import {
15- WfoProductStatusBadge ,
16- WfoSubscriptionStatusBadge ,
17- } from '../WfoBadges' ;
18- import { WfoKeyValueTableDataType } from '../WfoKeyValueTable/WfoKeyValueTable' ;
19- import { SubscriptionKeyValueBlock } from './SubscriptionKeyValueBlock' ;
20- import { WfoInSyncField } from './WfoInSyncField' ;
14+ import { toOptionalArrayEntry } from '@/utils' ;
2115
2216interface WfoSubscriptionGeneralProps {
2317 subscriptionDetail : SubscriptionDetail ;
@@ -35,177 +29,45 @@ export const WfoSubscriptionGeneral = ({
3529 subscriptionDetail,
3630 isFetching,
3731} : WfoSubscriptionGeneralProps ) => {
38- const t = useTranslations ( 'subscriptions.detail' ) ;
3932 const { overrideSections } =
4033 useSubscriptionDetailGeneralSectionConfigurationOverride ( ) ;
4134
42- const hasCustomerDescriptions =
43- subscriptionDetail . customerDescriptions . length > 0 ;
35+ const { metadata, fixedInputs, product } = subscriptionDetail ;
4436
45- const getSubscriptionDetailBlockData = ( ) : WfoKeyValueTableDataType [ ] => [
46- {
47- key : t ( 'subscriptionId' ) ,
48- value : subscriptionDetail . subscriptionId ,
49- textToCopy : subscriptionDetail . subscriptionId ,
50- } ,
51- {
52- key : t ( 'productName' ) ,
53- value : subscriptionDetail . product . name ,
54- } ,
55- {
56- key : t ( 'description' ) ,
57- value : subscriptionDetail . description ,
58- } ,
59- {
60- key : t ( 'startDate' ) ,
61- value : formatDate ( subscriptionDetail . startDate ) ,
62- } ,
63- {
64- key : t ( 'endDate' ) ,
65- value : formatDate ( subscriptionDetail . endDate ) ,
66- } ,
67- {
68- key : t ( 'status' ) ,
69- value : (
70- < WfoSubscriptionStatusBadge
71- status = { subscriptionDetail . status }
72- />
73- ) ,
74- } ,
75- {
76- key : t ( 'insync' ) ,
77- value : (
78- < WfoInSyncField
79- subscriptionDetail = { subscriptionDetail }
80- isFetching = { isFetching }
81- />
82- ) ,
83- } ,
84- {
85- key : t ( 'customer' ) ,
86- value :
87- subscriptionDetail && subscriptionDetail . customer
88- ? `${ subscriptionDetail . customer ?. fullname } `
89- : '-' ,
90- } ,
91- {
92- key : t ( 'customerUuid' ) ,
93- value :
94- subscriptionDetail && subscriptionDetail . customer
95- ? `${ subscriptionDetail . customer ?. customerId } `
96- : '-' ,
97- textToCopy : subscriptionDetail . customer ?. customerId ,
98- } ,
99- ...toOptionalArrayEntry (
100- {
101- key : t ( 'customerDescriptions' ) ,
102- value : (
103- < WfoCustomerDescriptionsField
104- customerDescriptions = {
105- subscriptionDetail . customerDescriptions
106- }
107- />
108- ) ,
109- } ,
110- hasCustomerDescriptions ,
111- ) ,
112- {
113- key : t ( 'note' ) ,
114- value : ( subscriptionDetail && subscriptionDetail . note ) || '-' ,
115- } ,
116- ] ;
117-
118- const getMetadataBlockData = ( ) : WfoKeyValueTableDataType [ ] =>
119- Object . entries ( subscriptionDetail . metadata ) . map ( ( [ key , value ] ) => ( {
120- key : camelToHuman ( key ) ,
121- value : < WfoJsonCodeBlock data = { value } isBasicStyle /> ,
122- } ) ) ;
123-
124- const getFixedInputBlockData = ( ) : WfoKeyValueTableDataType [ ] =>
125- subscriptionDetail . fixedInputs . map ( ( fixedInput ) => ( {
126- key : fixedInput . field ,
127- value : fixedInput . value ,
128- } ) ) ;
129-
130- const getProductInfoBlockData = ( ) : WfoKeyValueTableDataType [ ] => {
131- const product = subscriptionDetail . product ;
132- return [
133- {
134- key : t ( 'name' ) ,
135- value : product . name ,
136- } ,
137- {
138- key : t ( 'description' ) ,
139- value : product . description ,
140- } ,
141- {
142- key : t ( 'productType' ) ,
143- value : product . productType ,
144- } ,
145- {
146- key : t ( 'tag' ) ,
147- value : product . tag ,
148- } ,
149- {
150- key : t ( 'status' ) ,
151- value : < WfoProductStatusBadge status = { product . status } /> ,
152- } ,
153- {
154- key : t ( 'created' ) ,
155- value : formatDate ( product . createdAt ) ,
156- } ,
157- {
158- key : t ( 'endDate' ) ,
159- value : formatDate ( product . endDate ) ,
160- } ,
161- ] ;
162- } ;
163-
164- const hasMetadata = Object . entries ( subscriptionDetail . metadata ) . length > 0 ;
165- const hasFixedInputs = subscriptionDetail . fixedInputs . length > 0 ;
37+ const hasMetadata = Object . entries ( metadata ) . length > 0 ;
38+ const hasFixedInputs = fixedInputs . length > 0 ;
16639
16740 const defaultConfiguration : WfoSubscriptionDetailGeneralConfiguration [ ] = [
16841 {
16942 id : WfoSubscriptionGeneralSections . BLOCK_TITLE_SUBSCRIPTION_DETAILS ,
17043 node : (
171- < SubscriptionKeyValueBlock
172- title = { t ( 'blockTitleSubscriptionDetails' ) }
173- keyValues = { getSubscriptionDetailBlockData ( ) }
44+ < WfoSubscriptionDetailSection
45+ subscriptionDetail = { subscriptionDetail }
46+ isFetching = { isFetching }
17447 />
17548 ) ,
17649 } ,
17750 ...toOptionalArrayEntry (
17851 {
17952 id : WfoSubscriptionGeneralSections . BLOCK_TITLE_METADATA ,
180- node : (
181- < SubscriptionKeyValueBlock
182- title = { t ( 'metadata' ) }
183- keyValues = { getMetadataBlockData ( ) }
184- />
185- ) ,
53+ node : < WfoSubscriptionMetadataSection metadata = { metadata } /> ,
18654 } ,
18755 hasMetadata ,
18856 ) ,
18957 ...toOptionalArrayEntry (
19058 {
19159 id : WfoSubscriptionGeneralSections . BLOCK_TITLE_FIXED_INPUTS ,
19260 node : (
193- < SubscriptionKeyValueBlock
194- title = { t ( 'blockTitleFixedInputs' ) }
195- keyValues = { getFixedInputBlockData ( ) }
61+ < WfoSubscriptionFixedInputSection
62+ fixedInputs = { fixedInputs }
19663 />
19764 ) ,
19865 } ,
19966 hasFixedInputs ,
20067 ) ,
20168 {
20269 id : WfoSubscriptionGeneralSections . BLOCK_TITLE_PRODUCT_INFO ,
203- node : (
204- < SubscriptionKeyValueBlock
205- title = { t ( 'blockTitleProductInfo' ) }
206- keyValues = { getProductInfoBlockData ( ) }
207- />
208- ) ,
70+ node : < WfoSubscriptionProductInfoSection product = { product } /> ,
20971 } ,
21072 ] ;
21173
0 commit comments