fix(dashboard, medusa): validate provider for top level tax regions (#12450)
* fix(dashboard, medusa): validate provider for top level tax regions * chore: changesets, message * chore: add test case for province * fix: remove comment
This commit is contained in:
@@ -6462,14 +6462,14 @@
|
||||
"errors": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"rateIsRequired": {
|
||||
"missingProvider": {
|
||||
"type": "string"
|
||||
},
|
||||
"nameIsRequired": {
|
||||
"missingCountry": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["rateIsRequired", "nameIsRequired"],
|
||||
"required": ["missingProvider", "missingCountry"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"successToast": {
|
||||
|
||||
@@ -1718,8 +1718,8 @@
|
||||
"header": "Create Tax Region",
|
||||
"hint": "Create a new tax region to define tax rates for a specific country.",
|
||||
"errors": {
|
||||
"rateIsRequired": "Tax rate is required when creating a default tax rate.",
|
||||
"nameIsRequired": "Name is required when creating a default tax rate."
|
||||
"missingProvider": "Provider is required when creating a tax region.",
|
||||
"missingCountry": "Country is required when creating a tax region."
|
||||
},
|
||||
"successToast": "The tax region was successfully created."
|
||||
},
|
||||
|
||||
@@ -18,21 +18,40 @@ import { useComboboxData } from "../../../../../hooks/use-combobox-data"
|
||||
import { Combobox } from "../../../../../components/inputs/combobox"
|
||||
import { formatProvider } from "../../../../../lib/format-provider"
|
||||
import { sdk } from "../../../../../lib/client"
|
||||
import { i18n } from "../../../../../components/utilities/i18n"
|
||||
|
||||
type TaxRegionCreateFormProps = {
|
||||
parentId?: string
|
||||
}
|
||||
|
||||
const TaxRegionCreateSchema = z.object({
|
||||
name: z.string().optional(),
|
||||
code: z.string().optional(),
|
||||
rate: z.object({
|
||||
float: z.number().optional(),
|
||||
value: z.string().optional(),
|
||||
}),
|
||||
country_code: z.string().min(1),
|
||||
provider_id: z.string(),
|
||||
})
|
||||
const TaxRegionCreateSchema = z
|
||||
.object({
|
||||
name: z.string().optional(),
|
||||
code: z.string().optional(),
|
||||
rate: z.object({
|
||||
float: z.number().optional(),
|
||||
value: z.string().optional(),
|
||||
}),
|
||||
country_code: z.string(),
|
||||
provider_id: z.string(),
|
||||
})
|
||||
.superRefine(({ provider_id, country_code }, ctx) => {
|
||||
if (!provider_id) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: i18n.t("taxRegions.create.errors.missingProvider"),
|
||||
path: ["provider_id"],
|
||||
})
|
||||
}
|
||||
|
||||
if (!country_code) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: i18n.t("taxRegions.create.errors.missingCountry"),
|
||||
path: ["country_code"],
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export const TaxRegionCreateForm = ({ parentId }: TaxRegionCreateFormProps) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
Reference in New Issue
Block a user