🐛 fix(user): Refactor user form validation and reset password fields

This commit is contained in:
web@ppanel 2025-01-29 17:16:25 +07:00
parent f60d40c06d
commit 6733fc211c
4 changed files with 60 additions and 98 deletions

View File

@ -21,7 +21,6 @@ import {
SheetTrigger, SheetTrigger,
} from '@workspace/ui/components/sheet'; } from '@workspace/ui/components/sheet';
import { Switch } from '@workspace/ui/components/switch'; import { Switch } from '@workspace/ui/components/switch';
import { AreaCodeSelect } from '@workspace/ui/custom-components/area-code-select';
import { EnhancedInput } from '@workspace/ui/custom-components/enhanced-input'; import { EnhancedInput } from '@workspace/ui/custom-components/enhanced-input';
import { Icon } from '@workspace/ui/custom-components/icon'; import { Icon } from '@workspace/ui/custom-components/icon';
import { unitConversion } from '@workspace/ui/utils'; import { unitConversion } from '@workspace/ui/utils';
@ -52,9 +51,9 @@ export default function UserForm<T extends Record<string, any>>({
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const formSchema = z.object({ const formSchema = z.object({
email: z.string().email(t('form.invalidEmailFormat')), // email: z.string().email(t('form.invalidEmailFormat')),
telephone_area_code: z.string().optional(), // telephone_area_code: z.string().optional(),
telephone: z.string().optional(), // telephone: z.string().optional(),
password: z.string().optional(), password: z.string().optional(),
referer_id: z.number().optional(), referer_id: z.number().optional(),
refer_code: z.string().optional(), refer_code: z.string().optional(),
@ -99,7 +98,7 @@ export default function UserForm<T extends Record<string, any>>({
<ScrollArea className='-mx-6 h-[calc(100dvh-48px-36px-36px-env(safe-area-inset-top))]'> <ScrollArea className='-mx-6 h-[calc(100dvh-48px-36px-36px-env(safe-area-inset-top))]'>
<Form {...form}> <Form {...form}>
<form onSubmit={form.handleSubmit(handleSubmit)} className='space-y-4 px-6 pt-4'> <form onSubmit={form.handleSubmit(handleSubmit)} className='space-y-4 px-6 pt-4'>
<FormField {/* <FormField
control={form.control} control={form.control}
name='email' name='email'
render={({ field }) => ( render={({ field }) => (
@ -159,7 +158,7 @@ export default function UserForm<T extends Record<string, any>>({
<FormMessage /> <FormMessage />
</FormItem> </FormItem>
)} )}
/> /> */}
<FormField <FormField
control={form.control} control={form.control}
name='password' name='password'

View File

@ -59,18 +59,6 @@ export default function ResetForm({
</FormItem> </FormItem>
)} )}
/> />
<FormField
control={form.control}
name='password'
render={({ field }) => (
<FormItem>
<FormControl>
<Input placeholder='Enter your password...' type='password' {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
{auth?.email?.email_enable_verify && ( {auth?.email?.email_enable_verify && (
<FormField <FormField
@ -101,6 +89,18 @@ export default function ResetForm({
)} )}
/> />
)} )}
<FormField
control={form.control}
name='password'
render={({ field }) => (
<FormItem>
<FormControl>
<Input placeholder='Enter your new password...' type='password' {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
{verify.enable_reset_password_verify && ( {verify.enable_reset_password_verify && (
<FormField <FormField
control={form.control} control={form.control}

View File

@ -91,20 +91,6 @@ export default function ResetForm({
</FormItem> </FormItem>
)} )}
/> />
<FormField
control={form.control}
name='password'
render={({ field }) => (
<FormItem>
<FormControl>
<Input placeholder='Enter your password...' type='password' {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
{auth?.email?.email_enable_verify && (
<FormField <FormField
control={form.control} control={form.control}
name='code' name='code'
@ -125,7 +111,18 @@ export default function ResetForm({
</FormItem> </FormItem>
)} )}
/> />
<FormField
control={form.control}
name='password'
render={({ field }) => (
<FormItem>
<FormControl>
<Input placeholder='Enter your new password...' type='password' {...field} />
</FormControl>
<FormMessage />
</FormItem>
)} )}
/>
{verify.enable_reset_password_verify && ( {verify.enable_reset_password_verify && (
<FormField <FormField
control={form.control} control={form.control}

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Skip script in CI environment # Skip entire script in CI environment
if [ "$CI" = "true" ]; then if [ "$CI" = "true" ]; then
echo "CI environment detected, skipping script execution." echo "CI environment detected, skipping script execution."
exit 0 exit 0
@ -12,39 +12,28 @@ if [ ! -d ".git" ]; then
exit 1 exit 1
fi fi
# Check if .husky folder exists and skip `npx husky install` if it does
if [ -d ".husky" ]; then
echo ".husky folder already exists. Skipping npx husky install."
else
echo "Setting up Husky..."
if npx husky; then
echo "Husky has been successfully set up."
else
echo "Failed to set up Husky. Skipping."
exit 1
fi
fi
# Function to set up a Husky hook # Function to set up a Husky hook
setup_husky_hook() { setup_husky_hook() {
local hook_name=$1 local hook_name=$1
local hook_content=$2 local hook_content=$2
local hook_file=".husky/$hook_name"
if [ -f "$hook_file" ]; then
echo "$hook_name hook is already set up. Skipping."
return
fi
if [ ! -f ".husky/$hook_name" ]; then
echo "Setting up $hook_name hook..." echo "Setting up $hook_name hook..."
echo "$hook_content" > "$hook_file" && chmod +x "$hook_file" echo "$hook_content" > ".husky/$hook_name" || echo "Failed to set up $hook_name hook. Skipping."
if [ $? -eq 0 ]; then chmod +x ".husky/$hook_name" || echo "Failed to make $hook_name hook executable. Skipping."
echo "$hook_name hook has been successfully set up."
else else
echo "Failed to set up $hook_name hook. Skipping." echo "$hook_name hook is already set up."
fi fi
} }
# Ensure Husky is installed and initialized
if [ ! -d ".husky" ]; then
echo "Setting up Husky..."
npx husky || echo "Failed to set up Husky. Skipping."
else
echo "Husky is already set up."
fi
# Set up pre-commit hook # Set up pre-commit hook
setup_husky_hook "pre-commit" "#!/bin/sh setup_husky_hook "pre-commit" "#!/bin/sh
. \"\$(dirname \"\$0\")/_/husky.sh\" . \"\$(dirname \"\$0\")/_/husky.sh\"
@ -61,16 +50,11 @@ npx --no-install commitlint --edit \"\$1\""
install_global_package() { install_global_package() {
local package_name=$1 local package_name=$1
if npm list -g --depth=0 "$package_name" > /dev/null 2>&1; then if ! npm list -g --depth=0 "$package_name" > /dev/null 2>&1; then
echo "$package_name is already installed. Skipping installation."
return
fi
echo "Installing $package_name globally..." echo "Installing $package_name globally..."
if npm install -g "$package_name"; then npm install -g "$package_name" || echo "Failed to install $package_name globally. Skipping."
echo "$package_name has been successfully installed."
else else
echo "Failed to install $package_name globally. Skipping." echo "$package_name is already installed."
fi fi
} }
@ -78,24 +62,6 @@ install_global_package() {
install_global_package "@lobehub/i18n-cli" install_global_package "@lobehub/i18n-cli"
install_global_package "@lobehub/commit-cli" install_global_package "@lobehub/commit-cli"
# Check if .husky/_/prepare-commit-msg contains lobe-commit --hook
if grep -q "lobe-commit --hook" ".husky/_/prepare-commit-msg"; then
echo "prepare-commit-msg hook already contains lobe-commit --hook. Skipping lobe-commit -i."
else
# If the hook does not contain lobe-commit --hook, set it up and run lobe-commit -i
echo "Setting up prepare-commit-msg hook..."
if npx husky add .husky/prepare-commit-msg "exec < /dev/tty && npx lobe-commit -i"; then
echo "prepare-commit-msg hook has been successfully set up."
# Run lobe-commit interactively # Run lobe-commit interactively
echo "Running lobe-commit -i..." echo "Running lobe-commit -i..."
if lobe-commit -i; then lobe-commit -i || echo "lobe-commit failed. Skipping."
echo "lobe-commit executed successfully."
else
echo "lobe-commit failed. Skipping."
fi
else
echo "Failed to set up prepare-commit-msg hook. Skipping lobe-commit."
exit 1
fi
fi