Skip to content

Commit

Permalink
minor fixes to region domain and api (#7042)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperkristensen committed Apr 9, 2024
1 parent f175cac commit 276278c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/admin-next/dashboard/src/lib/format-provider.ts
Expand Up @@ -13,6 +13,6 @@ export const formatProvider = (id: string) => {
name
.split("-")
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
.join(" ") + (type ? ` (${type})` : "")
.join(" ") + (type ? ` (${type.toUpperCase()})` : "")
)
}
Expand Up @@ -16,24 +16,24 @@ import { useForm, useWatch } from "react-hook-form"
import { useTranslation } from "react-i18next"
import * as zod from "zod"

import { RegionCountryDTO, PaymentProviderDTO } from "@medusajs/types"
import { PaymentProviderDTO, RegionCountryDTO } from "@medusajs/types"

import { Combobox } from "../../../../../components/common/combobox"
import { Form } from "../../../../../components/common/form"
import { SplitView } from "../../../../../components/layout/split-view"
import {
useRouteModal,
RouteFocusModal,
useRouteModal,
} from "../../../../../components/route-modal"
import { DataTable } from "../../../../../components/table/data-table"
import { useCreateRegion } from "../../../../../hooks/api/regions"
import { useDataTable } from "../../../../../hooks/use-data-table"
import { countries as staticCountries } from "../../../../../lib/countries"
import { CurrencyInfo } from "../../../../../lib/currencies"
import { formatProvider } from "../../../../../lib/format-provider"
import { useCountries } from "../../../common/hooks/use-countries"
import { useCountryTableColumns } from "../../../common/hooks/use-country-table-columns"
import { useCountryTableQuery } from "../../../common/hooks/use-country-table-query"
import { CurrencyInfo } from "../../../../../lib/currencies"
import { useCreateRegion } from "../../../../../hooks/api/regions"

type CreateRegionFormProps = {
currencies: CurrencyInfo[]
Expand Down Expand Up @@ -78,7 +78,7 @@ export const CreateRegionForm = ({

const { t } = useTranslation()

const { mutateAsync, isLoading } = useCreateRegion()
const { mutateAsync, isPending } = useCreateRegion()

const handleSubmit = form.handleSubmit(async (values) => {
await mutateAsync(
Expand Down Expand Up @@ -195,7 +195,7 @@ export const CreateRegionForm = ({
{t("actions.cancel")}
</Button>
</RouteFocusModal.Close>
<Button size="small" type="submit" isLoading={isLoading}>
<Button size="small" type="submit" isLoading={isPending}>
{t("actions.save")}
</Button>
</div>
Expand Down Expand Up @@ -322,7 +322,12 @@ export const CreateRegionForm = ({
</div>
)}
<div className="flex items-center justify-end">
<Button onClick={() => setOpen(true)} type="button">
<Button
variant="secondary"
size="small"
onClick={() => setOpen(true)}
type="button"
>
{t("regions.addCountries")}
</Button>
</div>
Expand Down
@@ -1,9 +1,10 @@
import { Outlet, useLoaderData, useParams } from "react-router-dom"

import { JsonViewSection } from "../../../components/common/json-view-section"
import { useRegion } from "../../../hooks/api/regions"
import { RegionCountrySection } from "./components/region-country-section"
import { RegionGeneralSection } from "./components/region-general-section"
import { regionLoader } from "./loader"
import { useRegion } from "../../../hooks/api/regions"

export const RegionDetail = () => {
const initialData = useLoaderData() as Awaited<
Expand All @@ -13,7 +14,7 @@ export const RegionDetail = () => {
const { id } = useParams()
const { region, isLoading, isError, error } = useRegion(
id!,
{ fields: "*payment_providers" },
{ fields: "*payment_providers,*countries" },
{
initialData,
}
Expand All @@ -32,6 +33,7 @@ export const RegionDetail = () => {
<div className="flex flex-col gap-y-2">
<RegionGeneralSection region={region} />
<RegionCountrySection region={region} />
<JsonViewSection data={region} />
<Outlet />
</div>
)
Expand Down
10 changes: 5 additions & 5 deletions packages/medusa/src/api-v2/admin/regions/[id]/route.ts
@@ -1,16 +1,16 @@
import {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "../../../../types/routing"
import {
deleteRegionsWorkflow,
updateRegionsWorkflow,
} from "@medusajs/core-flows"
import {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "../../../../types/routing"

import { UpdateRegionDTO } from "@medusajs/types"
import {
ContainerRegistrationKeys,
remoteQueryObjectFromString
remoteQueryObjectFromString,
} from "@medusajs/utils"

export const GET = async (
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/api-v2/admin/regions/middlewares.ts
@@ -1,12 +1,12 @@
import * as QueryConfig from "./query-config"

import { transformBody, transformQuery } from "../../../api/middlewares"
import {
AdminGetRegionsParams,
AdminGetRegionsRegionParams,
AdminPostRegionsRegionReq,
AdminPostRegionsReq,
} from "./validators"
import { transformBody, transformQuery } from "../../../api/middlewares"

import { MiddlewareRoute } from "../../../loaders/helpers/routing/types"
import { authenticate } from "../../../utils/authenticate-middleware"
Expand Down
6 changes: 1 addition & 5 deletions packages/medusa/src/api-v2/admin/regions/query-config.ts
Expand Up @@ -6,11 +6,7 @@ export const defaultAdminRegionFields = [
"updated_at",
"deleted_at",
"metadata",
"countries.id",
"countries.iso_2",
"countries.iso_3",
"countries.num_code",
"countries.name",
"*countries",
]

export const retrieveTransformQueryConfig = {
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/api-v2/admin/regions/validators.ts
Expand Up @@ -8,7 +8,7 @@ import {
IsString,
ValidateNested,
} from "class-validator"
import { extendedFindParamsMixin, FindParams } from "../../../types/common"
import { FindParams, extendedFindParamsMixin } from "../../../types/common"
import { OperatorMapValidator } from "../../../types/validators/operator-map"

export class AdminGetRegionsRegionParams extends FindParams {}
Expand Down

0 comments on commit 276278c

Please sign in to comment.