🐛 fix(user): Update notification and verify code settings

This commit is contained in:
web@ppanel
2025-02-14 15:39:25 +07:00
parent e3f9ef6ebe
commit 574b043be6
112 changed files with 500 additions and 502 deletions
@@ -13,9 +13,6 @@ import { toast } from 'sonner';
import { z } from 'zod';
const FormSchema = z.object({
telegram: z.number().nullish(),
enable_email_notify: z.boolean(),
enable_telegram_notify: z.boolean(),
enable_balance_notify: z.boolean(),
enable_login_notify: z.boolean(),
enable_subscribe_notify: z.boolean(),
@@ -28,9 +25,6 @@ export default function NotifySettings() {
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
telegram: user?.telegram,
enable_email_notify: user?.enable_email_notify,
enable_telegram_notify: user?.enable_telegram_notify,
enable_balance_notify: user?.enable_balance_notify,
enable_login_notify: user?.enable_login_notify,
enable_subscribe_notify: user?.enable_subscribe_notify,
@@ -59,8 +53,6 @@ export default function NotifySettings() {
<form id='notify-form' onSubmit={form.handleSubmit(onSubmit)} className='space-y-4'>
<div className='space-y-4'>
{[
{ name: 'enable_email_notify', label: 'emailNotification' },
{ name: 'enable_telegram_notify', label: 'telegramNotification' },
{ name: 'enable_balance_notify', label: 'balanceChange' },
{ name: 'enable_login_notify', label: 'login' },
{ name: 'enable_subscribe_notify', label: 'subscribe' },
+25 -3
View File
@@ -1,10 +1,11 @@
'use client';
import useGlobalStore from '@/config/use-global';
import { sendEmailCode, sendSmsCode } from '@/services/common/common';
import { Button } from '@workspace/ui/components/button';
import { useCountDown } from 'ahooks';
import { useTranslations } from 'next-intl';
import { useState } from 'react';
import { useEffect, useState } from 'react';
interface SendCodeProps {
type: 'email' | 'phone';
@@ -17,22 +18,43 @@ interface SendCodeProps {
}
export default function SendCode({ type, params }: SendCodeProps) {
const t = useTranslations('auth');
const { common } = useGlobalStore();
const { verify_code_interval } = common.verify_code;
const [targetDate, setTargetDate] = useState<number>();
useEffect(() => {
const storedEndTime = localStorage.getItem(`verify_code_${type}`);
if (storedEndTime) {
const endTime = parseInt(storedEndTime);
if (endTime > Date.now()) {
setTargetDate(endTime);
} else {
localStorage.removeItem(`verify_code_${type}`);
}
}
}, [type]);
const [, { seconds }] = useCountDown({
targetDate,
onEnd: () => {
setTargetDate(undefined);
localStorage.removeItem(`verify_code_${type}`);
},
});
const setCodeTimer = () => {
const endTime = Date.now() + verify_code_interval * 1000;
setTargetDate(endTime);
localStorage.setItem(`verify_code_${type}`, endTime.toString());
};
const getEmailCode = async () => {
if (params.email && params.type) {
await sendEmailCode({
email: params.email,
type: params.type,
});
setTargetDate(Date.now() + 60000);
setCodeTimer();
}
};
@@ -43,7 +65,7 @@ export default function SendCode({ type, params }: SendCodeProps) {
telephone_area_code: params.telephone_area_code,
type: params.type,
});
setTargetDate(Date.now() + 60000);
setCodeTimer();
}
};