diff --git a/apps/web2/src/app/_components/posts/createPostForm.tsx b/apps/web2/src/app/_components/posts/createPostForm.tsx index 61167c3..e0c63d6 100644 --- a/apps/web2/src/app/_components/posts/createPostForm.tsx +++ b/apps/web2/src/app/_components/posts/createPostForm.tsx @@ -1,24 +1,19 @@ 'use client'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { trim } from 'lodash'; -import Link from 'next/link'; - -import { useState } from 'react'; -import { useForm } from 'react-hook-form'; - -import { z } from 'zod'; - import { fetchApi } from '@/lib/api'; import { generateLowerString } from '@/lib/utils'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { trim } from 'lodash'; +import Link from 'next/link'; +import { useState } from 'react'; +import { useForm } from 'react-hook-form'; +import { z } from 'zod'; import { MarkdownEditor } from '../markdown/editor'; - import { useAlert } from '../test/alert'; import { Button } from '../ui/button'; import { Input } from '../ui/input'; import { Label } from '../ui/label'; - import { isSlugUniqueForFrontend } from './hook'; export const CreatePostForm = () => { @@ -218,11 +213,11 @@ export const CreatePostForm = () => { disabled={form.formState.isSubmitting} className=" tw-mt-4 tw-mx-auto " type="submit" - onClick={() => handleSubmit()} + onClick={async () => handleSubmit()} > 保存 - + ); }; diff --git a/apps/web2/src/hooks/use-toast.ts b/apps/web2/src/hooks/use-toast.ts index b94fc00..160156e 100644 --- a/apps/web2/src/hooks/use-toast.ts +++ b/apps/web2/src/hooks/use-toast.ts @@ -1,10 +1,10 @@ 'use client'; +import type { ToastActionElement, ToastProps } from '@/app/_components/ui/toast'; + // Inspired by react-hot-toast library import * as React from 'react'; -import type { ToastActionElement, ToastProps } from '@/app/_components/ui/toast'; - const TOAST_LIMIT = 1; const TOAST_REMOVE_DELAY = 1000000; @@ -195,4 +195,4 @@ function useToast() { }; } -export { useToast, toast }; +export { toast, useToast }; diff --git a/apps/web2/src/lib/ms.ts b/apps/web2/src/lib/ms.ts index 83eac50..6c2efc9 100644 --- a/apps/web2/src/lib/ms.ts +++ b/apps/web2/src/lib/ms.ts @@ -90,16 +90,16 @@ export function parse(str: string): number { ); } const match = - /^(?-?(?:\d+)?\.?\d+) *(?milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( + /^(?-?(?:\d+(?:\.\d+)?|\.\d+)) *(?milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( str, ); // Named capture groups need to be manually typed today. // https://github.com/microsoft/TypeScript/issues/32098 const groups = match?.groups as { value: string; type?: string } | undefined; if (!groups) { - return NaN; + return Number.NaN; } - const n = parseFloat(groups.value); + const n = Number.parseFloat(groups.value); const type = (groups.type || 'ms').toLowerCase() as Lowercase; switch (type) { case 'years': @@ -157,7 +157,6 @@ export function parseStrict(value: StringValue): number { return parse(value); } -// eslint-disable-next-line import/no-default-export export default msFn; /** @@ -209,7 +208,7 @@ function fmtLong(ms: number): StringValue { */ export function format(ms: number, options?: Options): string { if (typeof ms !== 'number' || !Number.isFinite(ms)) { - throw new Error('Value provided to ms.format() must be of type number.'); + throw new TypeError('Value provided to ms.format() must be of type number.'); } return options?.long ? fmtLong(ms) : fmtShort(ms); } diff --git a/apps/web2/src/lib/validations/zod-password-validation-schema.ts b/apps/web2/src/lib/validations/zod-password-validation-schema.ts index b4baa0a..b77cb74 100644 --- a/apps/web2/src/lib/validations/zod-password-validation-schema.ts +++ b/apps/web2/src/lib/validations/zod-password-validation-schema.ts @@ -6,7 +6,7 @@ const FIELD_VALIDATION = { SPECIAL_CHAR: (value: string) => /[-._!"`'#%&,:;<>=@{}~$()*+/?[\]^|]+/.test(value), LOWERCASE: (value: string) => /[a-z]/.test(value), UPPERCASE: (value: string) => /[A-Z]/.test(value), - NUMBER: (value: string) => /.*[0-9].*/.test(value), + NUMBER: (value: string) => /.*\d.*/.test(value), }, MSG: { MIN_LEN: `密码长度必须 ${MIN_LENGTH} 字符以上`,