feat: support disable newsletter module
This commit is contained in:
parent
a1ae6ca384
commit
df3f3aa895
@ -1,10 +1,16 @@
|
||||
'use client';
|
||||
|
||||
import { NewsletterForm } from '@/components/newsletter/newsletter-form';
|
||||
import { websiteConfig } from '@/config/website';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { HeaderSection } from '../layout/header-section';
|
||||
|
||||
export function NewsletterCard() {
|
||||
// show nothing if newsletter is disabled
|
||||
if (!websiteConfig.newsletter.enable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const t = useTranslations('Newsletter');
|
||||
|
||||
return (
|
||||
|
@ -20,6 +20,7 @@ import {
|
||||
FormLabel,
|
||||
} from '@/components/ui/form';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { websiteConfig } from '@/config/website';
|
||||
import { authClient } from '@/lib/auth-client';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
@ -40,6 +41,11 @@ interface NewsletterFormCardProps {
|
||||
* Allows users to toggle their newsletter subscription status
|
||||
*/
|
||||
export function NewsletterFormCard({ className }: NewsletterFormCardProps) {
|
||||
// show nothing if newsletter is disabled
|
||||
if (!websiteConfig.newsletter.enable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const t = useTranslations('Dashboard.settings.notification');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | undefined>('');
|
||||
|
@ -81,6 +81,7 @@ export const websiteConfig: WebsiteConfig = {
|
||||
supportEmail: 'MkSaaS <support@mksaas.com>',
|
||||
},
|
||||
newsletter: {
|
||||
enable: true,
|
||||
provider: 'resend',
|
||||
autoSubscribeAfterSignUp: true,
|
||||
},
|
||||
|
@ -164,7 +164,11 @@ export function getLocaleFromRequest(request?: Request): Locale {
|
||||
async function onCreateUser(user: User) {
|
||||
// Auto subscribe user to newsletter after sign up if enabled in website config
|
||||
// Add a delay to avoid hitting Resend's 1 email per second limit
|
||||
if (user.email && websiteConfig.newsletter.autoSubscribeAfterSignUp) {
|
||||
if (
|
||||
user.email &&
|
||||
websiteConfig.newsletter.enable &&
|
||||
websiteConfig.newsletter.autoSubscribeAfterSignUp
|
||||
) {
|
||||
// Delay newsletter subscription by 2 seconds to avoid rate limiting
|
||||
// This ensures the email verification email is sent first
|
||||
// Using 2 seconds instead of 1 to provide extra buffer for network delays
|
||||
|
1
src/types/index.d.ts
vendored
1
src/types/index.d.ts
vendored
@ -137,6 +137,7 @@ export interface MailConfig {
|
||||
* Newsletter configuration
|
||||
*/
|
||||
export interface NewsletterConfig {
|
||||
enable: boolean; // Whether to enable the newsletter
|
||||
provider: 'resend'; // The newsletter provider, only resend is supported for now
|
||||
autoSubscribeAfterSignUp?: boolean; // Whether to automatically subscribe users to the newsletter after sign up
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user