Refactor: Move test email button and dialog

This commit is contained in:
Tola Leng
2025-06-17 21:39:12 +08:00
parent 575869c50a
commit e3f9111484
@@ -1,5 +1,4 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import { Switch } from "@/components/ui/switch"; import { Switch } from "@/components/ui/switch";
@@ -27,18 +26,15 @@ const MailSettingsTab: React.FC<MailSettingsTabProps> = ({
setIsTestingEmail(true); setIsTestingEmail(true);
console.log('Testing email with data:', data); console.log('Testing email with data:', data);
const response = await fetch('/api/settings', { const response = await fetch('/api/settings/test/email', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify({ body: JSON.stringify({
action: 'sendTestEmail', email: data.email,
data: { template: data.template,
email: data.email, ...(data.collection && { collection: data.collection })
template: data.template,
...(data.collection && { collection: data.collection })
}
}) })
}); });
@@ -257,10 +253,16 @@ const MailSettingsTab: React.FC<MailSettingsTabProps> = ({
)} )}
/> />
</div> </div>
</div>
{/* Only show Test Email button, removed Test Connection button */} {/* Test Email button - outside the form area and always visible when SMTP is enabled */}
{isEditing && form.watch('smtp.enabled') && ( {form.watch('smtp.enabled') && (
<div className="mt-4"> <div className="mt-6 pt-4 border-t border-border">
<div className="flex items-center justify-between mb-4">
<div>
<h3 className="text-lg font-medium">{t("testEmailSettings", "settings")}</h3>
<p className="text-sm text-muted-foreground">{t("testEmailDescription", "settings")}</p>
</div>
<Button <Button
type="button" type="button"
variant="outline" variant="outline"
@@ -272,8 +274,8 @@ const MailSettingsTab: React.FC<MailSettingsTabProps> = ({
{t("testEmail", "settings")} {t("testEmail", "settings")}
</Button> </Button>
</div> </div>
)} </div>
</div> )}
<TestEmailDialog <TestEmailDialog
open={showTestEmailDialog} open={showTestEmailDialog}