2021-02-02 09:38:43 +00:00
|
|
|
import { ChannelFragment } from "@saleor/fragments/types/ChannelFragment";
|
2021-07-21 08:59:52 +00:00
|
|
|
import { makeStyles } from "@saleor/macaw-ui";
|
2020-11-23 09:39:24 +00:00
|
|
|
import { ChannelProps } from "@saleor/types";
|
|
|
|
import { mapNodeToChoice } from "@saleor/utils/maps";
|
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import SingleSelectField from "../SingleSelectField";
|
|
|
|
|
|
|
|
const useStyles = makeStyles(
|
|
|
|
theme => ({
|
|
|
|
root: {
|
|
|
|
"&& fieldset": {
|
|
|
|
borderColor: theme.palette.divider
|
|
|
|
},
|
|
|
|
marginRight: theme.spacing(2),
|
|
|
|
width: 192
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
name: "AppChannelSelect"
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export interface AppChannelSelectProps extends ChannelProps {
|
2021-02-02 09:38:43 +00:00
|
|
|
channels: ChannelFragment[];
|
2020-11-23 09:39:24 +00:00
|
|
|
disabled: boolean;
|
|
|
|
onChannelSelect: (id: string) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const AppChannelSelect: React.FC<AppChannelSelectProps> = ({
|
|
|
|
channels,
|
|
|
|
disabled,
|
|
|
|
onChannelSelect,
|
|
|
|
selectedChannelId
|
|
|
|
}) => {
|
|
|
|
const classes = useStyles({});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classes.root}>
|
|
|
|
<SingleSelectField
|
2021-01-26 10:21:54 +00:00
|
|
|
testId="app-channel-select"
|
2020-11-23 09:39:24 +00:00
|
|
|
choices={mapNodeToChoice(channels)}
|
|
|
|
disabled={disabled}
|
|
|
|
value={selectedChannelId}
|
|
|
|
onChange={event => onChannelSelect(event.target.value)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
AppChannelSelect.displayName = "AppChannelSelect";
|
|
|
|
export default AppChannelSelect;
|