Skip to content

Commit

Permalink
Merge branch 'develop' into docs/router-page
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser committed Oct 14, 2024
2 parents beefd9a + b40fa63 commit c475bc9
Show file tree
Hide file tree
Showing 503 changed files with 233,772 additions and 229,902 deletions.
120 changes: 101 additions & 19 deletions integration-tests/modules/__tests__/cart/store/cart.workflows.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
addShippingMethodToWorkflow,
addShippingMethodToCartWorkflow,
addToCartWorkflow,
createCartWorkflow,
createPaymentCollectionForCartWorkflow,
Expand Down Expand Up @@ -1638,22 +1638,7 @@ medusaIntegrationTestRunner({
},
])

await addShippingMethodToWorkflow(appContainer).run({
input: {
options: [{ id: shippingOption.id }],
cart_id: cart.id,
},
})

await addShippingMethodToWorkflow(appContainer).run({
input: {
options: [{ id: shippingOption.id }],
cart_id: cart.id,
},
})

// should remove the previous shipping method
await addShippingMethodToWorkflow(appContainer).run({
await addShippingMethodToCartWorkflow(appContainer).run({
input: {
options: [{ id: shippingOption.id }],
cart_id: cart.id,
Expand Down Expand Up @@ -1707,7 +1692,7 @@ medusaIntegrationTestRunner({
},
])

const { errors } = await addShippingMethodToWorkflow(
const { errors } = await addShippingMethodToCartWorkflow(
appContainer
).run({
input: {
Expand All @@ -1729,7 +1714,7 @@ medusaIntegrationTestRunner({
})

it("should throw error when shipping option is not present in the db", async () => {
const { errors } = await addShippingMethodToWorkflow(
const { errors } = await addShippingMethodToCartWorkflow(
appContainer
).run({
input: {
Expand All @@ -1749,6 +1734,103 @@ medusaIntegrationTestRunner({
}),
])
})

it("should add shipping method with custom data", async () => {
const stockLocation = (
await api.post(
`/admin/stock-locations`,
{ name: "test location" },
adminHeaders
)
).data.stock_location

await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: stockLocation.id,
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: fulfillmentSet.id,
},
},
])

await api.post(
`/admin/stock-locations/${stockLocation.id}/fulfillment-providers`,
{ add: ["manual_test-provider"] },
adminHeaders
)

const shippingOption = await fulfillmentModule.createShippingOptions({
name: "Test shipping option",
service_zone_id: fulfillmentSet.service_zones[0].id,
shipping_profile_id: shippingProfile.id,
provider_id: "manual_test-provider",
price_type: "flat",
type: {
label: "Test type",
description: "Test description",
code: "test-code",
},
rules: [
{
operator: RuleOperator.EQ,
attribute: "is_return",
value: "false",
},
{
operator: RuleOperator.EQ,
attribute: "enabled_in_store",
value: "true",
},
],
})

await remoteLink.create([
{
[Modules.FULFILLMENT]: { shipping_option_id: shippingOption.id },
[Modules.PRICING]: { price_set_id: priceSet.id },
},
])

await addShippingMethodToCartWorkflow(appContainer).run({
input: {
options: [{ id: shippingOption.id, data: { test: "test" } }],
cart_id: cart.id,
},
})

cart = await cartModuleService.retrieveCart(cart.id, {
select: ["id"],
relations: ["shipping_methods"],
})

expect(cart).toEqual(
expect.objectContaining({
id: cart.id,
shipping_methods: [
{
id: expect.any(String),
cart_id: cart.id,
description: null,
amount: 3000,
raw_amount: {
value: "3000",
precision: 20,
},
metadata: null,
is_tax_inclusive: true,
name: "Test shipping option",
data: { test: "test" },
shipping_option_id: shippingOption.id,
deleted_at: null,
updated_at: expect.any(Date),
created_at: expect.any(Date),
},
],
})
)
})
})

describe("listShippingOptionsForCartWorkflow", () => {
Expand Down
1 change: 1 addition & 0 deletions packages/admin/dashboard/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,7 @@
"title": "Status"
},
"method": {
"label": "Method",
"code": {
"title": "Promotion code",
"description": "Customers must enter this code at checkout"
Expand Down
1 change: 0 additions & 1 deletion packages/admin/dashboard/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
:root {
@apply bg-ui-bg-subtle text-ui-fg-base antialiased;
text-rendering: optimizeLegibility;
color-scheme: light dark;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,20 @@ export const RouteMap: RouteObject[] = [
"../../routes/tax-regions/tax-region-tax-rate-edit"
),
},
{
path: "overrides/create",
lazy: () =>
import(
"../../routes/tax-regions/tax-region-tax-override-create"
),
},
{
path: "overrides/:tax_rate_id/edit",
lazy: () =>
import(
"../../routes/tax-regions/tax-region-tax-override-edit"
),
},
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const ThemeProvider = ({ children }: PropsWithChildren) => {

html.classList.remove(value === "light" ? "dark" : "light")
html.classList.add(value)
// Ensures that native elements respect the theme, e.g. the scrollbar.
html.style.colorScheme = value

/**
* Re-enable transitions after the theme has been set,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,53 @@
import { HttpTypes } from "@medusajs/types"
import { useMemo } from "react"
import { useTranslation } from "react-i18next"
import {
createDataGridHelper,
DataGrid,
} from "../../../../components/data-grid"
import { createDataGridPriceColumns } from "../../../../components/data-grid/helpers/create-data-grid-price-columns"

const columnHelper = createDataGridHelper()

export const useShippingOptionPriceColumns = ({
name,
currencies = [],
regions = [],
pricePreferences = [],
}: {
name: string
currencies?: string[]
regions?: HttpTypes.AdminRegion[]
pricePreferences?: HttpTypes.AdminPricePreference[]
}) => {
const { t } = useTranslation()

return useMemo(() => {
return createDataGridPriceColumns({
currencies,
regions,
pricePreferences,
getFieldName: (context, value) => {
if (context.column.id.startsWith("currency_prices")) {
return `currency_prices.${value}`
}
return [
columnHelper.column({
id: "name",
header: t("fields.name"),
cell: (context) => {
return (
<DataGrid.ReadonlyCell context={context}>
{name}
</DataGrid.ReadonlyCell>
)
},
}),
...createDataGridPriceColumns({
currencies,
regions,
pricePreferences,
getFieldName: (context, value) => {
if (context.column.id?.startsWith("currency_prices")) {
return `currency_prices.${value}`
}

return `region_prices.${value}`
},
t,
})
}, [t, currencies, regions, pricePreferences])
return `region_prices.${value}`
},
t,
}),
]
}, [t, currencies, regions, pricePreferences, name])
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export function EditShippingOptionsPricingForm({
const { setCloseOnEscape } = useRouteModal()

const columns = useShippingOptionPriceColumns({
name: shippingOption.name,
currencies,
regions,
pricePreferences,
Expand All @@ -129,7 +130,9 @@ export function EditShippingOptionsPricingForm({
return undefined
}

const currencyExists = currencies.some(currencyCode => currencyCode.toLowerCase() == code.toLowerCase())
const currencyExists = currencies.some(
(currencyCode) => currencyCode.toLowerCase() == code.toLowerCase()
)
if (!currencyExists) {
return undefined
}
Expand Down Expand Up @@ -162,8 +165,8 @@ export function EditShippingOptionsPricingForm({

// Check if the region_id exists in the regions array to avoid
// sending updates of region prices where the region has been
// deleted
const regionExists = regions?.some(region => region.id === region_id)
// deleted
const regionExists = regions?.some((region) => region.id === region_id)
if (!regionExists) {
return undefined
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AdminOrder } from "@medusajs/types"
import { Container, Heading } from "@medusajs/ui"
import { useTranslation } from "react-i18next"
import { OrderNoteForm } from "./order-note-form"
import { OrderTimeline } from "./order-timeline"

type OrderActivityProps = {
Expand All @@ -17,7 +16,8 @@ export const OrderActivitySection = ({ order }: OrderActivityProps) => {
<div className="flex items-center justify-between">
<Heading level="h2">{t("orders.activity.header")}</Heading>
</div>
<OrderNoteForm order={order} />
{/* TODO: Re-add when we have support for notes */}
{/* <OrderNoteForm order={order} /> */}
</div>
<OrderTimeline order={order} />
</Container>
Expand Down
Loading

0 comments on commit c475bc9

Please sign in to comment.