fix(dashboard, fulfilment): fulfilment providers enabled check (#9415)

**What**
- hide disabled fulfilment providers on the admin
- check if the fulfilment provider has an identifier when loading providers

---

FIXES CC-549
This commit is contained in:
Frane Polić
2024-10-02 16:48:40 +02:00
committed by GitHub
parent b39ba45b81
commit ab7e71a055
7 changed files with 23 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ function LocationsFulfillmentProvidersSection({
const { fulfillment_providers } = useFulfillmentProviders({
stock_location_id: location.id,
fields: "id",
is_enabled: true,
})
return (

View File

@@ -69,7 +69,7 @@ export const LocationEditFulfillmentProvidersForm = ({
const { fulfillment_providers, count, isLoading, isError, error } =
useFulfillmentProviders(
{ ...searchParams },
{ ...searchParams, is_enabled: true },
{ placeholderData: keepPreviousData }
)

View File

@@ -6,12 +6,10 @@ import { LocationEditFulfillmentProvidersForm } from "./components/edit-fulfillm
export const LocationFulfillmentProviders = () => {
const { location_id } = useParams()
const { stock_location, isPending, isError, error } = useStockLocation(
location_id!,
{ fields: "id,*fulfillment_providers" }
)
const { stock_location, isPending, isFetching, isError, error } =
useStockLocation(location_id!, { fields: "id,*fulfillment_providers" })
const ready = !isPending && !!stock_location
const ready = !isPending && !isFetching && !!stock_location
if (isError) {
throw error

View File

@@ -10,7 +10,9 @@ export const RegionCreate = () => {
const storeCurrencies = (store?.supported_currencies ?? []).map(
(c) => currencies[c.currency_code.toUpperCase()]
)
const { payment_providers: paymentProviders = [] } = usePaymentProviders()
const { payment_providers: paymentProviders = [] } = usePaymentProviders({
is_enabled: true,
})
if (isError) {
throw error

View File

@@ -50,6 +50,7 @@ export const RegionEdit = () => {
)
const { payment_providers: paymentProviders = [] } = usePaymentProviders({
limit: 999,
is_enabled: true,
})
if (isRegionError) {

View File

@@ -33,6 +33,12 @@ export default class FulfillmentProviderService extends ModulesSdkUtils.MedusaIn
providerClass: Constructor<IFulfillmentProvider>,
optionName?: string
) {
if (!(providerClass as any).identifier) {
throw new MedusaError(
MedusaError.Types.INVALID_ARGUMENT,
`Trying to register a fulfillment provider without an identifier.`
)
}
return `${(providerClass as any).identifier}_${optionName}`
}

View File

@@ -6,6 +6,7 @@ import {
ModulesSdkTypes,
} from "@medusajs/framework/types"
import { Lifetime, asFunction, asValue } from "awilix"
import { MedusaError } from "@medusajs/utils"
import { PaymentProviderService } from "@services"
import * as providers from "../providers"
@@ -13,6 +14,13 @@ import * as providers from "../providers"
const PROVIDER_REGISTRATION_KEY = "payment_providers"
const registrationFn = async (klass, container, pluginOptions) => {
if (!klass?.PROVIDER) {
throw new MedusaError(
MedusaError.Types.INVALID_ARGUMENT,
`Trying to register a payment provider without a provider identifier.`
)
}
const key = `pp_${klass.PROVIDER}_${pluginOptions.id}`
container.register({