
* Refactor changing address in order details directly (#1697) * wip change address edit buttons behaviour in order draft * wip modify dialog view when customer is not changed * wip remove old address edit modal * wip rm old address modal storybook * wip async search state change * wip disable edit in draft when no customer is selected * wip fix submitting issues * wip allow single address mutation * wip fix billing change & manual address change * wip fix covered country dropdown * wip add address clone checkbox * wip normal order details & unconfirmed views * wip messages minor fixes * wip clone address checkbox on new address input option * Storybook update * cleanup * billing same as shipping fixes * improve stories titles & move to component folder * improve continueToAddressSearchState readibility * improve dialog title/description message descriptors * change .then() to await * Remove redundant onClick arrow function Co-authored-by: Dominik Żegleń <flesz3@o2.pl> * Improve OrderAddressFields component * move shipping & billing address edit props outside file * Update snapshots * fix mutation output types in order views * Fix confirm button state type * fix skipping query when modal is refreshed * fix cancel button to match designs * update dialog headers * fix customer address choice card styling for blue theme * change hidecard to showcard * export types to local file * improve isAnyAddressEditModalOpen function * fix cut hover effect on inputs * fix submitting modal when modal is closed with x button * fix validation & initial form data * update messages * Update partial mutation return type * Add vertical spacer component * Revert CardSpacer changes * Change some of Form & Card spacers to Vertical Spacers * Fix makeStyles import in VerticalSpacer * Fix border color for AddressCards * Add type to addressFieldsCommonProps object * Change stories subtitles to lowercase * Fix country choices type * Fix setState react type * Improve address change handlers * Update snapshots * Fix default country not showing up in address edit single autocomplete field Co-authored-by: Dominik Żegleń <flesz3@o2.pl> Co-authored-by: Magdalena Markusik <magdalena.markusik@mirumee.com> * Fix linter issue Co-authored-by: Dominik Żegleń <flesz3@o2.pl> Co-authored-by: Magdalena Markusik <magdalena.markusik@mirumee.com>
177 lines
5.3 KiB
TypeScript
177 lines
5.3 KiB
TypeScript
import { Typography } from "@material-ui/core";
|
|
import CardMenu from "@saleor/components/CardMenu";
|
|
import CardSpacer from "@saleor/components/CardSpacer";
|
|
import { Container } from "@saleor/components/Container";
|
|
import { DateTime } from "@saleor/components/Date";
|
|
import Grid from "@saleor/components/Grid";
|
|
import PageHeader from "@saleor/components/PageHeader";
|
|
import Savebar from "@saleor/components/Savebar";
|
|
import Skeleton from "@saleor/components/Skeleton";
|
|
import { SubmitPromise } from "@saleor/hooks/useForm";
|
|
import { sectionNames } from "@saleor/intl";
|
|
import { ConfirmButtonTransitionState } from "@saleor/macaw-ui";
|
|
import { Backlink } from "@saleor/macaw-ui";
|
|
import { makeStyles } from "@saleor/macaw-ui";
|
|
import DraftOrderChannelSectionCard from "@saleor/orders/components/DraftOrderChannelSectionCard";
|
|
import { SearchCustomers_search_edges_node } from "@saleor/searches/types/SearchCustomers";
|
|
import { FetchMoreProps, UserPermissionProps } from "@saleor/types";
|
|
import React from "react";
|
|
import { useIntl } from "react-intl";
|
|
|
|
import { OrderDetails_order } from "../../types/OrderDetails";
|
|
import OrderCustomer, { CustomerEditData } from "../OrderCustomer";
|
|
import OrderDraftDetails from "../OrderDraftDetails/OrderDraftDetails";
|
|
import { FormData as OrderDraftDetailsProductsFormData } from "../OrderDraftDetailsProducts";
|
|
import OrderHistory, { FormData as HistoryFormData } from "../OrderHistory";
|
|
|
|
const useStyles = makeStyles(
|
|
theme => ({
|
|
date: {
|
|
marginBottom: theme.spacing(3)
|
|
},
|
|
header: {
|
|
display: "flex",
|
|
marginBottom: 0
|
|
}
|
|
}),
|
|
{ name: "OrderDraftPage" }
|
|
);
|
|
|
|
export interface OrderDraftPageProps
|
|
extends FetchMoreProps,
|
|
UserPermissionProps {
|
|
disabled: boolean;
|
|
order: OrderDetails_order;
|
|
users: SearchCustomers_search_edges_node[];
|
|
usersLoading: boolean;
|
|
saveButtonBarState: ConfirmButtonTransitionState;
|
|
fetchUsers: (query: string) => void;
|
|
onBack: () => void;
|
|
onBillingAddressEdit: () => void;
|
|
onCustomerEdit: (data: CustomerEditData) => void;
|
|
onDraftFinalize: () => void;
|
|
onDraftRemove: () => void;
|
|
onNoteAdd: (data: HistoryFormData) => SubmitPromise<any[]>;
|
|
onOrderLineAdd: () => void;
|
|
onOrderLineChange: (
|
|
id: string,
|
|
data: OrderDraftDetailsProductsFormData
|
|
) => void;
|
|
onOrderLineRemove: (id: string) => void;
|
|
onProductClick: (id: string) => void;
|
|
onShippingAddressEdit: () => void;
|
|
onShippingMethodEdit: () => void;
|
|
onProfileView: () => void;
|
|
}
|
|
|
|
const OrderDraftPage: React.FC<OrderDraftPageProps> = props => {
|
|
const {
|
|
disabled,
|
|
fetchUsers,
|
|
hasMore,
|
|
saveButtonBarState,
|
|
onBack,
|
|
onBillingAddressEdit,
|
|
onCustomerEdit,
|
|
onDraftFinalize,
|
|
onDraftRemove,
|
|
onFetchMore,
|
|
onNoteAdd,
|
|
onOrderLineAdd,
|
|
onOrderLineChange,
|
|
onOrderLineRemove,
|
|
onShippingAddressEdit,
|
|
onShippingMethodEdit,
|
|
onProfileView,
|
|
order,
|
|
users,
|
|
usersLoading,
|
|
userPermissions
|
|
} = props;
|
|
const classes = useStyles(props);
|
|
|
|
const intl = useIntl();
|
|
|
|
return (
|
|
<Container>
|
|
<Backlink onClick={onBack}>
|
|
{intl.formatMessage(sectionNames.draftOrders)}
|
|
</Backlink>
|
|
<PageHeader
|
|
className={classes.header}
|
|
inline
|
|
title={order?.number ? "#" + order?.number : undefined}
|
|
>
|
|
<CardMenu
|
|
menuItems={[
|
|
{
|
|
label: intl.formatMessage({
|
|
defaultMessage: "Cancel order",
|
|
description: "button"
|
|
}),
|
|
onSelect: onDraftRemove
|
|
}
|
|
]}
|
|
/>
|
|
</PageHeader>
|
|
<div className={classes.date}>
|
|
{order && order.created ? (
|
|
<Typography variant="body2">
|
|
<DateTime date={order.created} />
|
|
</Typography>
|
|
) : (
|
|
<Skeleton style={{ width: "10em" }} />
|
|
)}
|
|
</div>
|
|
<Grid>
|
|
<div>
|
|
<OrderDraftDetails
|
|
order={order}
|
|
onOrderLineAdd={onOrderLineAdd}
|
|
onOrderLineChange={onOrderLineChange}
|
|
onOrderLineRemove={onOrderLineRemove}
|
|
onShippingMethodEdit={onShippingMethodEdit}
|
|
/>
|
|
<OrderHistory
|
|
history={order?.events}
|
|
orderCurrency={order?.total?.gross.currency}
|
|
onNoteAdd={onNoteAdd}
|
|
/>
|
|
</div>
|
|
<div>
|
|
<OrderCustomer
|
|
canEditAddresses={!!order?.user}
|
|
canEditCustomer={true}
|
|
fetchUsers={fetchUsers}
|
|
hasMore={hasMore}
|
|
loading={usersLoading}
|
|
order={order}
|
|
users={users}
|
|
userPermissions={userPermissions}
|
|
onBillingAddressEdit={onBillingAddressEdit}
|
|
onCustomerEdit={onCustomerEdit}
|
|
onFetchMore={onFetchMore}
|
|
onProfileView={onProfileView}
|
|
onShippingAddressEdit={onShippingAddressEdit}
|
|
/>
|
|
<CardSpacer />
|
|
<DraftOrderChannelSectionCard channelName={order?.channel?.name} />
|
|
</div>
|
|
</Grid>
|
|
<Savebar
|
|
state={saveButtonBarState}
|
|
disabled={disabled || !order?.canFinalize}
|
|
onCancel={onBack}
|
|
onSubmit={onDraftFinalize}
|
|
labels={{
|
|
confirm: intl.formatMessage({
|
|
defaultMessage: "Finalize",
|
|
description: "button"
|
|
})
|
|
}}
|
|
/>
|
|
</Container>
|
|
);
|
|
};
|
|
OrderDraftPage.displayName = "OrderDraftPage";
|
|
export default OrderDraftPage;
|