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