From 3b6ef177ba5400e28ea611d52766a8476f006cc8 Mon Sep 17 00:00:00 2001 From: web Date: Sun, 28 Sep 2025 08:48:17 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Update=20minimum=20ratio?= =?UTF-8?q?=20value=20to=200=20in=20protocol=20fields=20and=20adjust=20rel?= =?UTF-8?q?ated=20schemas;=20enhance=20unit=20conversion=20in=20ServerConf?= =?UTF-8?q?ig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/dashboard/product/subscribe-form.tsx | 17 ++++++++++---- .../dashboard/servers/form-schema/fields.ts | 22 +++++++++---------- .../dashboard/servers/form-schema/schemas.ts | 2 +- .../app/dashboard/servers/server-config.tsx | 7 ++++-- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/apps/admin/app/dashboard/product/subscribe-form.tsx b/apps/admin/app/dashboard/product/subscribe-form.tsx index 68182e7..b1ed37f 100644 --- a/apps/admin/app/dashboard/product/subscribe-form.tsx +++ b/apps/admin/app/dashboard/product/subscribe-form.tsx @@ -1,5 +1,6 @@ 'use client'; +import useGlobalStore from '@/config/use-global'; import { useNode } from '@/store/node'; import { zodResolver } from '@hookform/resolvers/zod'; import { @@ -78,6 +79,9 @@ export default function SubscribeForm>({ trigger, title, }: Readonly>) { + const { common } = useGlobalStore(); + const { currency } = common; + const t = useTranslations('product'); const [open, setOpen] = useState(false); const updateTimeoutRef = useRef(null); @@ -213,7 +217,11 @@ export default function SubscribeForm>({ form?.reset( assign(defaultValues, shake(initialValues, (value) => value === null) as Record), ); - }, [form, initialValues]); + const discount = form.getValues('discount') || []; + if (discount.length > 0) { + debouncedCalculateDiscount(discount, 'discount'); + } + }, [form, initialValues, open]); useEffect(() => { return () => { @@ -228,7 +236,7 @@ export default function SubscribeForm>({ if (bool) setOpen(false); } - const { nodes, getAllAvailableTags, getNodesByTag, getNodesWithoutTags } = useNode(); + const { getAllAvailableTags, getNodesByTag, getNodesWithoutTags } = useNode(); const tagGroups = getAllAvailableTags(); @@ -630,9 +638,9 @@ export default function SubscribeForm>({ { name: 'discount', type: 'number', - min: 0.01, + min: 1, max: 100, - step: 0.01, + step: 1, placeholder: t('form.discountPercent'), suffix: '%', }, @@ -642,6 +650,7 @@ export default function SubscribeForm>({ type: 'number', min: 0, step: 0.01, + prefix: currency.currency_symbol, formatInput: (value) => unitConversion('centsToDollars', value), formatOutput: (value) => unitConversion('dollarsToCents', value).toString(), diff --git a/apps/admin/app/dashboard/servers/form-schema/fields.ts b/apps/admin/app/dashboard/servers/form-schema/fields.ts index bbb1a15..90b4dee 100644 --- a/apps/admin/app/dashboard/servers/form-schema/fields.ts +++ b/apps/admin/app/dashboard/servers/form-schema/fields.ts @@ -27,7 +27,7 @@ export const PROTOCOL_FIELDS: Record = { name: 'ratio', type: 'number', label: 'traffic_ratio', - min: 1, + min: 0, step: 0.01, defaultValue: 1, group: 'basic', @@ -134,7 +134,7 @@ export const PROTOCOL_FIELDS: Record = { name: 'ratio', type: 'number', label: 'traffic_ratio', - min: 1, + min: 0, step: 0.01, defaultValue: 1, group: 'basic', @@ -242,7 +242,7 @@ export const PROTOCOL_FIELDS: Record = { name: 'ratio', type: 'number', label: 'traffic_ratio', - min: 1, + min: 0, step: 0.01, defaultValue: 1, group: 'basic', @@ -500,7 +500,7 @@ export const PROTOCOL_FIELDS: Record = { name: 'ratio', type: 'number', label: 'traffic_ratio', - min: 1, + min: 0, step: 0.01, defaultValue: 1, group: 'basic', @@ -608,7 +608,7 @@ export const PROTOCOL_FIELDS: Record = { name: 'ratio', type: 'number', label: 'traffic_ratio', - min: 1, + min: 0, step: 0.01, defaultValue: 1, group: 'basic', @@ -716,7 +716,7 @@ export const PROTOCOL_FIELDS: Record = { name: 'ratio', type: 'number', label: 'traffic_ratio', - min: 1, + min: 0, step: 0.01, defaultValue: 1, group: 'basic', @@ -789,7 +789,7 @@ export const PROTOCOL_FIELDS: Record = { name: 'ratio', type: 'number', label: 'traffic_ratio', - min: 1, + min: 0, step: 0.01, defaultValue: 1, group: 'basic', @@ -809,7 +809,7 @@ export const PROTOCOL_FIELDS: Record = { name: 'ratio', type: 'number', label: 'traffic_ratio', - min: 1, + min: 0, step: 0.01, defaultValue: 1, group: 'basic', @@ -886,7 +886,7 @@ export const PROTOCOL_FIELDS: Record = { name: 'ratio', type: 'number', label: 'traffic_ratio', - min: 1, + min: 0, step: 0.01, defaultValue: 1, group: 'basic', @@ -963,7 +963,7 @@ export const PROTOCOL_FIELDS: Record = { name: 'ratio', type: 'number', label: 'traffic_ratio', - min: 1, + min: 0, step: 0.01, defaultValue: 1, group: 'basic', @@ -999,7 +999,7 @@ export const PROTOCOL_FIELDS: Record = { name: 'ratio', type: 'number', label: 'traffic_ratio', - min: 1, + min: 0, step: 0.01, defaultValue: 1, group: 'basic', diff --git a/apps/admin/app/dashboard/servers/form-schema/schemas.ts b/apps/admin/app/dashboard/servers/form-schema/schemas.ts index 0a5b2db..fdb957a 100644 --- a/apps/admin/app/dashboard/servers/form-schema/schemas.ts +++ b/apps/admin/app/dashboard/servers/form-schema/schemas.ts @@ -17,7 +17,7 @@ import { const nullableString = z.string().nullish(); const nullableBool = z.boolean().nullish(); const nullablePort = z.number().int().min(0).max(65535).nullish(); -const nullableRatio = z.number().min(1).nullish(); +const nullableRatio = z.number().min(0).nullish(); const ss = z.object({ ratio: nullableRatio, diff --git a/apps/admin/app/dashboard/servers/server-config.tsx b/apps/admin/app/dashboard/servers/server-config.tsx index 6daa898..5c78b06 100644 --- a/apps/admin/app/dashboard/servers/server-config.tsx +++ b/apps/admin/app/dashboard/servers/server-config.tsx @@ -35,6 +35,7 @@ import { Textarea } from '@workspace/ui/components/textarea'; import { ArrayInput } from '@workspace/ui/custom-components/dynamic-Inputs'; import { EnhancedInput } from '@workspace/ui/custom-components/enhanced-input'; import { Icon } from '@workspace/ui/custom-components/icon'; +import { unitConversion } from '@workspace/ui/utils'; import { DicesIcon } from 'lucide-react'; import { useTranslations } from 'next-intl'; import { uid } from 'radash'; @@ -275,8 +276,10 @@ export default function ServerConfig() { type='number' min={0} suffix='MB' - value={field.value as any} - onValueChange={field.onChange} + value={unitConversion('bitsToMb', field.value as number | undefined)} + onValueChange={(value) => { + field.onChange(unitConversion('mbToBits', value)); + }} placeholder='1' />