saleor-dashboard/src/orders/components/OrderDraftPage/OrderDraftPage.tsx

171 lines
5.4 KiB
TypeScript
Raw Normal View History

import { TopNav } from "@dashboard/components/AppLayout/TopNav";
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";
import Savebar from "@dashboard/components/Savebar";
import Skeleton from "@dashboard/components/Skeleton";
import {
ChannelUsabilityDataQuery,
OrderDetailsFragment,
OrderErrorFragment,
OrderLineInput,
SearchCustomersQuery,
} 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";
import { ConfirmButtonTransitionState } from "@saleor/macaw-ui";
import { Box } from "@saleor/macaw-ui/next";
import React from "react";
import { useIntl } from "react-intl";
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";
import OrderDraftAlert from "./OrderDraftAlert";
2019-06-19 14:40:52 +00:00
export interface OrderDraftPageProps extends FetchMoreProps {
2019-06-19 14:40:52 +00:00
disabled: boolean;
order?: OrderDetailsFragment;
channelUsabilityData?: ChannelUsabilityDataQuery;
Use graphql-codegen (#1874) * Use generated hooks in apps * Remove unused files * Use proper types in apps * Use generated hooks in attributes * Use generated hooks in auth module * Use generated hooks in categories * Use generated hooks in channels * Use generated types in collections * Remove legacy types from background tasks * Use generated hooks in customers * Use generated hooks in discounts * Use generated hook in file upload * Use generated types in gift cards * Use generated types in home * Use generated hooks in navigation * Use generated hooks in orders * Use generated hooks in pages * Use generated hooks in page types * Use generated hooks in permission groups * Use generated hooks in plugins * Use generated hooks in products * Use fragment to mark product variants * Improve code a bit * Use generated hooks in page types * Use generated types in searches * Use generated hooks in shipping * Use generated hooks in site settings * Use generated hooks in staff members * Use generated hooks in taxes * Place all gql generated files in one directory * Use generated hooks in translations * Use global types from new generated module * Use generated hooks in warehouses * Use generated hooks in webhooks * Use generated fragment types * Unclutter types * Remove hoc components * Split hooks and types * Fetch introspection file * Delete obsolete schema file * Fix rebase artifacts * Fix autoreplace * Fix auth provider tests * Fix urls * Remove leftover types * Fix rebase artifacts
2022-03-09 08:56:55 +00:00
users: RelayToFlat<SearchCustomersQuery["search"]>;
2019-06-19 14:40:52 +00:00
usersLoading: boolean;
errors: OrderErrorFragment[];
2019-06-19 14:40:52 +00:00
saveButtonBarState: ConfirmButtonTransitionState;
fetchUsers: (query: string) => void;
onBillingAddressEdit: () => void;
onCustomerEdit: (data: CustomerEditData) => void;
2019-06-19 14:40:52 +00:00
onDraftFinalize: () => void;
onDraftRemove: () => void;
Exit dirty form (#1816) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Fixes after review * Add default value for useform prop opts so the app doesn't crash * Add missing category prop to getting initial data for category details form * Add exit dialog to everywhere WIP (#1600) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Add CommonUseFormResultWithHandlers type for later use and refactor handleFormSubmit util * Refactor login form not to use custom form since it doesn't need to * Add exit form dialog to order refund page * Add exit form dialog to order return page * Add exit form dialog to order order settings page * Add exit form dialog to product variant page * Add exit form dialog to product create page * Add exit form dialog to product update page * Add exit form dialog to product variant create page * Fix confirm leave prop passing in generic Form * Add util function to handle for submit to extract errors * Add confirmLeave prop to generic forms * Move handleChange for custom forms to useForm * Add exit dialog to more forms * Add extract mutation errors util function * Add extracting errors to submit functions that use metadata create handler * Fix typo * Add missing category prop to getting initial data for category details form * Fix types * wip * wip * wip * wip * Fix types & refactor * Fix types & refactor * Fix typescript * Fix unmatching tag * Fixes * Add handling of multiple forms at once to exit dirty form provider * Change all usages of ExitFormDialogContext to designated hook * wip * wip * wip * Fix types wip * Fix types * Remove console logs * Add isSubmitting prop to exit form dialog in order to avoid enabling exit dialog while submit is still in progresS * Replace handleSubmit global util with a hook to use exit form dialog props inside * Move useHandleSubmit to general hooks dir, update imports * Small fixes * Update snapshots * Fix types * Small fixes due to extensive rebase * Update package lock * Fixes after rebase * Remove exit form from customer address dialog * Fix types and update messages * Fix types * Change imports names * Refactor * Remove unnecessary console.log * Update types, snapshots. etc after rebase
2022-02-01 09:58:06 +00:00
onNoteAdd: (data: HistoryFormData) => SubmitPromise<any[]>;
2019-06-19 14:40:52 +00:00
onOrderLineAdd: () => void;
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,
channelUsabilityData,
2019-06-19 14:40:52 +00:00
users,
usersLoading,
errors,
2019-10-30 14:34:24 +00:00
} = props;
const navigate = useNavigator();
2019-10-30 14:34:24 +00:00
const intl = useIntl();
2019-10-30 14:34:24 +00:00
return (
2023-02-28 09:33:16 +00:00
<DetailPageLayout>
<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({
id: "PAqicb",
2019-10-30 14:34:24 +00:00
defaultMessage: "Cancel order",
description: "button",
2019-10-30 14:34:24 +00:00
}),
onSelect: onDraftRemove,
},
2019-10-30 14:34:24 +00:00
]}
/>
</TopNav>
2023-02-28 09:33:16 +00:00
<DetailPageLayout.Content>
<OrderDraftAlert
order={order as OrderDetailsFragment}
channelUsabilityData={channelUsabilityData}
/>
<OrderDraftDetails
order={order as OrderDetailsFragment}
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>
<OrderChannelSectionCard channel={order?.channel} />
<CardSpacer />
<OrderCustomer
canEditAddresses={!!order?.user}
canEditCustomer={true}
fetchUsers={fetchUsers}
hasMore={hasMore}
loading={usersLoading}
errors={errors}
order={order as OrderDetailsFragment}
users={users}
onBillingAddressEdit={onBillingAddressEdit}
onCustomerEdit={onCustomerEdit}
onFetchMore={onFetchMore}
onProfileView={onProfileView}
onShippingAddressEdit={onShippingAddressEdit}
/>
2023-02-28 09:33:16 +00:00
</DetailPageLayout.RightSidebar>
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
<Savebar
2019-10-30 14:34:24 +00:00
state={saveButtonBarState}
disabled={disabled}
onCancel={() => navigate(orderDraftListUrl())}
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
onSubmit={onDraftFinalize}
2019-10-30 14:34:24 +00:00
labels={{
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
confirm: intl.formatMessage({
id: "4Z14xW",
2019-10-30 14:34:24 +00:00
defaultMessage: "Finalize",
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;