From c72b4847b9ae93643b929dc7334d5aa49ae473b0 Mon Sep 17 00:00:00 2001 From: Riqwan Thamir Date: Wed, 28 Aug 2024 10:59:36 +0200 Subject: [PATCH 1/5] fix(dashboard,js-sdk): fixes from rma flows testing (#8826) --- .../dashboard/src/i18n/translations/en.json | 19 ++- .../claim-create-form/claim-create-form.tsx | 21 ++- .../order-edit-create-form.tsx | 26 +++- .../exchange-create-form.tsx | 21 ++- .../return-create-form/return-create-form.tsx | 20 ++- .../active-order-claim-section.tsx | 2 +- .../active-order-exchange-section.tsx | 2 +- .../active-order-return-section.tsx | 2 +- .../copy-payment-link/copy-payment-link.tsx | 2 +- .../order-activity-section/activity-items.tsx | 136 ++++++++++++++++++ .../order-activity-section/order-timeline.tsx | 64 ++++++++- .../order-summary-section.tsx | 31 +++- .../orders/order-detail/order-detail.tsx | 16 +++ packages/core/js-sdk/src/admin/order.ts | 1 + .../types/src/http/order/admin/entities.ts | 2 + 15 files changed, 335 insertions(+), 30 deletions(-) create mode 100644 packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-activity-section/activity-items.tsx diff --git a/packages/admin-next/dashboard/src/i18n/translations/en.json b/packages/admin-next/dashboard/src/i18n/translations/en.json index 6c0b7498c168e..88da1771cb55f 100644 --- a/packages/admin-next/dashboard/src/i18n/translations/en.json +++ b/packages/admin-next/dashboard/src/i18n/translations/en.json @@ -848,6 +848,9 @@ }, "edits": { "title": "Edit order", + "confirm": "Confirm Edit", + "confirmText": "You are about to confirm an Order Edit. This action cannot be undone.", + "cancel": "Cancel Edit", "currentItems": "Current items", "currentItemsDescription": "Adjust item quantity or remove.", "addItemsDescription": "You can add new items to the order.", @@ -874,6 +877,8 @@ }, "returns": { "create": "Create Return", + "confirm": "Confirm Return", + "confirmText": "You are about to confirm a Return. This action cannot be undone.", "inbound": "Inbound", "outbound": "Outbound", "sendNotification": "Send notification", @@ -903,7 +908,7 @@ }, "receive": { "action": "Receive items", - "receive": "Return {{label}}", + "receiveItems": "{{ returnType }} {{ id }}", "restockAll": "Restock all items", "itemsLabel": "Items received", "title": "Receive items for #{{returnId}}", @@ -928,6 +933,9 @@ }, "claims": { "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", @@ -956,6 +964,9 @@ "exchanges": { "create": "Create Exchange", "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", @@ -1003,7 +1014,7 @@ "shipment": { "title": "Mark fulfillment shipped", "trackingNumber": "Tracking number", - "addTracking": "Add additional tracking number", + "addTracking": "Add tracking number", "sendNotification": "Send notification", "sendNotificationHint": "Notify the customer about this shipment.", "toastCreated": "Shipment created successfully." @@ -1078,6 +1089,10 @@ "deleteButtonText": "Delete comment" }, "events": { + "common": { + "toReturn": "To return", + "toSend": "To send" + }, "placed": { "title": "Order placed", "fromSalesChannel": "from {{salesChannel}}" diff --git a/packages/admin-next/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx b/packages/admin-next/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx index 50d5fe5afbc93..c297896da431d 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx @@ -15,6 +15,7 @@ import { Switch, Text, toast, + usePrompt, } from "@medusajs/ui" import { useEffect, useMemo, useState } from "react" import { useFieldArray, useForm } from "react-hook-form" @@ -305,8 +306,21 @@ export const ClaimCreateForm = ({ const showInboundItemsPlaceholder = !inboundItems.length const shippingOptionId = form.watch("inbound_option_id") + const prompt = usePrompt() const handleSubmit = form.handleSubmit(async (data) => { + const res = await prompt({ + title: t("general.areYouSure"), + description: t("orders.claims.confirmText"), + confirmText: t("actions.continue"), + cancelText: t("actions.cancel"), + variant: "confirmation", + }) + + if (!res) { + return + } + await confirmClaimRequest( { no_notification: !data.send_notification }, { @@ -518,6 +532,7 @@ export const ClaimCreateForm = ({ {t("actions.cancel")} + diff --git a/packages/admin-next/dashboard/src/routes/orders/order-create-edit/components/order-edit-create-form/order-edit-create-form.tsx b/packages/admin-next/dashboard/src/routes/orders/order-create-edit/components/order-edit-create-form/order-edit-create-form.tsx index 1f60214681983..d7f0641d24a27 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-create-edit/components/order-edit-create-form/order-edit-create-form.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-create-edit/components/order-edit-create-form/order-edit-create-form.tsx @@ -1,6 +1,6 @@ import { zodResolver } from "@hookform/resolvers/zod" import { AdminOrder, AdminOrderPreview } from "@medusajs/types" -import { Button, Heading, Input, Switch, toast } from "@medusajs/ui" +import { Button, Heading, Input, Switch, toast, usePrompt } from "@medusajs/ui" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" @@ -10,13 +10,13 @@ import { } from "../../../../../components/modals" import { Form } from "../../../../../components/common/form" -import { getStylizedAmount } from "../../../../../lib/money-amount-helpers" -import { CreateOrderEditSchemaType, OrderEditCreateSchema } from "./schema" import { useCancelOrderEdit, useRequestOrderEdit, } from "../../../../../hooks/api/order-edits" +import { getStylizedAmount } from "../../../../../lib/money-amount-helpers" import { OrderEditItemsSection } from "./order-edit-items-section" +import { CreateOrderEditSchemaType, OrderEditCreateSchema } from "./schema" type ReturnCreateFormProps = { order: AdminOrder @@ -55,8 +55,22 @@ export const OrderEditCreateForm = ({ resolver: zodResolver(OrderEditCreateSchema), }) + const prompt = usePrompt() + const handleSubmit = form.handleSubmit(async (data) => { try { + const res = await prompt({ + title: t("general.areYouSure"), + description: t("orders.edits.confirmText"), + confirmText: t("actions.continue"), + cancelText: t("actions.cancel"), + variant: "confirmation", + }) + + if (!res) { + return + } + await requestOrderEdit() toast.success(t("orders.edits.createSuccessToast")) @@ -185,6 +199,8 @@ export const OrderEditCreateForm = ({ }} /> + +
@@ -192,7 +208,7 @@ export const OrderEditCreateForm = ({
diff --git a/packages/admin-next/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-create-form.tsx b/packages/admin-next/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-create-form.tsx index 2b39ad9588940..337f2030f608c 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-create-form.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-create-form.tsx @@ -8,6 +8,7 @@ import { IconButton, Switch, toast, + usePrompt, } from "@medusajs/ui" import { useEffect, useMemo, useState } from "react" import { useForm } from "react-hook-form" @@ -148,9 +149,22 @@ export const ExchangeCreateForm = ({ }) const shippingOptionId = form.watch("inbound_option_id") + const prompt = usePrompt() const handleSubmit = form.handleSubmit(async (data) => { try { + const res = await prompt({ + title: t("general.areYouSure"), + description: t("orders.exchanges.confirmText"), + confirmText: t("actions.continue"), + cancelText: t("actions.cancel"), + variant: "confirmation", + }) + + if (!res) { + return + } + await confirmExchangeRequest({ no_notification: !data.send_notification }) handleSuccess() @@ -390,6 +404,8 @@ export const ExchangeCreateForm = ({ }} /> + +
@@ -402,9 +418,10 @@ export const ExchangeCreateForm = ({ variant="secondary" size="small" > - {t("actions.cancel")} + {t("orders.exchanges.cancel")} + diff --git a/packages/admin-next/dashboard/src/routes/orders/order-create-return/components/return-create-form/return-create-form.tsx b/packages/admin-next/dashboard/src/routes/orders/order-create-return/components/return-create-form/return-create-form.tsx index daf84ae273d3c..ac22d643e38fc 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-create-return/components/return-create-form/return-create-form.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-create-return/components/return-create-form/return-create-form.tsx @@ -10,6 +10,7 @@ import { Switch, Text, toast, + usePrompt, } from "@medusajs/ui" import { useEffect, useMemo, useState } from "react" import { useFieldArray, useForm } from "react-hook-form" @@ -240,9 +241,22 @@ export const ReturnCreateForm = ({ const showPlaceholder = !items.length const locationId = form.watch("location_id") const shippingOptionId = form.watch("option_id") + const prompt = usePrompt() const handleSubmit = form.handleSubmit(async (data) => { try { + const res = await prompt({ + title: t("general.areYouSure"), + description: t("orders.returns.confirmText"), + confirmText: t("actions.continue"), + cancelText: t("actions.cancel"), + variant: "confirmation", + }) + + if (!res) { + return + } + await confirmReturnRequest({ no_notification: !data.send_notification }) handleSuccess() @@ -702,6 +716,8 @@ export const ReturnCreateForm = ({ }} /> + +
@@ -709,7 +725,7 @@ export const ReturnCreateForm = ({
diff --git a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/active-order-claim-section/active-order-claim-section.tsx b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/active-order-claim-section/active-order-claim-section.tsx index 0d7bb8b4bd2ba..b9b78f07b0ecd 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/active-order-claim-section/active-order-claim-section.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/active-order-claim-section/active-order-claim-section.tsx @@ -65,7 +65,7 @@ export const ActiveOrderClaimSection = ({