Skip to content

Commit

Permalink
Merge branch 'develop' into fix/refunds-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
riqwan authored Sep 3, 2024
2 parents 0f142f3 + c42d66f commit 5e6cca6
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 29 deletions.
13 changes: 10 additions & 3 deletions packages/admin-next/dashboard/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,6 @@
"create": "Create Claim",
"confirm": "Confirm Claim",
"confirmText": "You are about to confirm a Claim. This action cannot be undone.",
"cancel": "Cancel Claim",
"manage": "Manage Claim",
"outbound": "Outbound",
"outboundItemAdded": "{{itemsCount}}x added through claim",
Expand All @@ -983,6 +982,10 @@
"successToast": "Claim was successfully canceled."
}
},
"cancel": {
"title": "Cancel Claim",
"description": "Are you sure you want to cancel the claim?"
},
"tooltips": {
"onlyReturnShippingOptions": "This list will consist of only return shipping options."
},
Expand All @@ -1000,7 +1003,6 @@
"manage": "Manage Exchange",
"confirm": "Confirm Exchange",
"confirmText": "You are about to confirm an Exchange. This action cannot be undone.",
"cancel": "Cancel Exchange",
"outbound": "Outbound",
"outboundItemAdded": "{{itemsCount}}x added through exchange",
"outboundTotal": "Outbound total",
Expand All @@ -1013,6 +1015,10 @@
"successToast": "Exchange was successfully canceled."
}
},
"cancel": {
"title": "Cancel Exchange",
"description": "Are you sure you want to cancel the exchange?"
},
"tooltips": {
"onlyReturnShippingOptions": "This list will consist of only return shipping options."
},
Expand Down Expand Up @@ -1160,16 +1166,17 @@
},
"claim": {
"created": "Claim #{{claimId}} requested",
"canceled": "Claim #{{claimId}} canceled",
"itemsInbound": "{{count}} item to return",
"itemsOutbound": "{{count}} item to send"
},
"exchange": {
"created": "Exchange #{{exchangeId}} requested",
"canceled": "Exchange #{{exchangeId}} canceled",
"itemsInbound": "{{count}} item to return",
"itemsOutbound": "{{count}} item to send"
},
"edit": {
"requested": "Order edit #{{editId}} requested",
"requested": "Order edit #{{editId}} requested",
"confirmed": "Order edit #{{editId}} confirmed"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ export const ClaimCreateForm = ({
variant="secondary"
size="small"
>
{t("orders.claims.cancel")}
{t("orders.claims.cancel.title")}
</Button>
</RouteFocusModal.Close>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ export const ExchangeCreateForm = ({
variant="secondary"
size="small"
>
{t("orders.exchanges.cancel")}
{t("orders.exchanges.cancel.title")}
</Button>
</RouteFocusModal.Close>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const ActiveOrderClaimSection = ({

<div className="flex items-center justify-end gap-x-2 rounded-b-xl px-4 py-4">
<Button size="small" variant="secondary" onClick={onCancelClaim}>
{t("orders.claims.cancel")}
{t("orders.claims.cancel.title")}
</Button>

<Button size="small" variant="secondary" onClick={onContinueClaim}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const ActiveOrderExchangeSection = ({

<div className="flex items-center justify-end gap-x-2 rounded-b-xl px-4 py-4">
<Button size="small" variant="secondary" onClick={onCancelExchange}>
{t("orders.exchanges.cancel")}
{t("orders.exchanges.cancel.title")}
</Button>

<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import {
import { useTranslation } from "react-i18next"

import { AdminOrderLineItem } from "@medusajs/types"
import { useClaims } from "../../../../../hooks/api/claims"
import { useExchanges } from "../../../../../hooks/api/exchanges"
import { useCancelClaim, useClaims } from "../../../../../hooks/api/claims"
import {
useCancelExchange,
useExchanges,
} from "../../../../../hooks/api/exchanges"
import { useCancelReturn, useReturns } from "../../../../../hooks/api/returns"
import { useDate } from "../../../../../hooks/use-date"
import { getStylizedAmount } from "../../../../../lib/money-amount-helpers"
Expand Down Expand Up @@ -283,10 +286,15 @@ const useActivityItems = (order: AdminOrder): Activity[] => {
const claimReturn = returnMap.get(claim.return_id!)

items.push({
title: t("orders.activity.events.claim.created", {
claimId: claim.id.slice(-7),
}),
timestamp: claim.created_at,
title: t(
claim.canceled_at
? "orders.activity.events.claim.canceled"
: "orders.activity.events.claim.created",
{
claimId: claim.id.slice(-7),
}
),
timestamp: claim.canceled_at || claim.created_at,
itemsToSend: claim.additional_items,
itemsToReturn: claimReturn?.items,
itemsMap,
Expand All @@ -298,10 +306,15 @@ const useActivityItems = (order: AdminOrder): Activity[] => {
const exchangeReturn = returnMap.get(exchange.return_id!)

items.push({
title: t("orders.activity.events.exchange.created", {
exchangeId: exchange.id.slice(-7),
}),
timestamp: exchange.created_at,
title: t(
exchange.canceled_at
? "orders.activity.events.exchange.canceled"
: "orders.activity.events.exchange.created",
{
exchangeId: exchange.id.slice(-7),
}
),
timestamp: exchange.canceled_at || exchange.created_at,
itemsToSend: exchange.additional_items,
itemsToReturn: exchangeReturn?.items,
itemsMap,
Expand Down Expand Up @@ -428,7 +441,7 @@ const OrderActivityItem = ({
<Text
size="small"
leading="compact"
className="text-ui-fg-subtle"
className="text-ui-fg-subtle text-right"
>
{getRelativeDate(timestamp)}
</Text>
Expand Down Expand Up @@ -647,8 +660,28 @@ const ClaimBody = ({
claim: AdminClaim
claimReturn?: AdminReturn
}) => {
const prompt = usePrompt()
const { t } = useTranslation()

const isCanceled = !!claim.created_at

const { mutateAsync: cancelClaim } = useCancelClaim(claim.id, claim.order_id)

const onCancel = async () => {
const res = await prompt({
title: t("orders.claims.cancel.title"),
description: t("orders.claims.cancel.description"),
confirmText: t("actions.confirm"),
cancelText: t("actions.cancel"),
})

if (!res) {
return
}

await cancelClaim()
}

const outboundItems = (claim.additional_items || []).reduce(
(acc, item) => (acc + item.quantity) as number,
0
Expand Down Expand Up @@ -676,6 +709,17 @@ const ClaimBody = ({
})}
</Text>
)}

{!isCanceled && (
<Button
onClick={onCancel}
className="text-ui-fg-subtle h-auto px-0 leading-none hover:bg-transparent"
variant="transparent"
size="small"
>
{t("actions.cancel")}
</Button>
)}
</div>
)
}
Expand All @@ -687,8 +731,31 @@ const ExchangeBody = ({
exchange: AdminExchange
exchangeReturn?: AdminReturn
}) => {
const prompt = usePrompt()
const { t } = useTranslation()

const isCanceled = !!exchange.canceled_at

const { mutateAsync: cancelExchange } = useCancelExchange(
exchange.id,
exchange.order_id
)

const onCancel = async () => {
const res = await prompt({
title: t("orders.exchanges.cancel.title"),
description: t("orders.exchanges.cancel.description"),
confirmText: t("actions.confirm"),
cancelText: t("actions.cancel"),
})

if (!res) {
return
}

await cancelExchange()
}

const outboundItems = (exchange.additional_items || []).reduce(
(acc, item) => (acc + item.quantity) as number,
0
Expand Down Expand Up @@ -716,6 +783,17 @@ const ExchangeBody = ({
})}
</Text>
)}

{!isCanceled && (
<Button
onClick={onCancel}
className="text-ui-fg-subtle h-auto px-0 leading-none hover:bg-transparent"
variant="transparent"
size="small"
>
{t("actions.cancel")}
</Button>
)}
</div>
)
}
Expand Down
12 changes: 3 additions & 9 deletions packages/medusa/src/api/admin/price-lists/[id]/products/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { batchPriceListPricesWorkflow } from "@medusajs/core-flows"
import { HttpTypes, LinkMethodRequest } from "@medusajs/types"
import { HttpTypes } from "@medusajs/types"
import { MedusaError } from "@medusajs/utils"
import {
AuthenticatedMedusaRequest,
Expand All @@ -8,17 +8,11 @@ import {
import { fetchPriceList, fetchPriceListPriceIdsForProduct } from "../../helpers"

export const POST = async (
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
req: AuthenticatedMedusaRequest<HttpTypes.AdminLinkPriceListProducts>,
res: MedusaResponse<HttpTypes.AdminPriceListResponse>
) => {
const id = req.params.id
const { add, remove = [] } = req.validatedBody
if (add?.length) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Adding products directly to a price list is not supported, please use the /admin/price-lists/:id/prices/batch endpoint instead"
)
}
const { remove = [] } = req.validatedBody

if (!remove.length) {
throw new MedusaError(
Expand Down
5 changes: 3 additions & 2 deletions packages/medusa/src/api/admin/price-lists/middlewares.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { MiddlewareRoute } from "@medusajs/framework"
import { validateAndTransformBody } from "../../utils/validate-body"
import { validateAndTransformQuery } from "../../utils/validate-query"
import { createBatchBody, createLinkBody } from "../../utils/validators"
import { createBatchBody } from "../../utils/validators"
import * as QueryConfig from "./query-config"
import {
AdminCreatePriceList,
AdminCreatePriceListPrice,
AdminGetPriceListParams,
AdminGetPriceListPricesParams,
AdminGetPriceListsParams,
AdminRemoveProductsPriceList,
AdminUpdatePriceList,
AdminUpdatePriceListPrice,
} from "./validators"
Expand Down Expand Up @@ -60,7 +61,7 @@ export const adminPriceListsRoutesMiddlewares: MiddlewareRoute[] = [
method: ["POST"],
matcher: "/admin/price-lists/:id/products",
middlewares: [
validateAndTransformBody(createLinkBody()),
validateAndTransformBody(AdminRemoveProductsPriceList),
validateAndTransformQuery(
AdminGetPriceListParams,
QueryConfig.listPriceListQueryConfig
Expand Down
8 changes: 8 additions & 0 deletions packages/medusa/src/api/admin/price-lists/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,11 @@ export const AdminUpdatePriceList = z.object({
})

export type AdminUpdatePriceListType = z.infer<typeof AdminUpdatePriceList>

export const AdminRemoveProductsPriceList = z.object({
remove: z.array(z.string()).optional(),
})

export type AdminRemoveProductsPriceListType = z.infer<
typeof AdminRemoveProductsPriceList
>

0 comments on commit 5e6cca6

Please sign in to comment.