fix(dashboard): cleanup Payments section (#9520)

**What**
- fix content breaking
- use a shorter payment ID in the UI

---

FIXES CC-572
This commit is contained in:
Frane Polić authored and GitHub committed 2024-10-17 11:36:02 +00:00
1 parent 1d540af783
commit 2cba362537
5 files changed
+61 -15

No files matched your search

@@ -0,0 +1,30 @@
import { useTranslation } from "react-i18next"
import { useState } from "react"
import copy from "copy-to-clipboard"
import { clx, toast, Tooltip } from "@medusajs/ui"
type DisplayIdProps = {
id: string
className?: string
}
function DisplayId({ id, className }: DisplayIdProps) {
const { t } = useTranslation()
const [open, setOpen] = useState(false)
const onClick = () => {
copy(id)
toast.success(t("actions.idCopiedToClipboard"))
}
return (
<Tooltip maxWidth={260} content={id} open={open} onOpenChange={setOpen}>
<span onClick={onClick} className={clx("cursor-pointer", className)}>
#{id.slice(-7)}
</span>
</Tooltip>
)
}
export default DisplayId
@@ -0,0 +1 @@
export * from "./display-id"
@@ -98,6 +98,8 @@
"actions": { "actions": {
"save": "Save", "save": "Save",
"saveAsDraft": "Save as draft", "saveAsDraft": "Save as draft",
"copy": "Copy",
"copied": "Copied",
"duplicate": "Duplicate", "duplicate": "Duplicate",
"publish": "Publish", "publish": "Publish",
"create": "Create", "create": "Create",
@@ -117,6 +119,7 @@
"showMore": "Show more", "showMore": "Show more",
"continue": "Continue", "continue": "Continue",
"continueWithEmail": "Continue with Email", "continueWithEmail": "Continue with Email",
"idCopiedToClipboard": "ID copied to clipboard",
"addReason": "Add Reason", "addReason": "Add Reason",
"addNote": "Add Note", "addNote": "Add Note",
"reset": "Reset", "reset": "Reset",
@@ -902,9 +905,10 @@
}, },
"payment": { "payment": {
"title": "Payments", "title": "Payments",
"isReadyToBeCaptured": "Payment {{id}} is ready to be captured.", "isReadyToBeCaptured": "Payment <0/> is ready to be captured.",
"totalPaidByCustomer": "Total paid by customer", "totalPaidByCustomer": "Total paid by customer",
"capture": "Capture payment", "capture": "Capture payment",
"capture_short": "Capture",
"refund": "Refund", "refund": "Refund",
"markAsPaid": "Mark as paid", "markAsPaid": "Mark as paid",
"statusLabel": "Payment status", "statusLabel": "Payment status",
@@ -41,12 +41,12 @@ const CopyPaymentLink = React.forwardRef<any, CopyPaymentLinkProps>(
React.useEffect(() => { React.useEffect(() => {
if (done) { if (done) {
setText("Copied") setText(t("actions.copied"))
return return
} }
setTimeout(() => { setTimeout(() => {
setText("Copy") setText(t("actions.copy"))
}, 500) }, 500)
}, [done]) }, [done])
@@ -12,7 +12,7 @@ import {
usePrompt, usePrompt,
} from "@medusajs/ui" } from "@medusajs/ui"
import { format } from "date-fns" import { format } from "date-fns"
import { useTranslation } from "react-i18next" import { Trans, useTranslation } from "react-i18next"
import { ActionMenu } from "../../../../../components/common/action-menu" import { ActionMenu } from "../../../../../components/common/action-menu"
import { useCapturePayment } from "../../../../../hooks/api" import { useCapturePayment } from "../../../../../hooks/api"
import { formatCurrency } from "../../../../../lib/format-currency" import { formatCurrency } from "../../../../../lib/format-currency"
@@ -22,6 +22,7 @@ import {
} from "../../../../../lib/money-amount-helpers" } from "../../../../../lib/money-amount-helpers"
import { getOrderPaymentStatus } from "../../../../../lib/order-helpers" import { getOrderPaymentStatus } from "../../../../../lib/order-helpers"
import { getTotalCaptured, getTotalPending } from "../../../../../lib/payment" import { getTotalCaptured, getTotalPending } from "../../../../../lib/payment"
import DisplayId from "../../../../../components/common/display-id/display-id"
type OrderPaymentSectionProps = { type OrderPaymentSectionProps = {
order: HttpTypes.AdminOrder order: HttpTypes.AdminOrder
@@ -176,21 +177,20 @@ const Payment = ({
payment.captured_at ? ["Captured", "green"] : ["Pending", "orange"] payment.captured_at ? ["Captured", "green"] : ["Pending", "orange"]
) as [string, "green" | "orange"] ) as [string, "green" | "orange"]
const cleanId = payment.id.replace("pay_", "")
const showCapture = const showCapture =
payment.captured_at === null && payment.canceled_at === null payment.captured_at === null && payment.canceled_at === null
return ( return (
<div className="divide-y divide-dashed"> <div className="divide-y divide-dashed">
<div className="text-ui-fg-subtle grid grid-cols-[1fr_1fr_1fr_1fr_20px] items-center gap-x-4 px-6 py-4"> <div className="text-ui-fg-subtle grid grid-cols-[1fr_1fr_1fr_20px] items-center gap-x-4 px-6 py-4 sm:grid-cols-[1fr_1fr_1fr_1fr_20px]">
<div className="w-full overflow-hidden"> <div className="w-full min-w-[60px] overflow-hidden">
<Text <Text
size="small" size="small"
leading="compact" leading="compact"
weight="plus" weight="plus"
className="truncate" className="truncate"
> >
{cleanId} <DisplayId id={payment.id} />
</Text> </Text>
<Text size="small" leading="compact"> <Text size="small" leading="compact">
{format( {format(
@@ -199,7 +199,7 @@ const Payment = ({
)} )}
</Text> </Text>
</div> </div>
<div className="flex items-center justify-end"> <div className="hidden items-center justify-end sm:flex">
<Text size="small" leading="compact" className="capitalize"> <Text size="small" leading="compact" className="capitalize">
{payment.provider_id} {payment.provider_id}
</Text> </Text>
@@ -232,16 +232,27 @@ const Payment = ({
{showCapture && ( {showCapture && (
<div className="bg-ui-bg-subtle flex items-center justify-between px-6 py-4"> <div className="bg-ui-bg-subtle flex items-center justify-between px-6 py-4">
<div className="flex items-center gap-x-2"> <div className="flex items-center gap-x-2">
<ArrowDownRightMini className="text-ui-fg-muted" /> <ArrowDownRightMini className="text-ui-fg-muted shrink-0" />
<Text size="small" leading="compact"> <Text size="small" leading="compact">
{t("orders.payment.isReadyToBeCaptured", { <Trans
id: cleanId, i18nKey="orders.payment.isReadyToBeCaptured"
})} components={[<DisplayId id={payment.id} />]}
/>
</Text> </Text>
</div> </div>
<Button size="small" variant="secondary" onClick={handleCapture}> <Button
{t("orders.payment.capture")} className="shrink-0"
size="small"
variant="secondary"
onClick={handleCapture}
>
<span className="hidden sm:block">
{t("orders.payment.capture")}
</span>
<span className="sm:hidden">
{t("orders.payment.capture_short")}
</span>
</Button> </Button>
</div> </div>
)} )}