Skip to content

Commit

Permalink
Merge branch 'develop' into feat/dml-float-datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage authored Dec 11, 2024
2 parents 66894c7 + 91cd9aa commit c40d4b8
Show file tree
Hide file tree
Showing 19 changed files with 479 additions and 470 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-seas-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/dashboard": patch
---

fix(dashboard): Prevent fulfillment provider modal from rerendering before form submission is complete
4 changes: 2 additions & 2 deletions packages/admin/dashboard/src/hooks/api/stock-locations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ export const useUpdateStockLocationFulfillmentProviders = (
>
) => {
return useMutation({
mutationFn: (payload) =>
sdk.admin.stockLocation.updateFulfillmentProviders(id, payload),
mutationFn: async (payload) =>
await sdk.admin.stockLocation.updateFulfillmentProviders(id, payload),
onSuccess: async (data, variables, context) => {
await queryClient.invalidateQueries({
queryKey: stockLocationsQueryKeys.details(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { HttpTypes } from "@medusajs/types"
import { Button, Checkbox, toast } from "@medusajs/ui"
import { keepPreviousData } from "@tanstack/react-query"
import { RowSelectionState, createColumnHelper } from "@tanstack/react-table"
import { useEffect, useMemo, useState } from "react"
import {
RowSelectionState,
Updater,
createColumnHelper,
} from "@tanstack/react-table"
import { useMemo, useState } from "react"
import { useTranslation } from "react-i18next"
import * as zod from "zod"

Expand All @@ -13,6 +17,7 @@ import {
useRouteModal,
} from "../../../../../components/modals"
import { DataTable } from "../../../../../components/table/data-table"
import { KeyboundForm } from "../../../../../components/utilities/keybound-form"
import { useFulfillmentProviders } from "../../../../../hooks/api/fulfillment-providers"
import { useUpdateStockLocationFulfillmentProviders } from "../../../../../hooks/api/stock-locations"
import { useFulfillmentProviderTableColumns } from "../../../../../hooks/table/columns/use-fulfillment-provider-table-columns"
Expand Down Expand Up @@ -55,13 +60,16 @@ export const LocationEditFulfillmentProvidersForm = ({
const [rowSelection, setRowSelection] =
useState<RowSelectionState>(initialState)

useEffect(() => {
const ids = Object.keys(rowSelection)
setValue("fulfillment_providers", ids, {
const handleRowSelectionChange = (updater: Updater<RowSelectionState>) => {
const ids = typeof updater === "function" ? updater(rowSelection) : updater

setValue("fulfillment_providers", Object.keys(ids), {
shouldDirty: true,
shouldTouch: true,
})
}, [rowSelection, setValue])

setRowSelection(ids)
}

const { searchParams, raw } = useFulfillmentProvidersTableQuery({
pageSize: PAGE_SIZE,
Expand All @@ -84,7 +92,7 @@ export const LocationEditFulfillmentProvidersForm = ({
enableRowSelection: true,
rowSelection: {
state: rowSelection,
updater: setRowSelection,
updater: handleRowSelectionChange,
},
getRowId: (row) => row.id,
pageSize: PAGE_SIZE,
Expand All @@ -104,9 +112,9 @@ export const LocationEditFulfillmentProvidersForm = ({
remove: originalIds?.filter((i) => !arr.includes(i)),
},
{
onSuccess: () => {
onSuccess: ({ stock_location }) => {
toast.success(t("stockLocations.fulfillmentProviders.successToast"))
handleSuccess(`/settings/locations/${location.id}`)
handleSuccess(`/settings/locations/${stock_location.id}`)
},
onError: (e) => {
toast.error(e.message)
Expand All @@ -121,8 +129,9 @@ export const LocationEditFulfillmentProvidersForm = ({

return (
<RouteFocusModal.Form form={form}>
<div className="flex h-full flex-col overflow-hidden">
<RouteFocusModal.Body>
<KeyboundForm onSubmit={handleSubmit} className="flex size-full flex-col">
<RouteFocusModal.Header />
<RouteFocusModal.Body className="flex flex-1 flex-col overflow-auto">
<DataTable
table={table}
columns={columns}
Expand All @@ -141,17 +150,17 @@ export const LocationEditFulfillmentProvidersForm = ({
<RouteFocusModal.Footer>
<div className="flex items-center justify-end gap-x-2">
<RouteFocusModal.Close asChild>
<Button size="small" variant="secondary">
<Button size="small" variant="secondary" type="button">
{t("actions.cancel")}
</Button>
</RouteFocusModal.Close>

<Button size="small" isLoading={isMutating} onClick={handleSubmit}>
<Button size="small" isLoading={isMutating} type="submit">
{t("actions.save")}
</Button>
</div>
</RouteFocusModal.Footer>
</div>
</KeyboundForm>
</RouteFocusModal.Form>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { LocationEditFulfillmentProvidersForm } from "./components/edit-fulfillm

export const LocationFulfillmentProviders = () => {
const { location_id } = useParams()
const { stock_location, isPending, isFetching, isError, error } =
useStockLocation(location_id!, { fields: "id,*fulfillment_providers" })
const { stock_location, isPending, isError, error } = useStockLocation(
location_id!,
{ fields: "id,*fulfillment_providers" }
)

const ready = !isPending && !isFetching && !!stock_location
const ready = !isPending && !!stock_location

if (isError) {
throw error
Expand Down
2 changes: 1 addition & 1 deletion packages/core/types/src/notification/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface Attachment {
*/
content_type?: string
/**
* The disposition of the attachment, e.g., "inline" or "attachment".
* The disposition of the attachment, For example, "inline" or "attachment".
*/
disposition?: string
/**
Expand Down
12 changes: 5 additions & 7 deletions packages/core/utils/src/fulfillment/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
*
* #### Example
*
* ```ts
* ```ts title="src/modules/my-fulfillment/service.ts"
* import { AbstractFulfillmentProviderService } from "@medusajs/framework/utils"
* import { Logger } from "@medusajs/framework/types"
*
Expand Down Expand Up @@ -56,13 +56,11 @@ export class AbstractFulfillmentProviderService
implements IFulfillmentProvider
{
/**
* The `identifier` property holds a unique identifier of the fulfillment module provider.
* Each fulfillment provider has a unique identifier defined in its class. The provider's ID
* will be stored as `fp_{identifier}_{id}`, where `{id}` is the provider's `id`
* property in the `medusa-config.ts`.
*
* You can use the kebab-case name of the provider as its value.
*
* For example:
*
* ```ts
* @example
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* static identifier = "my-fulfillment"
*
Expand Down
9 changes: 7 additions & 2 deletions packages/core/utils/src/payment/abstract-payment-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
export abstract class AbstractPaymentProvider<TConfig = Record<string, unknown>>
implements IPaymentProvider
{
/**
* @ignore
*/
protected readonly container: Record<string, unknown>
/**
* This method validates the options of the provider set in `medusa-config.ts`.
Expand Down Expand Up @@ -44,7 +47,7 @@ export abstract class AbstractPaymentProvider<TConfig = Record<string, unknown>>
* The provider can also access the module's options as a second parameter.
*
* @param {Record<string, unknown>} cradle - The module's container cradle used to resolve resources.
* @param {Record<string, unknown>} config - The options passed to the payment module provider.
* @param {Record<string, unknown>} config - The options passed to the Payment Module provider.
*
* @example
* ```ts
Expand Down Expand Up @@ -93,6 +96,9 @@ export abstract class AbstractPaymentProvider<TConfig = Record<string, unknown>>
*/
protected constructor(
cradle: Record<string, unknown>,
/**
* @ignore
*/
protected readonly config: TConfig = {} as TConfig // eslint-disable-next-line @typescript-eslint/no-empty-function
) {
this.container = cradle
Expand Down Expand Up @@ -122,7 +128,6 @@ export abstract class AbstractPaymentProvider<TConfig = Record<string, unknown>>
* static identifier = "my-payment"
* // ...
* }
* ```
*/
public static identifier: string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,33 @@ class MyAuthProviderService extends AbstractAuthModuleProvider {
export default MyAuthProviderService
```

### constructor
### identifier

Every auth provider must have an `identifier` static property. The provider's ID
will be stored as `au_{identifier}_{id}`, where `{id}` is the provider's `id`
property in the `medusa-config.ts`.

#### Example

```ts
class MyAuthProviderService extends AbstractAuthModuleProvider {
static identifier = "my-auth"
// ...
}
```

### DISPLAY\_NAME

This property indicates the name used when displaying the provider on a frontend application.

#### Example

```ts
class MyAuthProviderService extends AbstractAuthModuleProvider {
static DISPLAY_NAME = "My Auth"
// ...
}
```

### validateOptions

Expand Down Expand Up @@ -441,17 +467,18 @@ This exports the module's definition, indicating that the `MyAuthProviderService
To use your Auth Module Provider, add it to the `providers` array of the Auth Module in `medusa-config.ts`:

```ts title="medusa-config.ts"
import { Modules } from "@medusajs/framework/utils"

// ...

module.exports = defineConfig({
// ...
modules: [
{
resolve: "@medusajs/medusa/auth",
options: {
providers: [
// default provider
{
resolve: "@medusajs/medusa/auth-emailpass",
id: "emailpass",
},
{
resolve: "./src/modules/my-auth",
id: "my-auth",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,20 @@ class MyFileProviderService extends AbstractFileProviderService {
export default MyFileProviderService
```

### constructor
### identifier

Each file provider has a unique ID used to identify it. The provider's ID
will be stored as `fs_{identifier}_{id}`, where `{id}` is the provider's `id`
property in the `medusa-config.ts`.

#### Example

```ts
class MyFileProviderService extends AbstractFileProviderService {
static identifier = "my-file"
// ...
}
```

### validateOptions

Expand Down Expand Up @@ -229,17 +242,18 @@ The File Module accepts one provider only.
</Note>

```ts title="medusa-config.ts"
import { Modules } from "@medusajs/framework/utils"

// ...

module.exports = defineConfig({
// ...
modules: [
{
resolve: "@medusajs/medusa/file",
options: {
providers: [
// default provider
{
resolve: "@medusajs/medusa/file-local",
id: "local",
},
{
resolve: "./src/modules/my-file",
id: "my-file",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ If you're creating a client or establishing a connection with a third-party serv

#### Example

```ts
```ts title="src/modules/my-fulfillment/service.ts"
import { AbstractFulfillmentProviderService } from "@medusajs/framework/utils"
import { Logger } from "@medusajs/framework/types"

Expand Down Expand Up @@ -77,7 +77,21 @@ class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
export default MyFulfillmentProviderService
```

### constructor
### identifier

Each fulfillment provider has a unique identifier defined in its class. The provider's ID
will be stored as `fp_{identifier}_{id}`, where `{id}` is the provider's `id`
property in the `medusa-config.ts`.

#### Example

```ts
class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
static identifier = "my-fulfillment"

// ...
}
```

### getFulfillmentOptions

Expand Down Expand Up @@ -226,7 +240,7 @@ class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;number&#62;","optional":false,"defaultValue":"","description":"The calculated price","expandable":false,"children":[{"name":"number","type":"`number`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="calculatePrice"/>
<TypeList types={[{"name":"Promise","type":"Promise&#60;CalculatedShippingOptionPrice&#62;","optional":false,"defaultValue":"","description":"The calculated price","expandable":false,"children":[{"name":"CalculatedShippingOptionPrice","type":"`CalculatedShippingOptionPrice`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="calculatePrice"/>

### createFulfillment

Expand Down Expand Up @@ -473,17 +487,18 @@ This exports the module's definition, indicating that the `MyFulfillmentProvider
To use your Fulfillment Module Provider, add it to the `providers` array of the Fulfillment Module in `medusa-config.ts`:

```ts title="medusa-config.ts"
import { Modules } from "@medusajs/framework/utils"

// ...

module.exports = defineConfig({
// ...
modules: [
{
resolve: "@medusajs/medusa/fulfillment",
options: {
providers: [
// default provider
{
resolve: "@medusajs/medusa/fulfillment-manual",
id: "manual",
},
{
resolve: "./src/modules/my-fulfillment",
id: "my-fulfillment",
Expand Down
Loading

0 comments on commit c40d4b8

Please sign in to comment.