Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

921 B
Raw Blame
import type { TaxCategoryCreateParams, TaxCategoryUpdateParams } from '@spree/admin-sdk'
import { blankToNull } from '@spree/dashboard-core'
import { requiredMessage } from '@spree/dashboard-ui'
import { z } from 'zod/v4'

export const taxCategoryFormSchema = z.object({
  name: z.string().min(1, { error: requiredMessage('name') }),
  tax_code: z.string().optional(),
  description: z.string().optional(),
  is_default: z.boolean(),
})

export type TaxCategoryFormValues = z.infer<typeof taxCategoryFormSchema>

export const TAX_CATEGORY_DEFAULTS: TaxCategoryFormValues = {
  name: '',
  tax_code: '',
  description: '',
  is_default: false,
}

export function taxCategoryValuesToParams(
  v: TaxCategoryFormValues,
): TaxCategoryCreateParams & TaxCategoryUpdateParams {
  return {
    name: v.name,
    tax_code: blankToNull(v.tax_code),
    description: blankToNull(v.description),
    is_default: v.is_default,
  }
}