Skip to content

Commit 2532db1

Browse files
TASK: MD: Refactor individual components from functions to real components in EligibilityActions
1 parent c568413 commit 2532db1

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

src/app/_components/eligibility/EligibilityActions.tsx

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,21 @@ const EligibilityActions = ({ actions }: EligibilityActionProps): (JSX.Element |
1313
return actions.map((action: Action) => {
1414
switch (action.type) {
1515
case ActionDisplayType.infotext: {
16-
return _infotext(action.content, action.delineator);
16+
return <InfoText content={action.content} delineator={action.delineator} />;
1717
}
1818
case ActionDisplayType.card: {
19-
return _card(action.content, action.delineator);
19+
return <Card content={action.content} delineator={action.delineator} />;
2020
}
2121
case ActionDisplayType.buttonWithCard: {
2222
const card = action.content && <BasicCard content={action.content} delineator={false} />;
23-
const button = action.button && _button(action.button.url, action.button.label, "button", action.delineator);
23+
const button = action.button && (
24+
<Button
25+
url={action.button.url}
26+
label={action.button.label}
27+
renderAs={"button"}
28+
delineator={action.delineator}
29+
/>
30+
);
2431
return (
2532
<div key={action.content} data-testid="action-auth-button-components">
2633
{card}
@@ -30,8 +37,15 @@ const EligibilityActions = ({ actions }: EligibilityActionProps): (JSX.Element |
3037
);
3138
}
3239
case ActionDisplayType.buttonWithInfo: {
33-
const info = action.content && _infotext(action.content, false);
34-
const button = action.button && _button(action.button.url, action.button.label, "button", action.delineator);
40+
const info = action.content && <InfoText content={action.content} delineator={false} />;
41+
const button = action.button && (
42+
<Button
43+
url={action.button.url}
44+
label={action.button.label}
45+
renderAs={"button"}
46+
delineator={action.delineator}
47+
/>
48+
);
3549
return (
3650
<div key={action.content} data-testid="action-auth-button-components">
3751
{info}
@@ -41,7 +55,7 @@ const EligibilityActions = ({ actions }: EligibilityActionProps): (JSX.Element |
4155
);
4256
}
4357
case ActionDisplayType.actionLinkWithInfo: {
44-
const info = action.content && _infotext(action.content, false);
58+
const info = action.content && <InfoText content={action.content} delineator={false} />;
4559
const link = action.button && (
4660
<ActionLink asElement="a" href={action.button.url.href} rel="noopener" target="_blank">
4761
{action.button.label}
@@ -59,28 +73,40 @@ const EligibilityActions = ({ actions }: EligibilityActionProps): (JSX.Element |
5973
});
6074
};
6175

62-
const _infotext = (content: Content, delineator: boolean): JSX.Element => {
76+
type InfoTextProps = {
77+
content: Content;
78+
delineator: boolean;
79+
};
80+
81+
const InfoText = ({ content, delineator }: InfoTextProps): JSX.Element => {
6382
return (
6483
<div key={content} data-testid="action-paragraph">
6584
<MarkdownWithStyling content={content} delineator={delineator} />
6685
</div>
6786
);
6887
};
6988

70-
const _card = (content: Content, delineator: boolean): JSX.Element => {
89+
type CardProps = {
90+
content: Content;
91+
delineator: boolean;
92+
};
93+
94+
const Card = ({ content, delineator }: CardProps): JSX.Element => {
7195
return (
7296
<div key={content} data-testid="action-card-component">
7397
<BasicCard content={content} delineator={delineator} />
7498
</div>
7599
);
76100
};
77101

78-
const _button = (
79-
url: ButtonUrl,
80-
label: Label,
81-
renderAs: "anchor" | "button" | "actionLink",
82-
delineator: boolean,
83-
): JSX.Element => {
102+
type ButtonProps = {
103+
url: ButtonUrl;
104+
label: Label;
105+
renderAs: "anchor" | "button" | "actionLink";
106+
delineator: boolean;
107+
};
108+
109+
const Button = ({ url, label, renderAs, delineator }: ButtonProps): JSX.Element => {
84110
return (
85111
<NBSBookingActionForBaseUrl
86112
url={url.href}

0 commit comments

Comments
 (0)