ui: simplify Gmail delivery settings
Co-Authored-By: Claude <noreply@anthropic.com> Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
parent
b92a5b2817
commit
c94c3d36ad
1 changed files with 19 additions and 53 deletions
|
|
@ -16,7 +16,7 @@ import {
|
|||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Plus, Trash2 } from "lucide-react";
|
||||
import { addUser, deleteUser, sendTestEmail, updateEmailSettings, type ActionResult } from "@/actions/settings";
|
||||
import { addUser, deleteUser, sendTestEmail, type ActionResult } from "@/actions/settings";
|
||||
import { updateDefaultPrice } from "@/actions/pricing";
|
||||
import { toast } from "sonner";
|
||||
import type { AppUser, FuelSettings } from "@/lib/types";
|
||||
|
|
@ -32,16 +32,6 @@ interface Props {
|
|||
export function SettingsForms({ currentUserId, settings, users }: Props) {
|
||||
const router = useRouter();
|
||||
const [defaultPrice, setDefaultPrice] = useState(settings?.default_price_per_litre || 0);
|
||||
const [emailState, emailAction, emailPending] = useActionState(updateEmailSettings, initial);
|
||||
const emailFormRef = useRef<HTMLFormElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (emailState.ok) {
|
||||
toast.success("Email settings saved");
|
||||
} else if (emailState.error) {
|
||||
toast.error(emailState.error);
|
||||
}
|
||||
}, [emailState]);
|
||||
|
||||
function onSaveDefault() {
|
||||
startTransition(async () => {
|
||||
|
|
@ -56,7 +46,7 @@ export function SettingsForms({ currentUserId, settings, users }: Props) {
|
|||
}
|
||||
|
||||
const [, startTransition] = useTransition();
|
||||
const [testEmail, setTestEmail] = useState(settings?.statement_from_email || "");
|
||||
const [testEmail, setTestEmail] = useState("");
|
||||
|
||||
function onSendTest() {
|
||||
if (!testEmail) {
|
||||
|
|
@ -116,51 +106,27 @@ export function SettingsForms({ currentUserId, settings, users }: Props) {
|
|||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Email settings</CardTitle>
|
||||
<CardDescription>SMTP / Resend configuration for sending statements</CardDescription>
|
||||
<CardTitle>Email delivery</CardTitle>
|
||||
<CardDescription>Customer statements are sent through Gmail SMTP.</CardDescription>
|
||||
</CardHeader>
|
||||
<form ref={emailFormRef} action={emailAction}>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="from">From email</Label>
|
||||
<Input id="from" name="statement_from_email" type="email" defaultValue={settings?.statement_from_email || ""} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="cc">CC email</Label>
|
||||
<Input id="cc" name="statement_cc_email" type="email" defaultValue={settings?.statement_cc_email || ""} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="app">App email (fallback)</Label>
|
||||
<Input id="app" name="statement_app_email" type="email" defaultValue={settings?.statement_app_email || ""} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="pwd">Email password (SMTP)</Label>
|
||||
<Input
|
||||
id="pwd"
|
||||
name="statement_email_password"
|
||||
type="password"
|
||||
placeholder="••••••••"
|
||||
defaultValue={settings?.statement_email_password ? "••••••••" : ""}
|
||||
/>
|
||||
</div>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="rounded-md border bg-muted/30 p-3 text-sm">
|
||||
<p className="font-medium">Configured sender</p>
|
||||
<p className="text-muted-foreground">rjbulk01@gmail.com</p>
|
||||
<p className="mt-2 text-muted-foreground">
|
||||
Gmail credentials are managed by the deployment environment and are not stored in PocketBase.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-end gap-2 pt-2 border-t">
|
||||
<div className="space-y-2 flex-1">
|
||||
<Label htmlFor="test">Send test email to:</Label>
|
||||
<Input id="test" type="email" value={testEmail} onChange={(e) => setTestEmail(e.target.value)} />
|
||||
</div>
|
||||
<div className="flex items-end gap-2 pt-2 border-t">
|
||||
<div className="space-y-2 flex-1">
|
||||
<Label htmlFor="test">Send test email to:</Label>
|
||||
<Input id="test" type="email" value={testEmail} onChange={(e) => setTestEmail(e.target.value)} />
|
||||
</div>
|
||||
<Button type="button" variant="outline" onClick={onSendTest}>
|
||||
Send test
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
<div className="px-6 pb-6">
|
||||
<Button type="submit" disabled={emailPending}>
|
||||
{emailPending ? "Saving…" : "Save email settings"}
|
||||
<Button type="button" variant="outline" onClick={onSendTest}>
|
||||
Send test
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<UsersSection currentUserId={currentUserId} users={users} />
|
||||
|
|
|
|||
Loading…
Reference in a new issue