[1611] Create channel picker for draft order creation
This commit is contained in:
parent
a175fb9497
commit
cf7329ccce
6 changed files with 60 additions and 37 deletions
|
@ -3,16 +3,16 @@ import { storiesOf } from "@storybook/react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { channelsList } from "../../fixtures";
|
import { channelsList } from "../../fixtures";
|
||||||
import ChannelSettingsDialog, {
|
import ChannelPickerDialog, {
|
||||||
ChannelSettingsDialogProps
|
ChannelPickerDialogProps
|
||||||
} from "./ChannelSettingsDialog";
|
} from "./ChannelPickerDialog";
|
||||||
|
|
||||||
const channelsChoices = channelsList.map(channel => ({
|
const channelsChoices = channelsList.map(channel => ({
|
||||||
label: channel.name,
|
label: channel.name,
|
||||||
value: channel.id
|
value: channel.id
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const props: ChannelSettingsDialogProps = {
|
const props: ChannelPickerDialogProps = {
|
||||||
channelsChoices,
|
channelsChoices,
|
||||||
confirmButtonState: "default",
|
confirmButtonState: "default",
|
||||||
defaultChoice: channelsChoices[0]?.value,
|
defaultChoice: channelsChoices[0]?.value,
|
||||||
|
@ -23,4 +23,4 @@ const props: ChannelSettingsDialogProps = {
|
||||||
|
|
||||||
storiesOf("Views / Channels / Settings dialog", module)
|
storiesOf("Views / Channels / Settings dialog", module)
|
||||||
.addDecorator(Decorator)
|
.addDecorator(Decorator)
|
||||||
.add("default", () => <ChannelSettingsDialog {...props} />);
|
.add("default", () => <ChannelPickerDialog {...props} />);
|
|
@ -1,4 +1,3 @@
|
||||||
import Typography from "@material-ui/core/Typography";
|
|
||||||
import ActionDialog from "@saleor/components/ActionDialog";
|
import ActionDialog from "@saleor/components/ActionDialog";
|
||||||
import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
||||||
import {
|
import {
|
||||||
|
@ -6,11 +5,11 @@ import {
|
||||||
SingleSelectField
|
SingleSelectField
|
||||||
} from "@saleor/components/SingleSelectField";
|
} from "@saleor/components/SingleSelectField";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import { useStyles } from "../styles";
|
import { useStyles } from "../styles";
|
||||||
|
|
||||||
export interface ChannelSettingsDialogProps {
|
export interface ChannelPickerDialogProps {
|
||||||
channelsChoices: Choices;
|
channelsChoices: Choices;
|
||||||
confirmButtonState: ConfirmButtonTransitionState;
|
confirmButtonState: ConfirmButtonTransitionState;
|
||||||
defaultChoice: string;
|
defaultChoice: string;
|
||||||
|
@ -19,7 +18,7 @@ export interface ChannelSettingsDialogProps {
|
||||||
onConfirm: (choice: string) => void;
|
onConfirm: (choice: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ChannelSettingsDialog: React.FC<ChannelSettingsDialogProps> = ({
|
const ChannelPickerDialog: React.FC<ChannelPickerDialogProps> = ({
|
||||||
channelsChoices = [],
|
channelsChoices = [],
|
||||||
confirmButtonState,
|
confirmButtonState,
|
||||||
defaultChoice,
|
defaultChoice,
|
||||||
|
@ -40,23 +39,17 @@ const ChannelSettingsDialog: React.FC<ChannelSettingsDialogProps> = ({
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
onConfirm={() => onConfirm(choice)}
|
onConfirm={() => onConfirm(choice)}
|
||||||
title={intl.formatMessage({
|
title={intl.formatMessage({
|
||||||
defaultMessage: "Settings",
|
defaultMessage: "Select a channel",
|
||||||
description: "dialog header"
|
description: "dialog header"
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<Typography>
|
|
||||||
<FormattedMessage
|
|
||||||
defaultMessage="Configure the way information are presented in catalog section of Dashboard."
|
|
||||||
description="channel settings"
|
|
||||||
/>
|
|
||||||
</Typography>
|
|
||||||
<div className={classes.select}>
|
<div className={classes.select}>
|
||||||
<SingleSelectField
|
<SingleSelectField
|
||||||
choices={channelsChoices}
|
choices={channelsChoices}
|
||||||
name="channels"
|
name="channels"
|
||||||
label={intl.formatMessage({
|
label={intl.formatMessage({
|
||||||
defaultMessage: "Show prices for",
|
defaultMessage: "Channel name",
|
||||||
description: "select label"
|
description: "select label"
|
||||||
})}
|
})}
|
||||||
value={choice}
|
value={choice}
|
||||||
|
@ -67,5 +60,5 @@ const ChannelSettingsDialog: React.FC<ChannelSettingsDialogProps> = ({
|
||||||
</ActionDialog>
|
</ActionDialog>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
ChannelSettingsDialog.displayName = "ChannelSettingsDialog";
|
ChannelPickerDialog.displayName = "ChannelPickerDialog";
|
||||||
export default ChannelSettingsDialog;
|
export default ChannelPickerDialog;
|
2
src/channels/components/ChannelPickerDialog/index.ts
Normal file
2
src/channels/components/ChannelPickerDialog/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export * from "./ChannelPickerDialog";
|
||||||
|
export { default } from "./ChannelPickerDialog";
|
|
@ -1,2 +0,0 @@
|
||||||
export * from "./ChannelSettingsDialog";
|
|
||||||
export { default } from "./ChannelSettingsDialog";
|
|
|
@ -1,6 +1,7 @@
|
||||||
import DialogContentText from "@material-ui/core/DialogContentText";
|
import DialogContentText from "@material-ui/core/DialogContentText";
|
||||||
import IconButton from "@material-ui/core/IconButton";
|
import IconButton from "@material-ui/core/IconButton";
|
||||||
import DeleteIcon from "@material-ui/icons/Delete";
|
import DeleteIcon from "@material-ui/icons/Delete";
|
||||||
|
import ChannelPickerDialog from "@saleor/channels/components/ChannelPickerDialog";
|
||||||
import ActionDialog from "@saleor/components/ActionDialog";
|
import ActionDialog from "@saleor/components/ActionDialog";
|
||||||
import useAppChannel from "@saleor/components/AppLayout/AppChannelContext";
|
import useAppChannel from "@saleor/components/AppLayout/AppChannelContext";
|
||||||
import DeleteFilterTabDialog from "@saleor/components/DeleteFilterTabDialog";
|
import DeleteFilterTabDialog from "@saleor/components/DeleteFilterTabDialog";
|
||||||
|
@ -79,7 +80,10 @@ export const OrderDraftList: React.FC<OrderDraftListProps> = ({ params }) => {
|
||||||
onCompleted: handleCreateOrderCreateSuccess
|
onCompleted: handleCreateOrderCreateSuccess
|
||||||
});
|
});
|
||||||
|
|
||||||
const { channel } = useAppChannel();
|
const { channel, availableChannels } = useAppChannel();
|
||||||
|
const [channelPickerDialogOpen, setChannelPickerDialogOpen] = React.useState(
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
const tabs = getFilterTabs();
|
const tabs = getFilterTabs();
|
||||||
|
|
||||||
|
@ -196,13 +200,7 @@ export const OrderDraftList: React.FC<OrderDraftListProps> = ({ params }) => {
|
||||||
data.draftOrders.edges.map(edge => edge.node)
|
data.draftOrders.edges.map(edge => edge.node)
|
||||||
)}
|
)}
|
||||||
pageInfo={pageInfo}
|
pageInfo={pageInfo}
|
||||||
onAdd={() =>
|
onAdd={() => setChannelPickerDialogOpen(true)}
|
||||||
createOrder({
|
|
||||||
variables: {
|
|
||||||
input: { channel: channel.id }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
onNextPage={loadNextPage}
|
onNextPage={loadNextPage}
|
||||||
onPreviousPage={loadPreviousPage}
|
onPreviousPage={loadPreviousPage}
|
||||||
onRowClick={id => () => navigate(orderUrl(id))}
|
onRowClick={id => () => navigate(orderUrl(id))}
|
||||||
|
@ -263,6 +261,23 @@ export const OrderDraftList: React.FC<OrderDraftListProps> = ({ params }) => {
|
||||||
onSubmit={handleTabDelete}
|
onSubmit={handleTabDelete}
|
||||||
tabName={maybe(() => tabs[currentTab - 1].name, "...")}
|
tabName={maybe(() => tabs[currentTab - 1].name, "...")}
|
||||||
/>
|
/>
|
||||||
|
<ChannelPickerDialog
|
||||||
|
channelsChoices={availableChannels.map(channel => ({
|
||||||
|
label: channel.name,
|
||||||
|
value: channel.id
|
||||||
|
}))}
|
||||||
|
confirmButtonState="success"
|
||||||
|
defaultChoice={channel.id}
|
||||||
|
open={channelPickerDialogOpen}
|
||||||
|
onClose={() => setChannelPickerDialogOpen(false)}
|
||||||
|
onConfirm={channel =>
|
||||||
|
createOrder({
|
||||||
|
variables: {
|
||||||
|
input: { channel }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import ChannelPickerDialog from "@saleor/channels/components/ChannelPickerDialog";
|
||||||
import useAppChannel from "@saleor/components/AppLayout/AppChannelContext";
|
import useAppChannel from "@saleor/components/AppLayout/AppChannelContext";
|
||||||
import DeleteFilterTabDialog from "@saleor/components/DeleteFilterTabDialog";
|
import DeleteFilterTabDialog from "@saleor/components/DeleteFilterTabDialog";
|
||||||
import SaveFilterTabDialog, {
|
import SaveFilterTabDialog, {
|
||||||
|
@ -67,7 +68,10 @@ export const OrderList: React.FC<OrderListProps> = ({ params }) => {
|
||||||
onCompleted: handleCreateOrderCreateSuccess
|
onCompleted: handleCreateOrderCreateSuccess
|
||||||
});
|
});
|
||||||
|
|
||||||
const { channel } = useAppChannel();
|
const { channel, availableChannels } = useAppChannel();
|
||||||
|
const [channelPickerDialogOpen, setChannelPickerDialogOpen] = React.useState(
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
const tabs = getFilterTabs();
|
const tabs = getFilterTabs();
|
||||||
|
|
||||||
|
@ -145,13 +149,7 @@ export const OrderList: React.FC<OrderListProps> = ({ params }) => {
|
||||||
orders={maybe(() => data.orders.edges.map(edge => edge.node))}
|
orders={maybe(() => data.orders.edges.map(edge => edge.node))}
|
||||||
pageInfo={pageInfo}
|
pageInfo={pageInfo}
|
||||||
sort={getSortParams(params)}
|
sort={getSortParams(params)}
|
||||||
onAdd={() =>
|
onAdd={() => setChannelPickerDialogOpen(true)}
|
||||||
createOrder({
|
|
||||||
variables: {
|
|
||||||
input: { channel: channel.id }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
onNextPage={loadNextPage}
|
onNextPage={loadNextPage}
|
||||||
onPreviousPage={loadPreviousPage}
|
onPreviousPage={loadPreviousPage}
|
||||||
onUpdateListSettings={updateListSettings}
|
onUpdateListSettings={updateListSettings}
|
||||||
|
@ -179,6 +177,23 @@ export const OrderList: React.FC<OrderListProps> = ({ params }) => {
|
||||||
onSubmit={handleFilterTabDelete}
|
onSubmit={handleFilterTabDelete}
|
||||||
tabName={getStringOrPlaceholder(tabs[currentTab - 1]?.name)}
|
tabName={getStringOrPlaceholder(tabs[currentTab - 1]?.name)}
|
||||||
/>
|
/>
|
||||||
|
<ChannelPickerDialog
|
||||||
|
channelsChoices={availableChannels.map(channel => ({
|
||||||
|
label: channel.name,
|
||||||
|
value: channel.id
|
||||||
|
}))}
|
||||||
|
confirmButtonState="success"
|
||||||
|
defaultChoice={channel.id}
|
||||||
|
open={channelPickerDialogOpen}
|
||||||
|
onClose={() => setChannelPickerDialogOpen(false)}
|
||||||
|
onConfirm={channel =>
|
||||||
|
createOrder({
|
||||||
|
variables: {
|
||||||
|
input: { channel }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue