From aa0928d437e1953ed0f52ebd913b4e461c5e0573 Mon Sep 17 00:00:00 2001 From: Riqwan Thamir Date: Mon, 16 Sep 2024 22:50:41 +0200 Subject: [PATCH] feat(dashboard,types): added inbound shipping placeholder + shipping summary details (#9150) what: - shipping summary Screenshot 2024-09-16 at 18 05 37 - No Shipping options placeholder Screenshot 2024-09-16 at 18 06 11 --- .../components/inputs/combobox/combobox.tsx | 26 ++++++---- .../dashboard/src/i18n/translations/en.json | 17 ++++++- .../src/routes/orders/common/placeholders.tsx | 48 +++++++++++++++++++ .../claim-create-form/claim-create-form.tsx | 17 +++++-- .../claim-outbound-section.tsx | 2 + .../exchange-inbound-section.tsx | 15 ++++-- .../exchange-outbound-section.tsx | 2 + .../return-create-form/return-create-form.tsx | 12 +++++ .../order-summary-section.tsx | 32 +++++++++---- .../shipping-info-popover.tsx | 48 +++++++++++++++++++ packages/core/types/src/http/order/common.ts | 12 +++++ 11 files changed, 202 insertions(+), 29 deletions(-) create mode 100644 packages/admin/dashboard/src/routes/orders/common/placeholders.tsx create mode 100644 packages/admin/dashboard/src/routes/orders/order-detail/components/order-summary-section/shipping-info-popover.tsx diff --git a/packages/admin/dashboard/src/components/inputs/combobox/combobox.tsx b/packages/admin/dashboard/src/components/inputs/combobox/combobox.tsx index fdf65f9651..ca5a1e4231 100644 --- a/packages/admin/dashboard/src/components/inputs/combobox/combobox.tsx +++ b/packages/admin/dashboard/src/components/inputs/combobox/combobox.tsx @@ -20,6 +20,7 @@ import { ComponentPropsWithoutRef, ForwardedRef, Fragment, + ReactNode, useCallback, useDeferredValue, useImperativeHandle, @@ -50,6 +51,7 @@ interface ComboboxProps fetchNextPage?: () => void isFetchingNextPage?: boolean onCreateOption?: (value: string) => void + noResultsPlaceholder?: ReactNode } const ComboboxImpl = ( @@ -64,6 +66,7 @@ const ComboboxImpl = ( fetchNextPage, isFetchingNextPage, onCreateOption, + noResultsPlaceholder, ...inputProps }: ComboboxProps, ref: ForwardedRef @@ -182,7 +185,7 @@ const ComboboxImpl = ( setOpen(open) } - const hasValue = selectedValues.length > 0 + const hasValue = selectedValues?.length > 0 const showTag = hasValue && isArrayValue const showSelected = showTag && !searchValue && !open @@ -321,13 +324,20 @@ const ComboboxImpl = (
)} - {!results.length && ( -
- - {t("general.noResultsTitle")} - -
- )} + {!results.length && + (noResultsPlaceholder && !searchValue?.length ? ( + noResultsPlaceholder + ) : ( +
+ + {t("general.noResultsTitle")} + +
+ ))} {!results.length && onCreateOption && ( diff --git a/packages/admin/dashboard/src/i18n/translations/en.json b/packages/admin/dashboard/src/i18n/translations/en.json index 3030c48a2e..9338e9d574 100644 --- a/packages/admin/dashboard/src/i18n/translations/en.json +++ b/packages/admin/dashboard/src/i18n/translations/en.json @@ -835,6 +835,9 @@ }, "orders": { "domain": "Orders", + "claim": "Claim", + "exchange": "Exchange", + "return": "Return", "cancelWarning": "You are about to cancel the order {{id}}. This action cannot be undone.", "onDateFromSalesChannel": "{{date}} from {{salesChannel}}", "list": { @@ -929,7 +932,7 @@ "noteHint": "You can type freely if you want to specify something.", "location": "Location", "locationHint": "Choose which location you want to return the items to.", - "inboundShipping": "Inbound shipping", + "inboundShipping": "Return shipping", "inboundShippingHint": "Choose which method you want to use.", "returnableQuantityLabel": "Returnable quantity", "refundableAmountLabel": "Refundable amount", @@ -944,6 +947,16 @@ "title": "Cancel Return", "description": "Are you sure you want to cancel the return request?" }, + "placeholders": { + "noReturnShippingOptions": { + "title": "No return shipping options found", + "hint": "No return shipping options were created for the location. You can create one at Location & Shipping." + }, + "outboundShippingOptions": { + "title": "No outbound shipping options found", + "hint": "No outbound shipping options were created for the location. You can create one at Location & Shipping." + } + }, "receive": { "action": "Receive items", "receiveItems": "{{ returnType }} {{ id }}", @@ -2561,6 +2574,8 @@ "totalExclTax": "Total excl. tax", "subtotal": "Subtotal", "shipping": "Shipping", + "outboundShipping": "Outbound Shipping", + "returnShipping": "Return Shipping", "tax": "Tax", "created": "Created", "key": "Key", diff --git a/packages/admin/dashboard/src/routes/orders/common/placeholders.tsx b/packages/admin/dashboard/src/routes/orders/common/placeholders.tsx new file mode 100644 index 0000000000..66aa6a95d1 --- /dev/null +++ b/packages/admin/dashboard/src/routes/orders/common/placeholders.tsx @@ -0,0 +1,48 @@ +import { Trans, useTranslation } from "react-i18next" +import { Link } from "react-router-dom" + +export const ReturnShippingPlaceholder = () => { + const { t } = useTranslation() + + return ( +
+ + {t("orders.returns.placeholders.noReturnShippingOptions.title")} + + + + + ), + }} + /> + +
+ ) +} + +export const OutboundShippingPlaceholder = () => { + const { t } = useTranslation() + + return ( +
+ + {t("orders.returns.placeholders.outboundShippingOptions.title")} + + + + + ), + }} + /> + +
+ ) +} diff --git a/packages/admin/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx b/packages/admin/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx index 2898372b81..eceb025184 100644 --- a/packages/admin/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx +++ b/packages/admin/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx @@ -52,6 +52,7 @@ import { import { useUpdateReturn } from "../../../../../hooks/api/returns.tsx" import { sdk } from "../../../../../lib/client" import { currencies } from "../../../../../lib/data/currencies" +import { ReturnShippingPlaceholder } from "../../../common/placeholders.tsx" import { ClaimOutboundSection } from "./claim-outbound-section" import { ItemPlaceholder } from "./item-placeholder" @@ -715,12 +716,15 @@ export const ClaimCreateForm = ({ {/*INBOUND SHIPPING*/}
- + {t("orders.returns.inboundShipping")} + + ({t("fields.optional")}) + @@ -748,6 +752,9 @@ export const ClaimCreateForm = ({ value: so.id, }))} disabled={!locationId} + noResultsPlaceholder={ + + } /> diff --git a/packages/admin/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-outbound-section.tsx b/packages/admin/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-outbound-section.tsx index 8be81a5a63..193a85d051 100644 --- a/packages/admin/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-outbound-section.tsx +++ b/packages/admin/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-outbound-section.tsx @@ -26,6 +26,7 @@ import { } from "../../../../../hooks/api/claims" import { useShippingOptions } from "../../../../../hooks/api/shipping-options" import { sdk } from "../../../../../lib/client" +import { OutboundShippingPlaceholder } from "../../../common/placeholders" import { AddClaimOutboundItemsTable } from "../add-claim-outbound-items-table" import { ClaimOutboundItem } from "./claim-outbound-item" import { ItemPlaceholder } from "./item-placeholder" @@ -405,6 +406,7 @@ export const ClaimOutboundSection = ({ value: so.id, }))} disabled={!shipping_options.length} + noResultsPlaceholder={} /> diff --git a/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-inbound-section.tsx b/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-inbound-section.tsx index a28b96b4a7..3c4bcc88dc 100644 --- a/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-inbound-section.tsx +++ b/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-inbound-section.tsx @@ -28,6 +28,7 @@ import { } from "../../../../../hooks/api/exchanges" import { useUpdateReturn } from "../../../../../hooks/api/returns" import { sdk } from "../../../../../lib/client" +import { ReturnShippingPlaceholder } from "../../../common/placeholders" import { ItemPlaceholder } from "../../../order-create-claim/components/claim-create-form/item-placeholder" import { AddExchangeInboundItemsTable } from "../add-exchange-inbound-items-table" import { ExchangeInboundItem } from "./exchange-inbound-item" @@ -480,12 +481,15 @@ export const ExchangeInboundSection = ({ {/*INBOUND SHIPPING*/}
- + {t("orders.returns.inboundShipping")} + + ({t("fields.optional")}) + @@ -512,6 +516,7 @@ export const ExchangeInboundSection = ({ value: so.id, }))} disabled={!locationId} + noResultsPlaceholder={} /> diff --git a/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx b/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx index 36ff958296..24ba5aaef8 100644 --- a/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx +++ b/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx @@ -25,6 +25,7 @@ import { } from "../../../../../hooks/api/exchanges" import { useShippingOptions } from "../../../../../hooks/api/shipping-options" import { sdk } from "../../../../../lib/client" +import { OutboundShippingPlaceholder } from "../../../common/placeholders" import { ItemPlaceholder } from "../../../order-create-claim/components/claim-create-form/item-placeholder" import { AddExchangeOutboundItemsTable } from "../add-exchange-outbound-items-table" import { ExchangeOutboundItem } from "./exchange-outbound-item" @@ -402,6 +403,7 @@ export const ExchangeOutboundSection = ({ } value={value ?? undefined} onChange={(val) => { onChange(val) diff --git a/packages/admin/dashboard/src/routes/orders/order-create-return/components/return-create-form/return-create-form.tsx b/packages/admin/dashboard/src/routes/orders/order-create-return/components/return-create-form/return-create-form.tsx index e059eef8a0..496379b8b2 100644 --- a/packages/admin/dashboard/src/routes/orders/order-create-return/components/return-create-form/return-create-form.tsx +++ b/packages/admin/dashboard/src/routes/orders/order-create-return/components/return-create-form/return-create-form.tsx @@ -46,6 +46,7 @@ import { useStockLocations } from "../../../../../hooks/api/stock-locations" import { sdk } from "../../../../../lib/client" import { currencies } from "../../../../../lib/data/currencies" import { getStylizedAmount } from "../../../../../lib/money-amount-helpers" +import { ReturnShippingPlaceholder } from "../../../common/placeholders" import { AddReturnItemsTable } from "../add-return-items-table" import { ReturnItem } from "./return-item" import { ReturnCreateSchema, ReturnCreateSchemaType } from "./schema" @@ -549,7 +550,15 @@ export const ReturnCreateForm = ({
{t("orders.returns.inboundShipping")} + + ({t("fields.optional")}) + + {t("orders.returns.inboundShippingHint")} @@ -588,6 +597,9 @@ export const ReturnCreateForm = ({ value: so.id, }))} disabled={!locationId} + noResultsPlaceholder={ + + } /> diff --git a/packages/admin/dashboard/src/routes/orders/order-detail/components/order-summary-section/order-summary-section.tsx b/packages/admin/dashboard/src/routes/orders/order-detail/components/order-summary-section/order-summary-section.tsx index 4eb560ff0f..99642edf5f 100644 --- a/packages/admin/dashboard/src/routes/orders/order-detail/components/order-summary-section/order-summary-section.tsx +++ b/packages/admin/dashboard/src/routes/orders/order-detail/components/order-summary-section/order-summary-section.tsx @@ -1,4 +1,4 @@ -import { useMemo, useState } from "react" +import { ReactNode, useMemo, useState } from "react" import { useTranslation } from "react-i18next" import { useNavigate } from "react-router-dom" @@ -54,6 +54,7 @@ import { getTotalCaptured } from "../../../../../lib/payment" import { getReturnableQuantity } from "../../../../../lib/rma" import { CopyPaymentLink } from "../copy-payment-link/copy-payment-link" import ReturnInfoPopover from "./return-info-popover" +import ShippingInfoPopover from "./shipping-info-popover" type OrderSummarySectionProps = { order: AdminOrder @@ -523,14 +524,16 @@ const Cost = ({ label, value, secondaryValue, + tooltip, }: { label: string value: string | number secondaryValue: string + tooltip?: ReactNode }) => (
- {label} + {label} {tooltip}
@@ -568,14 +571,23 @@ const CostBreakdown = ({ order }: { order: AdminOrder }) => { .sort((m1, m2) => (m1.created_at as string).localeCompare(m2.created_at as string) ) - .map((sm, i) => ( - - ))} + .map((sm, i) => { + return ( +
+ } + /> +
+ ) + })}
) } diff --git a/packages/admin/dashboard/src/routes/orders/order-detail/components/order-summary-section/shipping-info-popover.tsx b/packages/admin/dashboard/src/routes/orders/order-detail/components/order-summary-section/shipping-info-popover.tsx new file mode 100644 index 0000000000..4b0bdca85a --- /dev/null +++ b/packages/admin/dashboard/src/routes/orders/order-detail/components/order-summary-section/shipping-info-popover.tsx @@ -0,0 +1,48 @@ +import { InformationCircleSolid } from "@medusajs/icons" +import { AdminOrderShippingMethod } from "@medusajs/types" +import { Badge, Tooltip } from "@medusajs/ui" +import { useTranslation } from "react-i18next" + +type ShippingInfoPopoverProps = { + shippingMethod: AdminOrderShippingMethod +} + +function ShippingInfoPopover({ shippingMethod }: ShippingInfoPopoverProps) { + const { t } = useTranslation() + const shippingDetail = shippingMethod?.detail + + if (!shippingDetail) { + return + } + + let rmaType = t("orders.return") + let rmaId = shippingDetail.return_id + + if (shippingDetail.claim_id) { + rmaType = t("orders.claim") + rmaId = shippingDetail.claim_id + } + + if (shippingDetail.exchange_id) { + rmaType = t("orders.exchange") + rmaId = shippingDetail.exchange_id + } + + if (!rmaId) { + return + } + + return ( + + {rmaType}: #{rmaId.slice(-7)} + + } + > + + + ) +} + +export default ShippingInfoPopover diff --git a/packages/core/types/src/http/order/common.ts b/packages/core/types/src/http/order/common.ts index 161f36b710..a27deb4c93 100644 --- a/packages/core/types/src/http/order/common.ts +++ b/packages/core/types/src/http/order/common.ts @@ -105,6 +105,7 @@ export interface BaseOrderShippingMethod { original_subtotal: BigNumberValue original_tax_total: BigNumberValue total: BigNumberValue + detail?: BaseOrderShippingDetail subtotal: BigNumberValue tax_total: BigNumberValue discount_total: BigNumberValue @@ -176,6 +177,17 @@ export interface BaseOrderItemDetail { updated_at: Date } +export interface BaseOrderShippingDetail { + id: string + shipping_method_id: string + shipping_method: BaseOrderShippingMethod + claim_id: string + exchange_id: string + return_id: string + created_at: Date + updated_at: Date +} + export interface BaseOrderChange { id: string order_id: string