Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Enable user changing

dominik-zeglen062b9baa14ad
diff --git a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
index ec226a4897..877df2a141 100644
--- a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
@@ -24,7 +24,12 @@ export interface OrderCustomerProps {
loading?: boolean;
canEditCustomer: boolean;
fetchUsers?: (query: string) => void;
- onCustomerEdit?: () => void;
+ onCustomerEdit?: (
+ data: {
+ user?: string;
+ userEmail?: string;
+ }
+ ) => void;
onBillingAddressEdit?: () => void;
onShippingAddressEdit?: () => void;
}
@@ -90,39 +95,37 @@ const OrderCustomer = decorate<OrderCustomerProps>(
<CardContent>
{user === undefined ? (
<Skeleton />
+ ) : editMode && canEditCustomer ? (
+ <Form initial={{ query: { label: "", value: "" } }}>
+ {({ change, data }) => {
+ const handleChange = (event: React.ChangeEvent<any>) => {
+ change(event);
+ onCustomerEdit({
+ [event.target.value.value.includes("@")
+ ? "userEmail"
+ : "user"]: event.target.value.value
+ });
+ toggleEditMode();
+ };
+ return (
+ <SingleAutocompleteSelectField
+ custom={true}
+ choices={maybe(() => users, []).map(user => ({
+ label: user.email,
+ value: user.id
+ }))}
+ fetchChoices={fetchUsers}
+ loading={loading}
+ placeholder={i18n.t("Search Customers")}
+ onChange={handleChange}
+ name="query"
+ value={data.query}
+ />
+ );
+ }}
+ </Form>
) : user === null ? (
- editMode && canEditCustomer ? (
- <Form
- initial={{ query: { label: "", value: "" } }}
- onSubmit={onCustomerEdit}
- >
- {({ change, data, submit }) => {
- const handleChange = (
- event: React.ChangeEvent<any>
- ) => {
- change(event);
- submit();
- };
- return (
- <SingleAutocompleteSelectField
- custom={true}
- choices={maybe(() => users, []).map(user => ({
- label: user.email,
- value: user.id
- }))}
- fetchChoices={fetchUsers}
- loading={loading}
- placeholder={i18n.t("Search Customers")}
- onChange={handleChange}
- name="query"
- value={data.query}
- />
- );
- }}
- </Form>
- ) : (
- <Typography>{i18n.t("Anonymous user")}</Typography>
- )
+ <Typography>{i18n.t("Anonymous user")}</Typography>
) : (
<>
<Typography className={classes.userEmail}>
diff --git a/saleor/static/dashboard-next/orders/views/OrderDetails.tsx b/saleor/static/dashboard-next/orders/views/OrderDetails.tsx
index c8c76cf15f..9d76521fff 100644
--- a/saleor/static/dashboard-next/orders/views/OrderDetails.tsx
+++ b/saleor/static/dashboard-next/orders/views/OrderDetails.tsx
@@ -316,6 +316,7 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
orderAddNote,
orderCancel,
orderCreateFulfillment,
+ orderDraftUpdate,
orderLineAdd,
orderLineDelete,
orderLineUpdate,
@@ -474,7 +475,9 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
variantsLoading={searchOpts.loading}
fetchUsers={users.search}
usersLoading={users.searchOpts.loading}
- onCustomerEdit={() => undefined}
+ onCustomerEdit={data =>
+ orderDraftUpdate.mutate({ id, input: data })
+ }
onDraftFinalize={() => undefined}
onDraftRemove={() => undefined}
onOrderLineAdd={variables =>