Skip to content

Commit 83ac890

Browse files
committed
feat: refactored and simplified code (PIN-9116)
1 parent 0c4075f commit 83ac890

File tree

4 files changed

+51
-61
lines changed

4 files changed

+51
-61
lines changed

src/pages/ProviderEServiceSummaryPage/ProviderEServiceSummary.page.tsx

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -240,25 +240,17 @@ const ProviderEServiceSummaryPage: React.FC = () => {
240240
}
241241
}
242242

243-
enum Section {
244-
GeneralInfoSummary = 'generalInfoSummary',
245-
VersionInfoSummary = 'versionInfoSummary',
246-
DocumentationSummary = 'documentationSummary',
247-
}
243+
const isGeneralInfoSectionValid =
244+
Boolean(descriptor?.eservice.description) &&
245+
Boolean(descriptor?.eservice.technology) &&
246+
(FEATURE_FLAG_ESERVICE_PERSONAL_DATA ? arePersonalDataSet : true)
248247

249-
const isSectionValid = (section: Section) => {
250-
const sections = {
251-
[Section.GeneralInfoSummary]:
252-
!!descriptor?.eservice.description &&
253-
!!descriptor?.eservice.technology &&
254-
(FEATURE_FLAG_ESERVICE_PERSONAL_DATA ? arePersonalDataSet : true),
255-
[Section.VersionInfoSummary]:
256-
!!descriptor?.description && !!descriptor?.audience[0] && !!descriptor?.voucherLifespan,
257-
[Section.DocumentationSummary]: !!descriptor?.interface,
258-
}
248+
const isVersionInfoSectionValid =
249+
Boolean(descriptor?.description) &&
250+
Boolean(descriptor?.audience?.length) &&
251+
Boolean(descriptor?.voucherLifespan)
259252

260-
return sections[section]
261-
}
253+
const isDocumentationSectionValid = Boolean(descriptor?.interface)
262254

263255
return (
264256
<>
@@ -304,6 +296,8 @@ const ProviderEServiceSummaryPage: React.FC = () => {
304296
headline="1"
305297
title={t('summary.generalInfoSummary.title')}
306298
defaultExpanded={true}
299+
showWarning={!isGeneralInfoSectionValid}
300+
warningLabel={t('summary.missingInformationsLabel')}
307301
>
308302
<ProviderEServiceGeneralInfoSummary />
309303
</SummaryAccordion>
@@ -324,7 +318,7 @@ const ProviderEServiceSummaryPage: React.FC = () => {
324318
<SummaryAccordion
325319
headline={isReceiveMode ? '4' : '3'}
326320
title={t('summary.documentationSummary.title')}
327-
showWarning={!isSectionValid(Section.DocumentationSummary)}
321+
showWarning={!isVersionInfoSectionValid}
328322
warningLabel={t('summary.missingInformationsLabel')}
329323
>
330324
<ProviderEServiceDocumentationSummary />
@@ -334,7 +328,7 @@ const ProviderEServiceSummaryPage: React.FC = () => {
334328
<SummaryAccordion
335329
headline={isReceiveMode ? '5' : '4'}
336330
title={t('summary.versionInfoSummary.title')}
337-
showWarning={!isSectionValid(Section.VersionInfoSummary)}
331+
showWarning={!isDocumentationSectionValid}
338332
warningLabel={t('summary.missingInformationsLabel')}
339333
>
340334
<ProviderEServiceVersionInfoSummary />

src/pages/ProviderEServiceSummaryPage/components/ProviderEServiceDocumentationSummary.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ export const ProviderEServiceDocumentationSummary: React.FC = () => {
3939
<Stack spacing={2}>
4040
<ProviderEServiceInformationContainer
4141
label={t('interface.label')}
42-
content={descriptor.interface?.prettyName}
43-
>
44-
{descriptor.interface && (
45-
<IconLink
46-
component="button"
47-
startIcon={<AttachFileIcon fontSize="small" />}
48-
onClick={handleDownloadDocument.bind(null, descriptor.interface)}
49-
>
50-
{descriptor.interface.prettyName}
51-
</IconLink>
52-
)}
53-
</ProviderEServiceInformationContainer>
42+
content={
43+
descriptor.interface && (
44+
<IconLink
45+
component="button"
46+
startIcon={<AttachFileIcon fontSize="small" />}
47+
onClick={handleDownloadDocument.bind(null, descriptor.interface)}
48+
>
49+
{descriptor.interface.prettyName}
50+
</IconLink>
51+
)
52+
}
53+
/>
5454
<ProviderEServiceInformationContainer
5555
label={t('audience.label')}
5656
content={descriptor.audience[0]}

src/pages/ProviderEServiceSummaryPage/components/ProviderEServiceInformationContainer.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,31 @@ import { useTranslation } from 'react-i18next'
77

88
type ProviderEServiceInformationContainerProps = {
99
label: string
10-
content?: string
11-
children?: React.ReactNode
10+
content?: string | JSX.Element
1211
}
1312

1413
export const ProviderEServiceInformationContainer: React.FC<
1514
ProviderEServiceInformationContainerProps
16-
> = ({ label, content, children }) => {
15+
> = ({ label, content }) => {
1716
const { t } = useTranslation('eservice')
1817

19-
if (children) {
20-
return (
21-
<InformationContainer sx={{ alignItems: 'center' }} label={label} content={<>{children}</>} />
22-
)
23-
}
24-
25-
if (content) {
26-
return <InformationContainer label={label} content={content} />
27-
}
18+
const hasContent = content !== null && content !== undefined
2819

2920
return (
3021
<InformationContainer
22+
sx={{ alignItems: 'center' }}
3123
label={label}
3224
content={
33-
<Stack alignItems="center" spacing={1} direction="row">
34-
<ReportProblemOutlinedIcon fontSize="small" color="warning" />
35-
<Typography variant="body2" fontWeight={600}>
36-
{t('summary.documentationSummary.missingInfoLabel')}
37-
</Typography>
38-
</Stack>
25+
hasContent ? (
26+
content
27+
) : (
28+
<Stack alignItems="center" spacing={1} direction="row">
29+
<ReportProblemOutlinedIcon fontSize="small" color="warning" />
30+
<Typography variant="body2" fontWeight={600}>
31+
{t('summary.documentationSummary.missingInfoLabel')}
32+
</Typography>
33+
</Stack>
34+
)
3935
}
4036
/>
4137
)

src/pages/ProviderEServiceSummaryPage/components/ProviderEServiceVersionInfoSummary.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ export const ProviderEServiceVersionInfoSummary: React.FC = () => {
4343
<ProviderEServiceInformationContainer
4444
key={doc.id}
4545
label={index === 0 ? t('documentation') : ''}
46-
content={doc.prettyName}
47-
>
48-
{descriptor.interface && (
49-
<IconLink
50-
component="button"
51-
startIcon={<AttachFileIcon fontSize="small" />}
52-
onClick={handleDownloadDocument.bind(null, doc)}
53-
>
54-
{doc.prettyName}
55-
</IconLink>
56-
)}
57-
</ProviderEServiceInformationContainer>
46+
content={
47+
descriptor.interface && (
48+
<IconLink
49+
component="button"
50+
startIcon={<AttachFileIcon fontSize="small" />}
51+
onClick={handleDownloadDocument.bind(null, doc)}
52+
>
53+
{doc.prettyName}
54+
</IconLink>
55+
)
56+
}
57+
/>
5858
))}
5959
<ProviderEServiceInformationContainer
6060
label={t('manualApproval.label')}

0 commit comments

Comments
 (0)