feat(medusa,dashboard,tax): added tax rates and regions UI (#7026)
whats missing: - make rules required for overrides - conditions for other rules - populating condition reference ids with labels on update Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
1 parent
92b633d1cb
commit
00e6b21bb5
77 files changed
+3654
-104
No files matched your search
@@ -1,21 +1,20 @@
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../types/routing"
|
||||
|
||||
import {
|
||||
remoteQueryObjectFromString,
|
||||
ContainerRegistrationKeys,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
deleteTaxRatesWorkflow,
|
||||
updateTaxRatesWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../types/routing"
|
||||
import { refetchTaxRate } from "../helpers"
|
||||
import {
|
||||
AdminGetTaxRateParamsType,
|
||||
AdminUpdateTaxRateType,
|
||||
} from "../validators"
|
||||
import { refetchTaxRate } from "../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateTaxRateType>,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as QueryConfig from "./query-config"
|
||||
|
||||
import { validateAndTransformQuery } from "../../utils/validate-query"
|
||||
import {
|
||||
AdminCreateTaxRate,
|
||||
AdminCreateTaxRateRule,
|
||||
@@ -11,7 +12,6 @@ import {
|
||||
import { MiddlewareRoute } from "../../../loaders/helpers/routing/types"
|
||||
import { authenticate } from "../../../utils/authenticate-middleware"
|
||||
import { validateAndTransformBody } from "../../utils/validate-body"
|
||||
import { validateAndTransformQuery } from "../../utils/validate-query"
|
||||
|
||||
export const adminTaxRateRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
@@ -41,16 +41,6 @@ export const adminTaxRateRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: "GET",
|
||||
matcher: "/admin/tax-rates",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminGetTaxRatesParams,
|
||||
QueryConfig.listTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: "GET",
|
||||
matcher: "/admin/tax-rates/:id",
|
||||
@@ -61,6 +51,16 @@ export const adminTaxRateRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: "GET",
|
||||
matcher: "/admin/tax-rates",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminGetTaxRatesParams,
|
||||
QueryConfig.listTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: "POST",
|
||||
matcher: "/admin/tax-rates/:id/rules",
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
export const defaultAdminTaxRateRelations = []
|
||||
export const allowedAdminTaxRateRelations = []
|
||||
export const defaultAdminTaxRateFields = [
|
||||
export const defaults = [
|
||||
"id",
|
||||
"name",
|
||||
"code",
|
||||
@@ -13,14 +11,16 @@ export const defaultAdminTaxRateFields = [
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
"metadata",
|
||||
"*tax_region",
|
||||
"*rules",
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaults: defaultAdminTaxRateFields,
|
||||
defaults,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
export const listTransformQueryConfig = {
|
||||
defaults: defaultAdminTaxRateFields,
|
||||
defaults,
|
||||
isList: true,
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
import { createTaxRatesWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
remoteQueryObjectFromString,
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../types/routing"
|
||||
import { refetchTaxRate } from "./helpers"
|
||||
import {
|
||||
AdminCreateTaxRateType,
|
||||
AdminGetTaxRatesParamsType,
|
||||
} from "./validators"
|
||||
import { refetchTaxRate } from "./helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminCreateTaxRateType>,
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { createFindParams, createSelectParams } from "../../utils/validators"
|
||||
import { z } from "zod"
|
||||
import {
|
||||
createFindParams,
|
||||
createOperatorMap,
|
||||
createSelectParams,
|
||||
} from "../../utils/validators"
|
||||
|
||||
export type AdminGetTaxRateParamsType = z.infer<typeof AdminGetTaxRateParams>
|
||||
export const AdminGetTaxRateParams = createSelectParams()
|
||||
@@ -8,7 +12,20 @@ export type AdminGetTaxRatesParamsType = z.infer<typeof AdminGetTaxRatesParams>
|
||||
export const AdminGetTaxRatesParams = createFindParams({
|
||||
limit: 20,
|
||||
offset: 0,
|
||||
})
|
||||
}).merge(
|
||||
z.object({
|
||||
q: z.string().optional(),
|
||||
tax_region_id: z
|
||||
.union([z.string(), z.array(z.string()), createOperatorMap()])
|
||||
.optional(),
|
||||
is_default: z.union([z.literal("true"), z.literal("false")]).optional(),
|
||||
created_at: createOperatorMap().optional(),
|
||||
updated_at: createOperatorMap().optional(),
|
||||
deleted_at: createOperatorMap().optional(),
|
||||
$and: z.lazy(() => AdminGetTaxRatesParams.array()).optional(),
|
||||
$or: z.lazy(() => AdminGetTaxRatesParams.array()).optional(),
|
||||
})
|
||||
)
|
||||
|
||||
export type AdminCreateTaxRateRuleType = z.infer<typeof AdminCreateTaxRateRule>
|
||||
export const AdminCreateTaxRateRule = z.object({
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
import { deleteTaxRegionsWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../types/routing"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const filters = { id: req.params.id }
|
||||
const [taxRegion] = await remoteQuery(
|
||||
remoteQueryObjectFromString({
|
||||
entryPoint: "tax_region",
|
||||
variables: { filters },
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
)
|
||||
|
||||
res.status(200).json({ tax_region: taxRegion })
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import * as QueryConfig from "./query-config"
|
||||
|
||||
import { AdminCreateTaxRegion, AdminGetTaxRegionsParams } from "./validators"
|
||||
import {
|
||||
AdminCreateTaxRegion,
|
||||
AdminGetTaxRegionParams,
|
||||
AdminGetTaxRegionsParams,
|
||||
} from "./validators"
|
||||
|
||||
import { MiddlewareRoute } from "../../../loaders/helpers/routing/types"
|
||||
import { authenticate } from "../../../utils/authenticate-middleware"
|
||||
@@ -34,4 +38,14 @@ export const adminTaxRegionRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: "GET",
|
||||
matcher: "/admin/tax-regions/:id",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminGetTaxRegionParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
]
|
||||
@@ -9,6 +9,12 @@ export const defaults = [
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
"metadata",
|
||||
"*children",
|
||||
"*children.tax_rates",
|
||||
"*children.tax_rates.rules",
|
||||
"*parent",
|
||||
"*tax_rates",
|
||||
"*tax_rates.rules",
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
|
||||
@@ -19,9 +19,16 @@ export const AdminGetTaxRegionsParams = createFindParams({
|
||||
}).merge(
|
||||
z.object({
|
||||
id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
country_code: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
province_code: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
parent_id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
q: z.string().optional(),
|
||||
country_code: z
|
||||
.union([z.string(), z.array(z.string()), createOperatorMap()])
|
||||
.optional(),
|
||||
province_code: z
|
||||
.union([z.string(), z.array(z.string()), createOperatorMap()])
|
||||
.optional(),
|
||||
parent_id: z
|
||||
.union([z.string(), z.array(z.string()), createOperatorMap()])
|
||||
.optional(),
|
||||
created_by: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
created_at: createOperatorMap().optional(),
|
||||
updated_at: createOperatorMap().optional(),
|
||||
@@ -41,6 +48,9 @@ export const AdminCreateTaxRegion = z.object({
|
||||
rate: z.number().optional(),
|
||||
code: z.string().optional(),
|
||||
name: z.string(),
|
||||
is_combinable: z
|
||||
.union([z.literal("true"), z.literal("false")])
|
||||
.optional(),
|
||||
metadata: z.record(z.unknown()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
|
||||
Reference in new issue
Block a user