Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/currency-input-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@lambdacurry/medusa-forms": patch
---

Fix currency input regex to reject malformed numbers and migrate to storybook/test v9

- Tighten number parsing: strip non-numeric, then clamp to valid format (no more `1.2.3` or `1-2-3`)
- Migrate `@storybook/test@8` → `storybook/test` (v9), removing compatibility warning
Comment on lines +5 to +8

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Keep the changeset scoped to the published package and actual behavior.

@lambdacurry/medusa-forms is the only package in the frontmatter, but the Storybook migration is an internal docs change. Also, ControlledCurrencyInput.tsx:6-48 normalizes/truncates malformed values rather than rejecting them. Keep this release note focused on currency parsing and describe the behavior as normalization.

Suggested wording
-Fix currency input regex to reject malformed numbers and migrate to storybook/test v9
+Normalize malformed currency input to a single numeric value
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.changeset/currency-input-fix.md around lines 5 - 8, Update the changeset
for `@lambdacurry/medusa-forms` to cover only the published currency-input
behavior; remove the internal Storybook/test v9 migration from the release note.
In the currency parsing description, refer to normalization of malformed values,
including stripping non-numeric characters and clamping the format, rather than
claiming they are rejected.

2 changes: 0 additions & 2 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
},
"devDependencies": {
"@storybook/addon-docs": "^9.0.6",
"@storybook/test": "^8.6.14",
"@storybook/test-runner": "^0.22.1",
"@storybook/testing-library": "^0.2.2",
"@tailwindcss/postcss": "^4.1.8",
"@tailwindcss/vite": "^4.0.0",
"@types/react": "^19.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { zodResolver } from '@hookform/resolvers/zod';
import { ControlledCurrencyInput } from '@lambdacurry/medusa-forms/controlled/ControlledCurrencyInput';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, userEvent, waitFor, within } from '@storybook/test';
import { useEffect } from 'react';
import { FormProvider, useForm } from 'react-hook-form';
import { expect, userEvent, waitFor, within } from 'storybook/test';
import { z } from 'zod';

const meta = {
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/medusa-forms/ControlledInput.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ControlledInput } from '@lambdacurry/medusa-forms/controlled/ControlledInput';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, userEvent, waitFor, within } from '@storybook/test';
import { FormProvider, useForm } from 'react-hook-form';
import { expect, userEvent, waitFor, within } from 'storybook/test';

const meta = {
title: 'Medusa Forms/Controlled Input',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { Controller, type ControllerProps, type FieldValues, type Path, useFormC
import { CurrencyInput, type CurrencyInputProps } from '../ui/CurrencyInput';
import { type ControlledRules, serializeDisplayValue, splitTransformRules, transformValue } from './valueTransforms';

/** Match a valid number: optional leading minus, digits, optional single decimal point + digits */
const NUMERIC_VALUE_REGEX = /^-?\d*\.?\d*/;
const NON_NUMERIC_REGEX = /[^0-9.-]/g;

export type ControlledCurrencyInputProps<T extends FieldValues> = CurrencyInputProps &
Omit<ControllerProps<T>, 'render' | 'control' | 'rules'> & {
name: Path<T>;
Expand Down Expand Up @@ -38,7 +42,8 @@ export const ControlledCurrencyInput = <T extends FieldValues>({
onChange(e);
}

const value = e.target.value.replace(/[^0-9.-]+/g, '');
const cleaned = e.target.value.replace(NON_NUMERIC_REGEX, '');
const value = cleaned.match(NUMERIC_VALUE_REGEX)?.[0] ?? '';
field.onChange(hasTransform ? transformValue(value, rules) : value);
}}
/>
Expand Down
Loading
Loading