🐛 fix(ui): Bugs

This commit is contained in:
web@ppanel 2024-11-15 13:21:39 +07:00
parent 059a8921d5
commit b023d0feff
8 changed files with 46 additions and 51 deletions

View File

@ -36,10 +36,10 @@ export default function Page() {
<div className='flex flex-col justify-center pb-14 lg:flex-auto lg:pb-20'> <div className='flex flex-col justify-center pb-14 lg:flex-auto lg:pb-20'>
<UserAuthForm /> <UserAuthForm />
</div> </div>
<div className='flex items-center justify-between'> <div className='flex items-center justify-end'>
<div className='text-primary flex gap-5 text-sm font-semibold'> {/* <div className='text-primary flex gap-5 text-sm font-semibold'>
<Link href='/tos'>{t('tos')}</Link> <Link href='/tos'>{t('tos')}</Link>
</div> </div> */}
<div className='flex items-center gap-5'> <div className='flex items-center gap-5'>
<LanguageSwitch /> <LanguageSwitch />
<ThemeSwitch /> <ThemeSwitch />

View File

@ -7,10 +7,7 @@ import {
import useGlobalStore from '@/config/use-global'; import useGlobalStore from '@/config/use-global';
import { checkUser, resetPassword, userLogin, userRegister } from '@/services/common/auth'; import { checkUser, resetPassword, userLogin, userRegister } from '@/services/common/auth';
import { getRedirectUrl, setAuthorization } from '@/utils/common'; import { getRedirectUrl, setAuthorization } from '@/utils/common';
import { Icon } from '@iconify/react';
import { Button } from '@shadcn/ui/button';
import { toast } from '@shadcn/ui/lib/sonner'; import { toast } from '@shadcn/ui/lib/sonner';
import { cn } from '@shadcn/ui/lib/utils';
import { useTranslations } from 'next-intl'; import { useTranslations } from 'next-intl';
import { useRouter } from 'next/navigation'; import { useRouter } from 'next/navigation';
import { ReactNode, useState, useTransition } from 'react'; import { ReactNode, useState, useTransition } from 'react';
@ -131,7 +128,7 @@ export default function UserAuthForm() {
{t(`${type || 'check'}.description`)} {t(`${type || 'check'}.description`)}
</div> </div>
</div> </div>
{!((type === 'register' && register.stop_register) || type === 'reset') && ( {/* {!((type === 'register' && register.stop_register) || type === 'reset') && (
<> <>
<div className='mb-3 flex flex-wrap items-center justify-center gap-3 font-bold'> <div className='mb-3 flex flex-wrap items-center justify-center gap-3 font-bold'>
<Button type='button' variant='outline'> <Button type='button' variant='outline'>
@ -157,7 +154,7 @@ export default function UserAuthForm() {
<span className='text-muted-foreground w-[125px] text-sm'>{t('orWithEmail')}</span> <span className='text-muted-foreground w-[125px] text-sm'>{t('orWithEmail')}</span>
</div> </div>
</> </>
)} )} */}
{UserForm} {UserForm}
</> </>

View File

@ -1,4 +1,3 @@
import useGlobalStore from '@/config/use-global';
import { Icon } from '@iconify/react'; import { Icon } from '@iconify/react';
import { Button } from '@shadcn/ui/button'; import { Button } from '@shadcn/ui/button';
import { Form, FormControl, FormField, FormItem, FormMessage } from '@shadcn/ui/form'; import { Form, FormControl, FormField, FormItem, FormMessage } from '@shadcn/ui/form';
@ -18,22 +17,20 @@ export default function UserCheckForm({
initialValues: any; initialValues: any;
}) { }) {
const t = useTranslations('auth.check'); const t = useTranslations('auth.check');
const { common } = useGlobalStore(); // const { common } = useGlobalStore();
const { register } = common; // const { register } = common;
const formSchema = z.object({ const formSchema = z.object({
email: z email: z.string().email(t('email')),
.string() // .refine(
.email(t('email')) // (email) => {
.refine( // if (!register.enable_email_domain_suffix) return true;
(email) => { // const domain = email.split('@')[1] as string;
if (!register.enable_email_domain_suffix) return true; // return register.email_domain_suffix_list.split('\n').includes(domain);
const domain = email.split('@')[1] as string; // },
return register.email_domain_suffix_list.split('\n').includes(domain); // {
}, // message: t('whitelist'),
{ // },
message: t('whitelist'), // ),
},
),
}); });
const form = useForm<z.infer<typeof formSchema>>({ const form = useForm<z.infer<typeof formSchema>>({

View File

@ -491,7 +491,7 @@ export default function SubscribeForm<T extends Record<string, any>>({
</div> </div>
</div> </div>
</div> </div>
<div className='grid grid-cols-2 gap-4'> <div className='flex flex-col gap-4'>
<FormField <FormField
control={form.control} control={form.control}
name='server_group' name='server_group'

View File

@ -24,7 +24,7 @@
"smtpAccount": "SMTP Account", "smtpAccount": "SMTP Account",
"smtpAccountDescription": "The email account used for authentication.", "smtpAccountDescription": "The email account used for authentication.",
"smtpEncryptionMethod": "SMTP Encryption Method", "smtpEncryptionMethod": "SMTP Encryption Method",
"smtpEncryptionMethodDescription": "Choose whether to enable SSL encryption.", "smtpEncryptionMethodDescription": "Choose whether to enable SSL/TLS encryption.",
"smtpPassword": "SMTP Password", "smtpPassword": "SMTP Password",
"smtpPasswordDescription": "The password for the SMTP account.", "smtpPasswordDescription": "The password for the SMTP account.",
"smtpServerAddress": "SMTP Server Address", "smtpServerAddress": "SMTP Server Address",

View File

@ -24,7 +24,7 @@
"smtpAccount": "SMTP 账号", "smtpAccount": "SMTP 账号",
"smtpAccountDescription": "用于身份验证的邮件账号。", "smtpAccountDescription": "用于身份验证的邮件账号。",
"smtpEncryptionMethod": "SMTP 加密方式", "smtpEncryptionMethod": "SMTP 加密方式",
"smtpEncryptionMethodDescription": "选择是否启用 SSL 加密。", "smtpEncryptionMethodDescription": "选择是否启用 SSL/TLS 加密。",
"smtpPassword": "SMTP 密码", "smtpPassword": "SMTP 密码",
"smtpPasswordDescription": "该 SMTP 账号的密码。", "smtpPasswordDescription": "该 SMTP 账号的密码。",
"smtpServerAddress": "SMTP 服务器地址", "smtpServerAddress": "SMTP 服务器地址",

View File

@ -26,7 +26,7 @@ export function EnhancedInput({
...props ...props
}: EnhancedInputProps) { }: EnhancedInputProps) {
const getProcessedValue = (inputValue: unknown) => { const getProcessedValue = (inputValue: unknown) => {
const newValue = String(inputValue ?? ''); const newValue = inputValue === '' || inputValue === 0 ? '' : String(inputValue ?? '');
return formatInput ? formatInput(newValue) : newValue; return formatInput ? formatInput(newValue) : newValue;
}; };
@ -47,16 +47,19 @@ export function EnhancedInput({
const handleChange = (e: ChangeEvent<HTMLInputElement>) => { const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
let inputValue = e.target.value; let inputValue = e.target.value;
if (props.type === 'number') { if (props.type === 'number' && inputValue) {
const numericValue = Number(inputValue); const numericValue = Number(inputValue);
if (!isNaN(numericValue)) { if (!isNaN(numericValue)) {
const min = Number.isFinite(props.min) ? props.min : -Infinity; const min = Number.isFinite(props.min) ? props.min : -Infinity;
const max = Number.isFinite(props.max) ? props.max : Infinity; const max = Number.isFinite(props.max) ? props.max : Infinity;
inputValue = String(Math.max(min!, Math.min(max!, numericValue))); inputValue = String(Math.max(min!, Math.min(max!, numericValue)));
} }
setValue(inputValue === '0' ? '' : inputValue);
} else {
setValue(inputValue);
} }
setValue(inputValue);
const outputValue = processValue(inputValue); const outputValue = processValue(inputValue);
console.log();
onValueChange?.(outputValue); onValueChange?.(outputValue);
}; };

View File

@ -2,13 +2,12 @@
import { Button } from '@shadcn/ui/button'; import { Button } from '@shadcn/ui/button';
import { cn } from '@shadcn/ui/lib/utils'; import { cn } from '@shadcn/ui/lib/utils';
import { ScrollArea } from '@shadcn/ui/scroll-area';
import 'katex/dist/katex.min.css'; import 'katex/dist/katex.min.css';
import { Check, Copy } from 'lucide-react'; import { Check, Copy } from 'lucide-react';
import { useCallback, useState } from 'react'; import { useCallback, useState } from 'react';
import ReactMarkdown from 'react-markdown'; import ReactMarkdown from 'react-markdown';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { oneDark, oneLight } from 'react-syntax-highlighter/dist/esm/styles/prism'; import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
import rehypeKatex from 'rehype-katex'; import rehypeKatex from 'rehype-katex';
import rehypeRaw from 'rehype-raw'; import rehypeRaw from 'rehype-raw';
import remarkGfm from 'remark-gfm'; import remarkGfm from 'remark-gfm';
@ -39,39 +38,38 @@ function CodeBlock({ className, children, dark, ...props }: CodeBlockProps) {
if (match) { if (match) {
return ( return (
<div className='group relative w-full'> <div className='group relative my-4 w-full overflow-hidden rounded-lg'>
<div className='bg-muted flex items-center justify-between gap-4 rounded-t-lg px-4 py-2 text-sm font-semibold'> <div className='bg-muted flex items-center justify-between gap-4 px-4 py-2 text-sm font-semibold'>
<span className='lowercase [&>span]:text-xs'>{match[1]}</span> <span className='lowercase [&>span]:text-xs'>{match[1]}</span>
<Button <Button
variant='ghost' variant='ghost'
size='sm' size='icon'
onClick={() => handleCopy(String(children).replace(/\n$/, ''))} onClick={() => handleCopy(String(children).replace(/\n$/, ''))}
className='absolute right-2 top-2 z-20 opacity-0 transition-opacity duration-200 group-hover:opacity-100' className='absolute right-2 top-0 z-20 p-0.5 opacity-0 transition-opacity duration-200 group-hover:opacity-100'
> >
{copied ? <Check size={16} /> : <Copy size={16} />} {copied ? <Check size={16} /> : <Copy size={16} />}
</Button> </Button>
</div> </div>
<ScrollArea className='max-h-96 w-full overflow-auto'> <SyntaxHighlighter
<SyntaxHighlighter {...props}
{...props} PreTag='div'
PreTag='div' language={match[1]}
language={match[1]} style={oneDark}
style={dark ? oneDark : oneLight} showLineNumbers
showLineNumbers customStyle={{
customStyle={{ margin: 0,
margin: 0, borderRadius: 0,
}} }}
> >
{String(children).replace(/\n$/, '')} {String(children).replace(/\n$/, '')}
</SyntaxHighlighter> </SyntaxHighlighter>
</ScrollArea>
</div> </div>
); );
} }
return ( return (
<code {...props} className={cn(className, 'bg-muted rounded border font-semibold')}> <code {...props} className={cn(className, 'rounded border font-semibold')}>
{children} {children}
</code> </code>
); );