saleor-dashboard/src/orders/views/OrderDetails/index.tsx

610 lines
26 KiB
TypeScript
Raw Normal View History

2020-09-01 16:22:54 +00:00
import { MetadataFormData } from "@saleor/components/Metadata";
import NotFoundPage from "@saleor/components/NotFoundPage";
2019-06-19 14:40:52 +00:00
import { WindowTitle } from "@saleor/components/WindowTitle";
2019-11-21 14:59:06 +00:00
import { DEFAULT_INITIAL_SEARCH_DATA } from "@saleor/config";
2020-06-26 17:06:48 +00:00
import { Task } from "@saleor/containers/BackgroundTasks/types";
import useBackgroundTask from "@saleor/hooks/useBackgroundTask";
2019-06-19 14:40:52 +00:00
import useNavigator from "@saleor/hooks/useNavigator";
2020-09-01 16:22:54 +00:00
import useNotifier from "@saleor/hooks/useNotifier";
2019-10-09 10:18:44 +00:00
import useUser from "@saleor/hooks/useUser";
2020-09-01 16:22:54 +00:00
import { commonMessages } from "@saleor/intl";
import OrderCannotCancelOrderDialog from "@saleor/orders/components/OrderCannotCancelOrderDialog";
2020-06-24 15:29:13 +00:00
import OrderInvoiceEmailSendDialog from "@saleor/orders/components/OrderInvoiceEmailSendDialog";
import { useOrderConfirmMutation } from "@saleor/orders/mutations";
2020-06-26 17:06:48 +00:00
import { InvoiceRequest } from "@saleor/orders/types/InvoiceRequest";
2019-11-19 16:32:35 +00:00
import useCustomerSearch from "@saleor/searches/useCustomerSearch";
import getOrderErrorMessage from "@saleor/utils/errors/order";
2019-12-06 14:58:28 +00:00
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
2020-09-01 16:22:54 +00:00
import createMetadataUpdateHandler from "@saleor/utils/handlers/metadataUpdateHandler";
import {
useMetadataUpdate,
usePrivateMetadataUpdate
} from "@saleor/utils/metadata/updateMetadata";
2020-04-27 14:26:57 +00:00
import { useWarehouseList } from "@saleor/warehouses/queries";
import React from "react";
import { useIntl } from "react-intl";
2019-06-19 14:40:52 +00:00
import { customerUrl } from "../../../customers/urls";
2020-10-29 11:59:48 +00:00
import { getMutationState, getStringOrPlaceholder, maybe } from "../../../misc";
2019-06-19 14:40:52 +00:00
import { productUrl } from "../../../products/urls";
2020-06-26 17:06:48 +00:00
import {
FulfillmentStatus,
JobStatusEnum,
OrderStatus
2020-06-26 17:06:48 +00:00
} from "../../../types/globalTypes";
2019-06-19 14:40:52 +00:00
import OrderCancelDialog from "../../components/OrderCancelDialog";
import OrderDetailsPage from "../../components/OrderDetailsPage";
import OrderDraftCancelDialog from "../../components/OrderDraftCancelDialog/OrderDraftCancelDialog";
import OrderDraftPage from "../../components/OrderDraftPage";
import OrderFulfillmentCancelDialog from "../../components/OrderFulfillmentCancelDialog";
import OrderFulfillmentTrackingDialog from "../../components/OrderFulfillmentTrackingDialog";
import OrderMarkAsPaidDialog from "../../components/OrderMarkAsPaidDialog/OrderMarkAsPaidDialog";
import OrderPaymentDialog from "../../components/OrderPaymentDialog";
import OrderPaymentVoidDialog from "../../components/OrderPaymentVoidDialog";
import OrderProductAddDialog from "../../components/OrderProductAddDialog";
import OrderShippingMethodEditDialog from "../../components/OrderShippingMethodEditDialog";
import OrderOperations from "../../containers/OrderOperations";
2019-11-20 10:24:42 +00:00
import { TypedOrderDetailsQuery, useOrderVariantSearch } from "../../queries";
2019-06-19 14:40:52 +00:00
import {
2020-10-08 10:39:26 +00:00
orderDraftListUrl,
orderFulfillUrl,
2019-06-19 14:40:52 +00:00
orderListUrl,
Refunds (#870) * 1721 - add refunds miscellaneous view (#860) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Fix refund details on order details page (#879) * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Add missing refund amount to order history * Merge repeated order lines in fulfillment lines * Update order history events types and test snapshots * Update changelog with refunds changes
2020-12-01 13:13:05 +00:00
orderRefundUrl,
Feature/order reissue (#910) * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Add change to changelog * Remove console.log * Update tests * Extract messages * Add utils functions for selecting only ulfulfilled order lines * Add optional value selection for line item * Update tests * Add optional rendering of unfulfilled items card and refactor a bit * Update displaying of items card title when refunded card * UUpdate utils, form data etc. not to include refunded items when calculating replaced items amount * Uppdate return items card not to display replace buttons for refunded items * Refactor and small fixes after review * Update extracted messages * Fix card title when no fullfilemtn id * wip * Initially stitch returns page. Update types, add mutation * remove unnecessary component display names * Add loading status from form submission & refactor * Add errors from response * Add errors from response and refactor * Remove comments * Add optional error adding when no data from return create request * Update messages * wip * Update snapshots * Remove unnecessary console.log * Add better typing for getParsedLineData function * Update & refactor card title to match cards both in return and order details * Add handling of new statuses to order details cards. Also refactor, and devide order fulfillment card into couple of smaller components * Update messages * Update schema to match api * Update types * Update status label component to match colors with new designs and order details cards * RUpdate and refactor order fulfillment card components to be reusable. Also add replaced status handling * Updayte card title component to handle all cases and statuses * Update oorder unfulfilled items card and order details page, reduce some of the boilerplate * Fix card title types and adjust returns card to match * Update messages * Update snapshots * RUpdate order fulfillment card with subtitles and buttons for returned status * Add onRefund to order fulfillment card * Fix typo and wrong message in card title * Add missing condition in return form submission utils to decice if to refund products * Update fulfillment subtitles row and tests * Update messages * Change naming and locations of OrderFulfillment and items card components * Update messages * U[pdate names of components again to even better ones * Update messages * changelog * Update schema and types so that order history event also includes user first and last name * Add extended timeline event and event header components. Move some of the logic to utils and add way to display links in the event header. * FFix types * Update messages * Change naming of isOfType -> isTimelineEventOfType and refactor extended timeline event messages selection to be less complicated * Add ids and update messages * Add ids and update messages some more * Update storybook decorator to work with react router context in components and tests * Refactor after review * Update messages * Add rredirecting to draft order * Add handling draft creation from replacement * Add related order to order event fragment and update lots and lots of types * Update extended timeline event to match related order type on order history event * Update fixtures * Refactor ExtendedTimelineEvent Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix typing * Update messages * Fix missing history event for replacement draft created for replaced products * Update messages * Handle new statuses for returned and partially returned orders * Update messages * update snapshots * BBump empty line to rebuild ci * Change status to proper color * Change replaceable items in return for replace to be auto off instead of on * Add utils functions and make order details menu not show option to return items when there are returnable items in the order * Fix replace checkbox showing when previously hidden and clicked set maximal quantities * Fix return form invalid money values * Add default values to avoid returning of NaN in utils for return amount and refactor * Add ggeneral error alerts * Add eproduct error box component and style. style a lot. * Fixes * Fix lint * Add cannot refund error title + description * Extract messages * Refactor after review * Add better, nicer and fancier imports to product error cell * Use error color from palette in product error cell * Fix max refund when 0 for return * Add ddisable ability to refund products button so it's disabled when 0 products selected * Add class for order return form data parsing and add condition to not do refund when total captured on order is 0 * Update snapshots * Add condition for order lines quantity in order products table row * Fix return amount submit button * Add change to changelog Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2021-01-20 16:16:43 +00:00
orderReturnPath,
2019-06-19 14:40:52 +00:00
orderUrl,
2020-04-20 17:18:20 +00:00
OrderUrlDialog,
OrderUrlQueryParams
2019-06-19 14:40:52 +00:00
} from "../../urls";
2020-10-29 11:59:48 +00:00
import OrderAddressFields from "./OrderAddressFields";
2019-06-19 14:40:52 +00:00
import { OrderDetailsMessages } from "./OrderDetailsMessages";
interface OrderDetailsProps {
id: string;
params: OrderUrlQueryParams;
}
export const OrderDetails: React.FC<OrderDetailsProps> = ({ id, params }) => {
2019-06-19 14:40:52 +00:00
const navigate = useNavigator();
2019-10-09 10:18:44 +00:00
const { user } = useUser();
Multichannel (#833) * add multichannel to configuration view * create multichannels list view * create multichannels list view * add ChannelsCreate view * update channels in configuration * add stories * update default messages * fix ChannelForm props * update channels list styles * update snapshots * update channel form currency input * update Channels fragments * extract messages * remove tabs from channelsList * channel details, channel delete modal (#598) * create Channel details view * create ChannelDeleteDialog * add channels delete dialog to channels list * update messages and types * fixes after review * channels availability (#609) * create Channel details view * update messages and types * create ChannelsAvailability component * create more product channels components * create channels stories, update fixtures, types * update product views with channels data * update schema and snapshots * update defaultMessages * update ProductUpdate view * create ChannelsAvailabilityDropdown component * add product channels to local storage * update globalTypes * Update to new schema and resolve issues * Update messages * create deleteChannel mutation * add channels availability component to product create view * refactor ProductCreate and ProductUpdate views * CollectionProducts view cleanup * add disabled prop to ActionDialog * use updateChannels mutation in ProductCreate view * ProductCreate - update submit function * fixes after review * update snapshots and messages Co-authored-by: Krzysztof Wolski <krzysztof.k.wolski@gmail.com> * channels shipping components (#655) * create PricingCard, OrderValue and OrderWeight components * create ShippingZoneRatesPage and DeleteShippingRateDialog * update ChannelsAvailability component * updates after review * channels shipping views (#662) * update ChannelsAvailability component * updates after review * create PriceRate views, update types * create weight rates views * update shipping views, stories, messages * update snapshots * update snapshots * update useChannels hook * orders channels components (#698) * create OrderChannelSectionCard component * update OrderDetailsPage * update DraftOrderChannelCard * update snapshots * update fixtures * small change after review, update snapshots * product pricing (#702) * update product types * update Pricing in simple product view * use productVariantCreate mutation in simple product view * update snapshots and messages * handle create variant (#715) * update product types * update Pricing in simple product view * handle product create and update errors * update snapshots and messages * fix update and create product handlers * update pricing types * channels modal - new styles, search input (#717) * update product types * update Pricing in simple product view * handle product create and update errors * update pricing types * add search input in ChannelsAvailabilityDialog * update ChannelsAvailabilityDialog in all views * update snapshots * fix search input label styles * update toggleAllChannels function * update variant creator (#724) * update product types * update Pricing in simple product view * handle product create and update errors * update pricing types * add search input in ChannelsAvailabilityDialog * update ChannelsAvailabilityDialog in all views * update snapshots * add channelLisitngs to variant creator * update variant creator price styles * update product variant creator reducer tests * update createVariants tests * update error handling in product variant creator * add Skip pricing for now option * use PriceField instead of TextField in ProductVariantCreatorSummary * create price validation function * fix errors handling in ProductVariantPrice component * fixes after review * Product List - remove publish/unpublish buttons (#727) * ProductList - remove publish and unpublish buttons * update messages * update snapshots, messages * revert changes in ChannelsAvailabilityDropdown * products/shipping/discount list settings (#739) * create ChannelSettingsDialog component * update snapshots * ProductList - open settings modal when there is no selected channel * add settings modal to vouchers list * add settings dialog to sales list * add setting modal to shipping list * update shipping * update snapshots, messages * useChannelsSettings - remove selectedChannelSlug * fix channels update handler in product and shipping view * messages update in ChannelSettingsDialog * handle product/discount list when there is no channels * update onSettingsOpen prop * collection availability dropdown (#743) * add availability dropdown to collection products list * update channelListingProduct fragment name * update voucher view/components with channels (#746) * update voucher view/components with channels * update VoucherSummary, remove defaultCurrency from voucher components * update snapshots * move getChannelsVariables func to discounts handlers * update voucher messages * sale view/components with channels (#750) * update sale views with channels * small fixes in discounts * order views with channels (#752) * update draft orders with channels * add channel activate/deactivate mutations * remove sort by total in orders list * add error notification on channel activate/deactivate * product variants channel select (#755) * add channels selector to ProductVariants component * remove selectedChannel from ProductUpdate, update messages and snapshots * update product fragments * update translations (#762) * update translations * fix translation types * update messages * update Availability component (#766) * update ChannelsAvailability component * update product fixtures * update collection and channel fixtures * ChannelsAvailability - handle errors * update product handlers * update ChannelsAvailability styles * update ProductVariant * update snapshots * fix missing things in multichannel (#785) * add availability dropdown to discount products list * fix error handling in shipping components * update product views and components * update messages * update category view/components * update CategoryProducts styles * remove defaultCurrency from shipping components * create ChannelsSelect component * update channels error handling after review * another fixes after review * Add channels to collection views/components (#791) ** update collection components and views * update create collection view * update error handling in collection * remove filter bar from collection list * update products fragments * small fix in collection create view * use collectionFragment in useCatalogSearch * update defaultMessages and snapshots * update homepage view/drop defaultCurrency (#801) * update homepage view * drop defaultCurrency prop * fix onChannelChange function in home view * remove visibility from product list filters * update export products with channels (#803) * update ProductExportDialog with channels * add new channel error code * remover VISIBLE from product export dialog Financial information * fix input size in ProductVariantCreatorSummary (#804) * channels currency code select (#806) * create select with currency codes * fix ChannelDeleteDialog * update defaultMessages, remove unneeded ChannelDetails handlers * fixes after rebase * replace channelListing with channelListings * [multichannel] Update schema] * Fix product create test Co-authored-by: AlicjaSzu <alicja.szukuc@gmail.com> Co-authored-by: Krzysztof Wolski <krzysztof.k.wolski@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2020-11-17 16:10:42 +00:00
2019-11-19 16:32:35 +00:00
const {
loadMore: loadMoreCustomers,
search: searchUsers,
result: users
2019-11-19 16:32:35 +00:00
} = useCustomerSearch({
variables: DEFAULT_INITIAL_SEARCH_DATA
2019-11-19 16:32:35 +00:00
});
2019-11-20 10:24:42 +00:00
const {
loadMore,
search: variantSearch,
result: variantSearchOpts
2019-11-20 10:24:42 +00:00
} = useOrderVariantSearch({
variables: DEFAULT_INITIAL_SEARCH_DATA
2019-11-20 10:24:42 +00:00
});
2020-04-27 14:26:57 +00:00
const warehouses = useWarehouseList({
displayLoader: true,
variables: {
first: 30
}
2020-04-27 14:26:57 +00:00
});
2020-06-26 17:06:48 +00:00
const { queue } = useBackgroundTask();
2020-03-16 12:28:52 +00:00
const intl = useIntl();
2020-09-01 16:22:54 +00:00
const [updateMetadata, updateMetadataOpts] = useMetadataUpdate({});
const [
updatePrivateMetadata,
updatePrivateMetadataOpts
] = usePrivateMetadataUpdate({});
const notify = useNotifier();
const [transactionReference, setTransactionReference] = React.useState("");
2020-03-16 12:28:52 +00:00
const [openModal, closeModal] = createDialogActionHandlers<
OrderUrlDialog,
OrderUrlQueryParams
>(navigate, params => orderUrl(id, params), params);
2019-06-19 14:40:52 +00:00
2020-02-20 14:18:22 +00:00
const handleBack = () => navigate(orderListUrl());
const [orderConfirm] = useOrderConfirmMutation({
onCompleted: ({ orderConfirm: { errors } }) => {
const isError = !!errors.length;
notify({
status: isError ? "error" : "success",
text: isError
? getOrderErrorMessage(errors[0], intl)
: "Confirmed Order"
});
}
});
2019-06-19 14:40:52 +00:00
return (
2020-02-20 14:18:22 +00:00
<TypedOrderDetailsQuery displayLoader variables={{ id }}>
2019-06-19 14:40:52 +00:00
{({ data, loading }) => {
2020-02-20 14:18:22 +00:00
const order = data?.order;
if (order === null) {
return <NotFoundPage onBack={handleBack} />;
}
2020-09-01 16:22:54 +00:00
const handleSubmit = async (data: MetadataFormData) => {
if (order?.status === OrderStatus.UNCONFIRMED) {
await orderConfirm({ variables: { id: order?.id } });
}
2020-09-01 16:22:54 +00:00
const update = createMetadataUpdateHandler(
order,
() => Promise.resolve([]),
variables => updateMetadata({ variables }),
variables => updatePrivateMetadata({ variables })
);
const result = await update(data);
if (result.length === 0) {
notify({
status: "success",
text: intl.formatMessage(commonMessages.savedChanges)
});
}
2020-10-22 11:33:29 +00:00
return result;
2020-09-01 16:22:54 +00:00
};
2019-06-19 14:40:52 +00:00
return (
2020-03-16 12:28:52 +00:00
<OrderDetailsMessages id={id} params={params}>
{orderMessages => (
2019-11-19 16:32:35 +00:00
<OrderOperations
order={id}
onNoteAdd={orderMessages.handleNoteAdd}
onOrderCancel={orderMessages.handleOrderCancel}
onOrderVoid={orderMessages.handleOrderVoid}
onPaymentCapture={orderMessages.handlePaymentCapture}
onUpdate={orderMessages.handleUpdate}
onDraftUpdate={orderMessages.handleDraftUpdate}
onShippingMethodUpdate={
orderMessages.handleShippingMethodUpdate
}
onOrderLineDelete={orderMessages.handleOrderLineDelete}
onOrderLinesAdd={orderMessages.handleOrderLinesAdd}
onOrderLineUpdate={orderMessages.handleOrderLineUpdate}
onOrderFulfillmentCancel={
orderMessages.handleOrderFulfillmentCancel
}
onOrderFulfillmentUpdate={
orderMessages.handleOrderFulfillmentUpdate
}
onDraftFinalize={orderMessages.handleDraftFinalize}
onDraftCancel={orderMessages.handleDraftCancel}
onOrderMarkAsPaid={orderMessages.handleOrderMarkAsPaid}
2020-06-26 17:06:48 +00:00
onInvoiceRequest={(data: InvoiceRequest) => {
if (
data.invoiceRequest.invoice.status === JobStatusEnum.SUCCESS
) {
orderMessages.handleInvoiceGenerateFinished(data);
} else {
orderMessages.handleInvoiceGeneratePending(data);
queue(Task.INVOICE_GENERATE, {
2020-07-06 23:57:43 +00:00
generateInvoice: {
2020-06-26 17:06:48 +00:00
invoiceId: data.invoiceRequest.invoice.id,
orderId: id
}
2020-06-26 17:06:48 +00:00
});
}
}}
2020-06-24 12:50:14 +00:00
onInvoiceSend={orderMessages.handleInvoiceSend}
2019-11-19 16:32:35 +00:00
>
{({
orderAddNote,
orderCancel,
orderDraftUpdate,
orderLinesAdd,
orderLineDelete,
orderLineUpdate,
orderPaymentCapture,
orderVoid,
orderShippingMethodUpdate,
orderUpdate,
orderFulfillmentCancel,
orderFulfillmentUpdateTracking,
orderDraftCancel,
orderDraftFinalize,
2020-06-22 16:34:59 +00:00
orderPaymentMarkAsPaid,
2020-06-23 12:27:44 +00:00
orderInvoiceRequest,
orderInvoiceSend
2019-12-06 17:11:46 +00:00
}) => (
<>
2020-03-16 12:28:52 +00:00
{order?.status !== OrderStatus.DRAFT ? (
2019-12-06 17:11:46 +00:00
<>
<WindowTitle
2020-03-16 12:28:52 +00:00
title={intl.formatMessage(
{
defaultMessage: "Order #{orderNumber}",
description: "window title"
2020-03-16 12:28:52 +00:00
},
{
orderNumber: getStringOrPlaceholder(
data?.order?.number
)
2020-03-16 12:28:52 +00:00
}
)}
2019-12-06 17:11:46 +00:00
/>
<OrderDetailsPage
Feature/order reissue (#910) * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Add change to changelog * Remove console.log * Update tests * Extract messages * Add utils functions for selecting only ulfulfilled order lines * Add optional value selection for line item * Update tests * Add optional rendering of unfulfilled items card and refactor a bit * Update displaying of items card title when refunded card * UUpdate utils, form data etc. not to include refunded items when calculating replaced items amount * Uppdate return items card not to display replace buttons for refunded items * Refactor and small fixes after review * Update extracted messages * Fix card title when no fullfilemtn id * wip * Initially stitch returns page. Update types, add mutation * remove unnecessary component display names * Add loading status from form submission & refactor * Add errors from response * Add errors from response and refactor * Remove comments * Add optional error adding when no data from return create request * Update messages * wip * Update snapshots * Remove unnecessary console.log * Add better typing for getParsedLineData function * Update & refactor card title to match cards both in return and order details * Add handling of new statuses to order details cards. Also refactor, and devide order fulfillment card into couple of smaller components * Update messages * Update schema to match api * Update types * Update status label component to match colors with new designs and order details cards * RUpdate and refactor order fulfillment card components to be reusable. Also add replaced status handling * Updayte card title component to handle all cases and statuses * Update oorder unfulfilled items card and order details page, reduce some of the boilerplate * Fix card title types and adjust returns card to match * Update messages * Update snapshots * RUpdate order fulfillment card with subtitles and buttons for returned status * Add onRefund to order fulfillment card * Fix typo and wrong message in card title * Add missing condition in return form submission utils to decice if to refund products * Update fulfillment subtitles row and tests * Update messages * Change naming and locations of OrderFulfillment and items card components * Update messages * U[pdate names of components again to even better ones * Update messages * changelog * Update schema and types so that order history event also includes user first and last name * Add extended timeline event and event header components. Move some of the logic to utils and add way to display links in the event header. * FFix types * Update messages * Change naming of isOfType -> isTimelineEventOfType and refactor extended timeline event messages selection to be less complicated * Add ids and update messages * Add ids and update messages some more * Update storybook decorator to work with react router context in components and tests * Refactor after review * Update messages * Add rredirecting to draft order * Add handling draft creation from replacement * Add related order to order event fragment and update lots and lots of types * Update extended timeline event to match related order type on order history event * Update fixtures * Refactor ExtendedTimelineEvent Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix typing * Update messages * Fix missing history event for replacement draft created for replaced products * Update messages * Handle new statuses for returned and partially returned orders * Update messages * update snapshots * BBump empty line to rebuild ci * Change status to proper color * Change replaceable items in return for replace to be auto off instead of on * Add utils functions and make order details menu not show option to return items when there are returnable items in the order * Fix replace checkbox showing when previously hidden and clicked set maximal quantities * Fix return form invalid money values * Add default values to avoid returning of NaN in utils for return amount and refactor * Add ggeneral error alerts * Add eproduct error box component and style. style a lot. * Fixes * Fix lint * Add cannot refund error title + description * Extract messages * Refactor after review * Add better, nicer and fancier imports to product error cell * Use error color from palette in product error cell * Fix max refund when 0 for return * Add ddisable ability to refund products button so it's disabled when 0 products selected * Add class for order return form data parsing and add condition to not do refund when total captured on order is 0 * Update snapshots * Add condition for order lines quantity in order products table row * Fix return amount submit button * Add change to changelog Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2021-01-20 16:16:43 +00:00
onOrderReturn={() => navigate(orderReturnPath(id))}
2020-09-01 16:22:54 +00:00
disabled={
updateMetadataOpts.loading ||
updatePrivateMetadataOpts.loading
}
onNoteAdd={variables =>
2019-12-06 17:11:46 +00:00
orderAddNote.mutate({
input: variables,
order: id
2019-12-06 17:11:46 +00:00
})
}
2020-02-20 14:18:22 +00:00
onBack={handleBack}
2019-12-06 17:11:46 +00:00
order={order}
2020-09-01 16:22:54 +00:00
saveButtonBarState={getMutationState(
updateMetadataOpts.called ||
updatePrivateMetadataOpts.called,
updateMetadataOpts.loading ||
updatePrivateMetadataOpts.loading,
[
...(updateMetadataOpts.data?.deleteMetadata
.errors || []),
...(updateMetadataOpts.data?.updateMetadata
.errors || []),
...(updatePrivateMetadataOpts.data
?.deletePrivateMetadata.errors || []),
...(updatePrivateMetadataOpts.data
?.updatePrivateMetadata.errors || [])
]
)}
2019-12-06 17:11:46 +00:00
shippingMethods={maybe(
() => data.order.availableShippingMethods,
[]
)}
userPermissions={user?.userPermissions || []}
2019-12-06 17:11:46 +00:00
onOrderCancel={() => openModal("cancel")}
2020-04-20 17:18:20 +00:00
onOrderFulfill={() => navigate(orderFulfillUrl(id))}
onFulfillmentCancel={fulfillmentId =>
2019-12-06 17:11:46 +00:00
navigate(
orderUrl(id, {
action: "cancel-fulfillment",
id: fulfillmentId
2019-11-19 16:32:35 +00:00
})
2019-12-06 17:11:46 +00:00
)
}
onFulfillmentTrackingNumberUpdate={fulfillmentId =>
2019-12-06 17:11:46 +00:00
navigate(
orderUrl(id, {
action: "edit-fulfillment",
id: fulfillmentId
2019-11-19 16:32:35 +00:00
})
2019-12-06 17:11:46 +00:00
)
}
onPaymentCapture={() => openModal("capture")}
onPaymentVoid={() => openModal("void")}
Refunds (#870) * 1721 - add refunds miscellaneous view (#860) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Fix refund details on order details page (#879) * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Add missing refund amount to order history * Merge repeated order lines in fulfillment lines * Update order history events types and test snapshots * Update changelog with refunds changes
2020-12-01 13:13:05 +00:00
onPaymentRefund={() => navigate(orderRefundUrl(id))}
onProductClick={id => () => navigate(productUrl(id))}
2019-12-06 17:11:46 +00:00
onBillingAddressEdit={() =>
openModal("edit-billing-address")
}
onShippingAddressEdit={() =>
openModal("edit-shipping-address")
}
onPaymentPaid={() => openModal("mark-paid")}
onProfileView={() =>
navigate(customerUrl(order.user.id))
}
2020-07-02 11:58:44 +00:00
onInvoiceClick={id =>
window.open(
order.invoices.find(invoice => invoice.id === id)
?.url,
"_blank"
)
2020-06-22 16:34:59 +00:00
}
2020-06-24 15:29:13 +00:00
onInvoiceGenerate={() =>
2020-06-23 12:27:44 +00:00
orderInvoiceRequest.mutate({
orderId: id
2020-06-23 12:27:44 +00:00
})
}
2020-07-02 11:58:44 +00:00
onInvoiceSend={id =>
openModal("invoice-send", { id })
2020-06-23 14:44:34 +00:00
}
2020-09-01 16:22:54 +00:00
onSubmit={handleSubmit}
2019-12-06 17:11:46 +00:00
/>
2020-04-28 01:09:31 +00:00
<OrderCannotCancelOrderDialog
onClose={closeModal}
open={
params.action === "cancel" &&
order?.fulfillments.some(
fulfillment =>
2020-04-28 01:09:31 +00:00
fulfillment.status ===
FulfillmentStatus.FULFILLED
)
}
/>
2019-12-06 17:11:46 +00:00
<OrderCancelDialog
2020-03-16 12:28:52 +00:00
confirmButtonState={orderCancel.opts.status}
errors={
2020-03-03 11:20:39 +00:00
orderCancel.opts.data?.orderCancel.errors || []
2020-03-16 12:28:52 +00:00
}
number={order?.number}
2019-12-06 17:11:46 +00:00
open={params.action === "cancel"}
onClose={closeModal}
2020-04-28 01:09:31 +00:00
onSubmit={() =>
2019-12-06 17:11:46 +00:00
orderCancel.mutate({
id
2019-12-06 17:11:46 +00:00
})
}
/>
<OrderMarkAsPaidDialog
2020-03-16 12:28:52 +00:00
confirmButtonState={
orderPaymentMarkAsPaid.opts.status
}
errors={
orderPaymentMarkAsPaid.opts.data?.orderMarkAsPaid
.errors || []
}
2019-12-06 17:11:46 +00:00
onClose={closeModal}
onConfirm={() =>
orderPaymentMarkAsPaid.mutate({
id,
transactionReference
2019-12-06 17:11:46 +00:00
})
}
open={params.action === "mark-paid"}
transactionReference={transactionReference}
handleTransactionReference={({ target }) =>
setTransactionReference(target.value)
}
2019-12-06 17:11:46 +00:00
/>
<OrderPaymentVoidDialog
2020-03-16 12:28:52 +00:00
confirmButtonState={orderVoid.opts.status}
errors={orderVoid.opts.data?.orderVoid.errors || []}
2019-12-06 17:11:46 +00:00
open={params.action === "void"}
onClose={closeModal}
onConfirm={() => orderVoid.mutate({ id })}
/>
<OrderPaymentDialog
2020-03-16 12:28:52 +00:00
confirmButtonState={orderPaymentCapture.opts.status}
errors={
orderPaymentCapture.opts.data?.orderCapture
.errors || []
}
initial={order?.total.gross.amount}
2019-12-06 17:11:46 +00:00
open={params.action === "capture"}
onClose={closeModal}
onSubmit={variables =>
2019-12-06 17:11:46 +00:00
orderPaymentCapture.mutate({
...variables,
id
2019-12-06 17:11:46 +00:00
})
}
/>
<OrderFulfillmentCancelDialog
2020-03-16 12:28:52 +00:00
confirmButtonState={
orderFulfillmentCancel.opts.status
}
errors={
orderFulfillmentCancel.opts.data
?.orderFulfillmentCancel.errors || []
}
2019-12-06 17:11:46 +00:00
open={params.action === "cancel-fulfillment"}
2020-04-27 14:26:57 +00:00
warehouses={
warehouses.data?.warehouses.edges.map(
edge => edge.node
2020-04-27 14:26:57 +00:00
) || []
}
onConfirm={variables =>
2019-12-06 17:11:46 +00:00
orderFulfillmentCancel.mutate({
id: params.id,
input: variables
2019-12-06 17:11:46 +00:00
})
}
onClose={closeModal}
/>
<OrderFulfillmentTrackingDialog
2020-03-16 12:28:52 +00:00
confirmButtonState={
orderFulfillmentUpdateTracking.opts.status
}
errors={
orderFulfillmentUpdateTracking.opts.data
?.orderFulfillmentUpdateTracking.errors || []
}
2019-12-06 17:11:46 +00:00
open={params.action === "edit-fulfillment"}
2020-03-16 12:28:52 +00:00
trackingNumber={getStringOrPlaceholder(
data?.order?.fulfillments.find(
fulfillment => fulfillment.id === params.id
2020-03-16 12:28:52 +00:00
)?.trackingNumber
2019-12-06 17:11:46 +00:00
)}
onConfirm={variables =>
2019-12-06 17:11:46 +00:00
orderFulfillmentUpdateTracking.mutate({
id: params.id,
input: {
2019-11-19 16:32:35 +00:00
...variables,
notifyCustomer: true
}
2019-12-06 17:11:46 +00:00
})
}
onClose={closeModal}
/>
2020-06-24 15:29:13 +00:00
<OrderInvoiceEmailSendDialog
confirmButtonState={orderInvoiceSend.opts.status}
errors={
2020-06-25 11:36:43 +00:00
orderInvoiceSend.opts.data?.invoiceSendEmail
2020-06-24 15:29:13 +00:00
.errors || []
}
open={params.action === "invoice-send"}
invoice={order?.invoices?.find(
invoice => invoice.id === params.id
2020-06-24 15:29:13 +00:00
)}
onClose={closeModal}
onSend={() =>
2020-06-24 15:29:13 +00:00
orderInvoiceSend.mutate({ id: params.id })
}
/>
2019-12-06 17:11:46 +00:00
</>
) : (
<>
<WindowTitle
2020-03-16 12:28:52 +00:00
title={intl.formatMessage(
{
defaultMessage: "Draft Order #{orderNumber}",
description: "window title"
2020-03-16 12:28:52 +00:00
},
{
orderNumber: getStringOrPlaceholder(
data?.order?.number
)
2020-03-16 12:28:52 +00:00
}
2019-12-06 17:11:46 +00:00
)}
/>
<OrderDraftPage
disabled={loading}
onNoteAdd={variables =>
2019-12-06 17:11:46 +00:00
orderAddNote.mutate({
input: variables,
order: id
2019-12-06 17:11:46 +00:00
})
}
users={maybe(
() =>
users.data.search.edges.map(edge => edge.node),
2019-12-06 17:11:46 +00:00
[]
)}
hasMore={maybe(
() => users.data.search.pageInfo.hasNextPage,
false
)}
onFetchMore={loadMoreCustomers}
fetchUsers={searchUsers}
loading={users.loading}
usersLoading={users.loading}
onCustomerEdit={data =>
2019-12-06 17:11:46 +00:00
orderDraftUpdate.mutate({
id,
input: data
2019-12-06 17:11:46 +00:00
})
}
2020-10-20 13:19:58 +00:00
onDraftFinalize={() =>
orderDraftFinalize.mutate({ id })
}
2019-12-06 17:11:46 +00:00
onDraftRemove={() => openModal("cancel")}
onOrderLineAdd={() => openModal("add-order-line")}
2020-10-08 10:39:26 +00:00
onBack={() => navigate(orderDraftListUrl())}
2019-12-06 17:11:46 +00:00
order={order}
countries={maybe(() => data.shop.countries, []).map(
country => ({
2019-12-06 17:11:46 +00:00
code: country.code,
label: country.country
2019-12-06 17:11:46 +00:00
})
)}
onProductClick={id => () =>
2019-12-06 17:11:46 +00:00
navigate(productUrl(encodeURIComponent(id)))}
onBillingAddressEdit={() =>
openModal("edit-billing-address")
}
onShippingAddressEdit={() =>
openModal("edit-shipping-address")
}
onShippingMethodEdit={() =>
openModal("edit-shipping")
}
onOrderLineRemove={id =>
2019-12-06 17:11:46 +00:00
orderLineDelete.mutate({ id })
}
onOrderLineChange={(id, data) =>
orderLineUpdate.mutate({
id,
input: data
2019-12-06 17:11:46 +00:00
})
}
saveButtonBarState="default"
onProfileView={() =>
navigate(customerUrl(order.user.id))
}
userPermissions={user?.userPermissions || []}
2019-12-06 17:11:46 +00:00
/>
<OrderDraftCancelDialog
2020-03-16 12:28:52 +00:00
confirmButtonState={orderDraftCancel.opts.status}
errors={
orderDraftCancel.opts.data?.draftOrderDelete
.errors || []
}
2019-12-06 17:11:46 +00:00
onClose={closeModal}
onConfirm={() => orderDraftCancel.mutate({ id })}
open={params.action === "cancel"}
2020-03-16 12:28:52 +00:00
orderNumber={getStringOrPlaceholder(order?.number)}
2019-12-06 17:11:46 +00:00
/>
<OrderShippingMethodEditDialog
2020-03-16 12:28:52 +00:00
confirmButtonState={
orderShippingMethodUpdate.opts.status
}
errors={
orderShippingMethodUpdate.opts.data
?.orderUpdateShipping.errors || []
}
2019-12-06 17:11:46 +00:00
open={params.action === "edit-shipping"}
2020-03-16 12:28:52 +00:00
shippingMethod={order?.shippingMethod?.id}
shippingMethods={order?.availableShippingMethods}
2019-12-06 17:11:46 +00:00
onClose={closeModal}
onSubmit={variables =>
2019-12-06 17:11:46 +00:00
orderShippingMethodUpdate.mutate({
id,
input: {
shippingMethod: variables.shippingMethod
}
2019-12-06 17:11:46 +00:00
})
}
/>
<OrderProductAddDialog
2020-03-16 12:28:52 +00:00
confirmButtonState={orderLinesAdd.opts.status}
errors={
orderLinesAdd.opts.data?.orderLinesCreate.errors ||
[]
2020-03-16 12:28:52 +00:00
}
2019-12-06 17:11:46 +00:00
loading={variantSearchOpts.loading}
open={params.action === "add-order-line"}
2020-03-16 12:28:52 +00:00
hasMore={
variantSearchOpts.data?.search.pageInfo.hasNextPage
}
products={variantSearchOpts.data?.search.edges.map(
edge => edge.node
2019-12-06 17:11:46 +00:00
)}
selectedChannelId={order?.channel?.id}
2019-12-06 17:11:46 +00:00
onClose={closeModal}
onFetch={variantSearch}
onFetchMore={loadMore}
onSubmit={variants =>
2019-12-06 17:11:46 +00:00
orderLinesAdd.mutate({
id,
input: variants.map(variant => ({
2019-12-06 17:11:46 +00:00
quantity: 1,
variantId: variant.id
}))
2019-12-06 17:11:46 +00:00
})
}
/>
</>
)}
2020-10-29 11:59:48 +00:00
<OrderAddressFields
isDraft={order?.status === OrderStatus.DRAFT}
orderUpdate={orderUpdate}
orderDraftUpdate={orderDraftUpdate}
data={data}
id={id}
2019-12-06 17:11:46 +00:00
onClose={closeModal}
2020-10-29 11:59:48 +00:00
action={params.action}
2019-12-06 17:11:46 +00:00
/>
</>
)}
2019-11-19 16:32:35 +00:00
</OrderOperations>
2019-06-19 14:40:52 +00:00
)}
2019-11-19 16:32:35 +00:00
</OrderDetailsMessages>
2019-06-19 14:40:52 +00:00
);
}}
</TypedOrderDetailsQuery>
);
};
export default OrderDetails;