Skip to content

Commit ec7e252

Browse files
committed
Build fix
1 parent 72b2a06 commit ec7e252

File tree

2 files changed

+177
-135
lines changed

2 files changed

+177
-135
lines changed

components/settings/integration-form-dialog.tsx

Lines changed: 85 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,89 @@ export function IntegrationFormDialog({
191191
});
192192
};
193193

194+
const renderHelpText = (
195+
helpText?: string,
196+
helpLink?: { text: string; url: string }
197+
) => {
198+
if (!(helpText || helpLink)) {
199+
return null;
200+
}
201+
return (
202+
<p className="text-muted-foreground text-xs">
203+
{helpText}
204+
{helpLink && (
205+
<a
206+
className="underline hover:text-foreground"
207+
href={helpLink.url}
208+
rel="noopener noreferrer"
209+
target="_blank"
210+
>
211+
{helpLink.text}
212+
</a>
213+
)}
214+
</p>
215+
);
216+
};
217+
218+
const renderCheckboxField = (field: {
219+
id: string;
220+
type: string;
221+
label: string;
222+
configKey: string;
223+
defaultValue?: string | boolean;
224+
helpText?: string;
225+
helpLink?: { text: string; url: string };
226+
}) => {
227+
let checkboxValue: string | boolean | undefined =
228+
formData.config[field.configKey];
229+
if (checkboxValue === undefined) {
230+
checkboxValue =
231+
field.defaultValue !== undefined ? field.defaultValue : true;
232+
}
233+
const isChecked =
234+
typeof checkboxValue === "boolean"
235+
? checkboxValue
236+
: checkboxValue === "true";
237+
238+
return (
239+
<div className="flex items-center space-x-2" key={field.id}>
240+
<Checkbox
241+
checked={isChecked}
242+
id={field.id}
243+
onCheckedChange={(checked) =>
244+
updateConfig(field.configKey, checked === true)
245+
}
246+
/>
247+
<Label className="cursor-pointer font-normal" htmlFor={field.id}>
248+
{field.label}
249+
</Label>
250+
{renderHelpText(field.helpText, field.helpLink)}
251+
</div>
252+
);
253+
};
254+
255+
const renderInputField = (field: {
256+
id: string;
257+
type: string;
258+
label: string;
259+
configKey: string;
260+
placeholder?: string;
261+
helpText?: string;
262+
helpLink?: { text: string; url: string };
263+
}) => (
264+
<div className="space-y-2" key={field.id}>
265+
<Label htmlFor={field.id}>{field.label}</Label>
266+
<Input
267+
id={field.id}
268+
onChange={(e) => updateConfig(field.configKey, e.target.value)}
269+
placeholder={field.placeholder}
270+
type={field.type}
271+
value={(formData.config[field.configKey] as string) || ""}
272+
/>
273+
{renderHelpText(field.helpText, field.helpLink)}
274+
</div>
275+
);
276+
194277
const renderConfigFields = () => {
195278
// Handle system integrations with hardcoded fields
196279
if (formData.type === "database") {
@@ -237,75 +320,9 @@ export function IntegrationFormDialog({
237320
// Default rendering for other integrations
238321
return plugin.formFields.map((field) => {
239322
if (field.type === "checkbox") {
240-
let checkboxValue: string | boolean | undefined =
241-
formData.config[field.configKey];
242-
if (checkboxValue === undefined) {
243-
checkboxValue =
244-
field.defaultValue !== undefined ? field.defaultValue : true;
245-
}
246-
const isChecked =
247-
typeof checkboxValue === "boolean"
248-
? checkboxValue
249-
: checkboxValue === "true";
250-
251-
return (
252-
<div className="flex items-center space-x-2" key={field.id}>
253-
<Checkbox
254-
checked={isChecked}
255-
id={field.id}
256-
onCheckedChange={(checked) =>
257-
updateConfig(field.configKey, checked === true)
258-
}
259-
/>
260-
<Label className="cursor-pointer font-normal" htmlFor={field.id}>
261-
{field.label}
262-
</Label>
263-
{(field.helpText || field.helpLink) && (
264-
<p className="text-muted-foreground text-xs">
265-
{field.helpText}
266-
{field.helpLink && (
267-
<a
268-
className="underline hover:text-foreground"
269-
href={field.helpLink.url}
270-
rel="noopener noreferrer"
271-
target="_blank"
272-
>
273-
{field.helpLink.text}
274-
</a>
275-
)}
276-
</p>
277-
)}
278-
</div>
279-
);
323+
return renderCheckboxField(field);
280324
}
281-
282-
return (
283-
<div className="space-y-2" key={field.id}>
284-
<Label htmlFor={field.id}>{field.label}</Label>
285-
<Input
286-
id={field.id}
287-
onChange={(e) => updateConfig(field.configKey, e.target.value)}
288-
placeholder={field.placeholder}
289-
type={field.type}
290-
value={(formData.config[field.configKey] as string) || ""}
291-
/>
292-
{(field.helpText || field.helpLink) && (
293-
<p className="text-muted-foreground text-xs">
294-
{field.helpText}
295-
{field.helpLink && (
296-
<a
297-
className="underline hover:text-foreground"
298-
href={field.helpLink.url}
299-
rel="noopener noreferrer"
300-
target="_blank"
301-
>
302-
{field.helpLink.text}
303-
</a>
304-
)}
305-
</p>
306-
)}
307-
</div>
308-
);
325+
return renderInputField(field);
309326
});
310327
};
311328

components/settings/sendgrid-integration-section.tsx

Lines changed: 92 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
15105
export 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

Comments
 (0)