@@ -12,6 +12,96 @@ type SendGridIntegrationSectionProps = {
1212 updateConfig : ( key : string , value : string | boolean ) => void ;
1313} ;
1414
15+ const renderHelpText = (
16+ helpText ?: string ,
17+ helpLink ?: { text : string ; url : string }
18+ ) => {
19+ if ( ! ( helpText || helpLink ) ) {
20+ return null ;
21+ }
22+ return (
23+ < p className = "text-muted-foreground text-xs" >
24+ { helpText }
25+ { helpLink && (
26+ < a
27+ className = "underline hover:text-foreground"
28+ href = { helpLink . url }
29+ rel = "noopener noreferrer"
30+ target = "_blank"
31+ >
32+ { helpLink . text }
33+ </ a >
34+ ) }
35+ </ p >
36+ ) ;
37+ } ;
38+
39+ const renderCheckboxField = (
40+ field : {
41+ id : string ;
42+ type : string ;
43+ label : string ;
44+ configKey : string ;
45+ defaultValue ?: string | boolean ;
46+ helpText ?: string ;
47+ helpLink ?: { text : string ; url : string } ;
48+ } ,
49+ config : IntegrationConfig ,
50+ updateConfig : ( key : string , value : string | boolean ) => void
51+ ) => {
52+ let checkboxValue : string | boolean | undefined = config [ field . configKey ] ;
53+ if ( checkboxValue === undefined ) {
54+ checkboxValue =
55+ field . defaultValue !== undefined ? field . defaultValue : true ;
56+ }
57+ const isChecked =
58+ typeof checkboxValue === "boolean"
59+ ? checkboxValue
60+ : checkboxValue === "true" ;
61+
62+ return (
63+ < div className = "flex items-center space-x-2" key = { field . id } >
64+ < Checkbox
65+ checked = { isChecked }
66+ id = { field . id }
67+ onCheckedChange = { ( checked ) =>
68+ updateConfig ( field . configKey , checked === true )
69+ }
70+ />
71+ < Label className = "cursor-pointer font-normal" htmlFor = { field . id } >
72+ { field . label }
73+ </ Label >
74+ { renderHelpText ( field . helpText , field . helpLink ) }
75+ </ div >
76+ ) ;
77+ } ;
78+
79+ const renderInputField = (
80+ field : {
81+ id : string ;
82+ type : string ;
83+ label : string ;
84+ configKey : string ;
85+ placeholder ?: string ;
86+ helpText ?: string ;
87+ helpLink ?: { text : string ; url : string } ;
88+ } ,
89+ config : IntegrationConfig ,
90+ updateConfig : ( key : string , value : string | boolean ) => void
91+ ) => (
92+ < div className = "space-y-2" key = { field . id } >
93+ < Label htmlFor = { field . id } > { field . label } </ Label >
94+ < Input
95+ id = { field . id }
96+ onChange = { ( e ) => updateConfig ( field . configKey , e . target . value ) }
97+ placeholder = { field . placeholder }
98+ type = { field . type }
99+ value = { ( config [ field . configKey ] as string ) || "" }
100+ />
101+ { renderHelpText ( field . helpText , field . helpLink ) }
102+ </ div >
103+ ) ;
104+
15105export function SendGridIntegrationSection ( {
16106 formFields,
17107 config,
@@ -28,80 +118,15 @@ export function SendGridIntegrationSection({
28118 < >
29119 { formFields . map ( ( field ) => {
30120 if ( field . type === "checkbox" ) {
31- let checkboxValue : string | boolean | undefined =
32- config [ field . configKey ] ;
33- if ( checkboxValue === undefined ) {
34- checkboxValue =
35- field . defaultValue !== undefined ? field . defaultValue : true ;
36- }
37- const isChecked =
38- typeof checkboxValue === "boolean"
39- ? checkboxValue
40- : checkboxValue === "true" ;
41-
42- return (
43- < div className = "flex items-center space-x-2" key = { field . id } >
44- < Checkbox
45- checked = { isChecked }
46- id = { field . id }
47- onCheckedChange = { ( checked ) =>
48- updateConfig ( field . configKey , checked === true )
49- }
50- />
51- < Label className = "cursor-pointer font-normal" htmlFor = { field . id } >
52- { field . label }
53- </ Label >
54- { ( field . helpText || field . helpLink ) && (
55- < p className = "text-muted-foreground text-xs" >
56- { field . helpText }
57- { field . helpLink && (
58- < a
59- className = "underline hover:text-foreground"
60- href = { field . helpLink . url }
61- rel = "noopener noreferrer"
62- target = "_blank"
63- >
64- { field . helpLink . text }
65- </ a >
66- ) }
67- </ p >
68- ) }
69- </ div >
70- ) ;
121+ return renderCheckboxField ( field , config , updateConfig ) ;
71122 }
72123
73124 // Hide API key field if useKeeperHubApiKey is checked
74125 if ( useKeeperHubApiKey && field . configKey === "apiKey" ) {
75126 return null ;
76127 }
77128
78- return (
79- < div className = "space-y-2" key = { field . id } >
80- < Label htmlFor = { field . id } > { field . label } </ Label >
81- < Input
82- id = { field . id }
83- onChange = { ( e ) => updateConfig ( field . configKey , e . target . value ) }
84- placeholder = { field . placeholder }
85- type = { field . type }
86- value = { ( config [ field . configKey ] as string ) || "" }
87- />
88- { ( field . helpText || field . helpLink ) && (
89- < p className = "text-muted-foreground text-xs" >
90- { field . helpText }
91- { field . helpLink && (
92- < a
93- className = "underline hover:text-foreground"
94- href = { field . helpLink . url }
95- rel = "noopener noreferrer"
96- target = "_blank"
97- >
98- { field . helpLink . text }
99- </ a >
100- ) }
101- </ p >
102- ) }
103- </ div >
104- ) ;
129+ return renderInputField ( field , config , updateConfig ) ;
105130 } ) }
106131 </ >
107132 ) ;
0 commit comments