2023-02-20 15:21:28 +00:00
|
|
|
import { TopNav } from "@dashboard/components/AppLayout/TopNav";
|
2023-01-16 09:45:12 +00:00
|
|
|
import CardMenu from "@dashboard/components/CardMenu";
|
|
|
|
import CardSpacer from "@dashboard/components/CardSpacer";
|
|
|
|
import { DateTime } from "@dashboard/components/Date";
|
2023-02-28 09:33:16 +00:00
|
|
|
import { DetailPageLayout } from "@dashboard/components/Layouts";
|
2023-01-16 09:45:12 +00:00
|
|
|
import Savebar from "@dashboard/components/Savebar";
|
|
|
|
import Skeleton from "@dashboard/components/Skeleton";
|
2022-07-07 15:31:26 +00:00
|
|
|
import {
|
2022-08-10 09:11:32 +00:00
|
|
|
ChannelUsabilityDataQuery,
|
2022-07-07 15:31:26 +00:00
|
|
|
OrderDetailsFragment,
|
2022-08-10 09:11:32 +00:00
|
|
|
OrderErrorFragment,
|
2022-07-07 15:31:26 +00:00
|
|
|
OrderLineInput,
|
|
|
|
SearchCustomersQuery,
|
2023-01-16 09:45:12 +00:00
|
|
|
} from "@dashboard/graphql";
|
|
|
|
import { SubmitPromise } from "@dashboard/hooks/useForm";
|
|
|
|
import useNavigator from "@dashboard/hooks/useNavigator";
|
|
|
|
import OrderChannelSectionCard from "@dashboard/orders/components/OrderChannelSectionCard";
|
|
|
|
import { orderDraftListUrl } from "@dashboard/orders/urls";
|
|
|
|
import { FetchMoreProps, RelayToFlat } from "@dashboard/types";
|
|
|
|
import { Typography } from "@material-ui/core";
|
2022-08-10 09:11:32 +00:00
|
|
|
import { ConfirmButtonTransitionState } from "@saleor/macaw-ui";
|
2023-02-20 15:21:28 +00:00
|
|
|
import { Box } from "@saleor/macaw-ui/next";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
2021-05-06 11:38:15 +00:00
|
|
|
import OrderCustomer, { CustomerEditData } from "../OrderCustomer";
|
2019-06-19 14:40:52 +00:00
|
|
|
import OrderDraftDetails from "../OrderDraftDetails/OrderDraftDetails";
|
|
|
|
import OrderHistory, { FormData as HistoryFormData } from "../OrderHistory";
|
2022-08-10 09:11:32 +00:00
|
|
|
import OrderDraftAlert from "./OrderDraftAlert";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2022-03-01 08:38:23 +00:00
|
|
|
export interface OrderDraftPageProps extends FetchMoreProps {
|
2019-06-19 14:40:52 +00:00
|
|
|
disabled: boolean;
|
2022-08-10 09:11:32 +00:00
|
|
|
order?: OrderDetailsFragment;
|
|
|
|
channelUsabilityData?: ChannelUsabilityDataQuery;
|
2022-03-09 08:56:55 +00:00
|
|
|
users: RelayToFlat<SearchCustomersQuery["search"]>;
|
2019-06-19 14:40:52 +00:00
|
|
|
usersLoading: boolean;
|
2022-08-10 09:11:32 +00:00
|
|
|
errors: OrderErrorFragment[];
|
2019-06-19 14:40:52 +00:00
|
|
|
saveButtonBarState: ConfirmButtonTransitionState;
|
|
|
|
fetchUsers: (query: string) => void;
|
|
|
|
onBillingAddressEdit: () => void;
|
2021-05-06 11:38:15 +00:00
|
|
|
onCustomerEdit: (data: CustomerEditData) => void;
|
2019-06-19 14:40:52 +00:00
|
|
|
onDraftFinalize: () => void;
|
|
|
|
onDraftRemove: () => void;
|
2022-02-01 09:58:06 +00:00
|
|
|
onNoteAdd: (data: HistoryFormData) => SubmitPromise<any[]>;
|
2019-06-19 14:40:52 +00:00
|
|
|
onOrderLineAdd: () => void;
|
2022-07-07 15:31:26 +00:00
|
|
|
onOrderLineChange: (id: string, data: OrderLineInput) => void;
|
2019-06-19 14:40:52 +00:00
|
|
|
onOrderLineRemove: (id: string) => void;
|
|
|
|
onProductClick: (id: string) => void;
|
|
|
|
onShippingAddressEdit: () => void;
|
|
|
|
onShippingMethodEdit: () => void;
|
|
|
|
onProfileView: () => void;
|
|
|
|
}
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const OrderDraftPage: React.FC<OrderDraftPageProps> = props => {
|
|
|
|
const {
|
2019-06-19 14:40:52 +00:00
|
|
|
disabled,
|
|
|
|
fetchUsers,
|
2019-10-15 12:17:35 +00:00
|
|
|
hasMore,
|
2019-06-19 14:40:52 +00:00
|
|
|
saveButtonBarState,
|
|
|
|
onBillingAddressEdit,
|
|
|
|
onCustomerEdit,
|
|
|
|
onDraftFinalize,
|
|
|
|
onDraftRemove,
|
2019-10-15 12:17:35 +00:00
|
|
|
onFetchMore,
|
2019-06-19 14:40:52 +00:00
|
|
|
onNoteAdd,
|
|
|
|
onOrderLineAdd,
|
|
|
|
onOrderLineChange,
|
|
|
|
onOrderLineRemove,
|
|
|
|
onShippingAddressEdit,
|
|
|
|
onShippingMethodEdit,
|
|
|
|
onProfileView,
|
|
|
|
order,
|
2022-08-10 09:11:32 +00:00
|
|
|
channelUsabilityData,
|
2019-06-19 14:40:52 +00:00
|
|
|
users,
|
2022-06-21 09:36:55 +00:00
|
|
|
usersLoading,
|
2022-08-10 09:11:32 +00:00
|
|
|
errors,
|
2019-10-30 14:34:24 +00:00
|
|
|
} = props;
|
2022-05-06 08:59:55 +00:00
|
|
|
const navigate = useNavigator();
|
2019-10-30 14:34:24 +00:00
|
|
|
|
|
|
|
const intl = useIntl();
|
2019-08-26 17:44:42 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
return (
|
2023-02-28 09:33:16 +00:00
|
|
|
<DetailPageLayout>
|
2023-02-20 15:21:28 +00:00
|
|
|
<TopNav
|
|
|
|
href={orderDraftListUrl()}
|
|
|
|
title={
|
|
|
|
<Box display="flex" alignItems="center" gap={6}>
|
|
|
|
<span>{order?.number ? "#" + order?.number : undefined}</span>
|
|
|
|
<div>
|
|
|
|
{order && order.created ? (
|
|
|
|
<Typography variant="body2">
|
|
|
|
<DateTime date={order.created} plain />
|
|
|
|
</Typography>
|
|
|
|
) : (
|
|
|
|
<Skeleton style={{ width: "10em" }} />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Box>
|
|
|
|
}
|
2019-10-30 14:34:24 +00:00
|
|
|
>
|
|
|
|
<CardMenu
|
|
|
|
menuItems={[
|
|
|
|
{
|
|
|
|
label: intl.formatMessage({
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "PAqicb",
|
2019-10-30 14:34:24 +00:00
|
|
|
defaultMessage: "Cancel order",
|
2022-06-21 09:36:55 +00:00
|
|
|
description: "button",
|
2019-10-30 14:34:24 +00:00
|
|
|
}),
|
2022-06-21 09:36:55 +00:00
|
|
|
onSelect: onDraftRemove,
|
|
|
|
},
|
2019-10-30 14:34:24 +00:00
|
|
|
]}
|
|
|
|
/>
|
2023-02-20 15:21:28 +00:00
|
|
|
</TopNav>
|
2023-02-28 09:33:16 +00:00
|
|
|
<DetailPageLayout.Content>
|
2023-02-20 15:21:28 +00:00
|
|
|
<OrderDraftAlert
|
|
|
|
order={order}
|
|
|
|
channelUsabilityData={channelUsabilityData}
|
|
|
|
/>
|
|
|
|
<OrderDraftDetails
|
|
|
|
order={order}
|
|
|
|
channelUsabilityData={channelUsabilityData}
|
|
|
|
errors={errors}
|
|
|
|
onOrderLineAdd={onOrderLineAdd}
|
|
|
|
onOrderLineChange={onOrderLineChange}
|
|
|
|
onOrderLineRemove={onOrderLineRemove}
|
|
|
|
onShippingMethodEdit={onShippingMethodEdit}
|
|
|
|
/>
|
|
|
|
<OrderHistory
|
|
|
|
history={order?.events}
|
|
|
|
orderCurrency={order?.total?.gross.currency}
|
|
|
|
onNoteAdd={onNoteAdd}
|
|
|
|
/>
|
2023-02-28 09:33:16 +00:00
|
|
|
</DetailPageLayout.Content>
|
|
|
|
<DetailPageLayout.RightSidebar>
|
2023-02-20 15:21:28 +00:00
|
|
|
<OrderChannelSectionCard channel={order?.channel} />
|
|
|
|
<CardSpacer />
|
|
|
|
<OrderCustomer
|
|
|
|
canEditAddresses={!!order?.user}
|
|
|
|
canEditCustomer={true}
|
|
|
|
fetchUsers={fetchUsers}
|
|
|
|
hasMore={hasMore}
|
|
|
|
loading={usersLoading}
|
|
|
|
errors={errors}
|
|
|
|
order={order}
|
|
|
|
users={users}
|
|
|
|
onBillingAddressEdit={onBillingAddressEdit}
|
|
|
|
onCustomerEdit={onCustomerEdit}
|
|
|
|
onFetchMore={onFetchMore}
|
|
|
|
onProfileView={onProfileView}
|
|
|
|
onShippingAddressEdit={onShippingAddressEdit}
|
|
|
|
/>
|
2023-02-28 09:33:16 +00:00
|
|
|
</DetailPageLayout.RightSidebar>
|
2021-07-21 08:59:52 +00:00
|
|
|
<Savebar
|
2019-10-30 14:34:24 +00:00
|
|
|
state={saveButtonBarState}
|
2022-08-10 09:11:32 +00:00
|
|
|
disabled={disabled}
|
2022-05-06 08:59:55 +00:00
|
|
|
onCancel={() => navigate(orderDraftListUrl())}
|
2021-07-21 08:59:52 +00:00
|
|
|
onSubmit={onDraftFinalize}
|
2019-10-30 14:34:24 +00:00
|
|
|
labels={{
|
2021-07-21 08:59:52 +00:00
|
|
|
confirm: intl.formatMessage({
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "4Z14xW",
|
2019-10-30 14:34:24 +00:00
|
|
|
defaultMessage: "Finalize",
|
2022-06-21 09:36:55 +00:00
|
|
|
description: "button",
|
|
|
|
}),
|
2019-10-30 14:34:24 +00:00
|
|
|
}}
|
|
|
|
/>
|
2023-02-28 09:33:16 +00:00
|
|
|
</DetailPageLayout>
|
2019-10-30 14:34:24 +00:00
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
OrderDraftPage.displayName = "OrderDraftPage";
|
|
|
|
export default OrderDraftPage;
|