Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: charge min amount should default to undefined if not set #1574

Merged
merged 1 commit into from
Jun 28, 2024
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
2 changes: 1 addition & 1 deletion src/components/plans/ChargeAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ export const ChargeAccordion = memo(
variant="quaternary"
disabled={disabled}
onClick={() => {
formikProps.setFieldValue(`charges.${index}.minAmountCents`, null)
formikProps.setFieldValue(`charges.${index}.minAmountCents`, undefined)
setShowSpendingMinimum(false)
}}
/>
Expand Down
14 changes: 7 additions & 7 deletions src/core/serializers/__tests__/serializePlanInput.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ describe('serializePlanInput()', () => {
billableMetricId: '1234',
chargeModel: 'package',
filters: [],
minAmountCents: 0,
minAmountCents: undefined,
properties: {
amount: '1',
fixedAmount: '2',
Expand Down Expand Up @@ -363,7 +363,7 @@ describe('serializePlanInput()', () => {
{
billableMetricId: '1234',
chargeModel: 'percentage',
minAmountCents: 0,
minAmountCents: undefined,
filters: [],
properties: {
amount: undefined,
Expand Down Expand Up @@ -431,7 +431,7 @@ describe('serializePlanInput()', () => {
{
billableMetricId: '1234',
chargeModel: 'standard',
minAmountCents: 0,
minAmountCents: undefined,
filters: [],
properties: {
amount: '1',
Expand Down Expand Up @@ -498,7 +498,7 @@ describe('serializePlanInput()', () => {
{
billableMetricId: '1234',
chargeModel: 'standard',
minAmountCents: 0,
minAmountCents: undefined,
filters: [],
properties: {
amount: undefined,
Expand Down Expand Up @@ -588,7 +588,7 @@ describe('serializePlanInput()', () => {
{
billableMetricId: '1234',
chargeModel: 'standard',
minAmountCents: 0,
minAmountCents: undefined,
properties: {
amount: undefined,
freeUnits: undefined,
Expand Down Expand Up @@ -691,7 +691,7 @@ describe('serializePlanInput()', () => {
{
billableMetricId: '1234',
chargeModel: 'volume',
minAmountCents: 0,
minAmountCents: undefined,
filters: [],
properties: {
amount: '1',
Expand Down Expand Up @@ -770,7 +770,7 @@ describe('serializePlanInput()', () => {
{
billableMetricId: '1234',
chargeModel: 'custom',
minAmountCents: 0,
minAmountCents: undefined,
filters: [],
properties: {
amount: '1',
Expand Down
4 changes: 3 additions & 1 deletion src/core/serializers/serializePlanInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ export const serializePlanInput = (values: PlanFormInput) => {
return {
chargeModel,
billableMetricId: billableMetric.id,
minAmountCents: Number(serializeAmount(minAmountCents, values.amountCurrency) || 0),
minAmountCents: !!minAmountCents
? Number(serializeAmount(minAmountCents, values.amountCurrency) || 0)
: undefined,
taxCodes: chargeTaxes?.map(({ code }) => code) || [],
filters: serializeFilters(filters, chargeModel),
properties: properties
Expand Down
16 changes: 11 additions & 5 deletions src/hooks/plans/usePlanForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,17 @@ export const usePlanForm: ({
// Used to not enable submit button on invoiceDisplayName reset
invoiceDisplayName: invoiceDisplayName || '',
taxes: taxes || [],
minAmountCents: isNaN(minAmountCents)
? undefined
: String(
deserializeAmount(minAmountCents || 0, plan.amountCurrency || CurrencyEnum.Usd),
),
minAmountCents:
// Some plan have been saved with minAmountCents as 0 string but it makes the sub form send an override plan each time
// This || minAmountCents === '0' serves to prevent this to happen
isNaN(minAmountCents) || minAmountCents === '0'
? undefined
: String(
deserializeAmount(
minAmountCents || 0,
plan.amountCurrency || CurrencyEnum.Usd,
),
),
payInAdvance: payInAdvance || false,
properties: properties ? getPropertyShape(properties) : undefined,
filters: (filters || []).map((filter) => {
Expand Down
Loading