Skip to content

Commit

Permalink
Fix promotion rule channel select (#4669)
Browse files Browse the repository at this point in the history
* Replace Select with combobox for channel input

* Add changeset
  • Loading branch information
poulch committed Feb 12, 2024
1 parent 465aa7b commit a3b365b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-hotels-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Use Combobox component instead of Select in promotion rule channel input
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Combobox } from "@dashboard/components/Combobox";
import { createEmptyCodition, Rule } from "@dashboard/discounts/models";
import { RewardValueTypeEnum } from "@dashboard/graphql";
import { ChangeEvent } from "@dashboard/hooks/useForm";
import { commonMessages } from "@dashboard/intl";
import { getFormErrors } from "@dashboard/utils/errors";
import {
Expand All @@ -8,7 +10,7 @@ import {
} from "@dashboard/utils/errors/common";
import { RichTextContext } from "@dashboard/utils/richText/context";
import useRichText from "@dashboard/utils/richText/useRichText";
import { Box, Input, Option, Select } from "@saleor/macaw-ui-next";
import { Box, Input, Option } from "@saleor/macaw-ui-next";
import React, { useEffect, useMemo } from "react";
import { useController, useFormContext } from "react-hook-form";
import { useIntl } from "react-intl";
Expand Down Expand Up @@ -71,8 +73,17 @@ export const RuleForm = <ErrorCode,>({
}
}, [currencySymbol]);

const handleChannelChange = (selectedChannel: Option) => {
setValue("channel", selectedChannel, { shouldValidate: true });
const handleChannelChange = (e: ChangeEvent) => {
const channelId = e.target.value;
const channel = channels.find(channel => channel.id === channelId);

if (channel) {
setValue(
"channel",
{ value: channel.id, label: channel.name },
{ shouldValidate: true },
);
}

if (conditions.length > 0) {
setValue("conditions", [createEmptyCodition()]);
Expand All @@ -98,9 +109,10 @@ export const RuleForm = <ErrorCode,>({
</RuleInputWrapper>

<RuleInputWrapper __flex={1}>
<Select
<Combobox
{...channelfield}
onChange={handleChannelChange}
fetchOptions={() => {}}
size="small"
data-test-id="channel-dropdown"
label={intl.formatMessage(commonMessages.channel)}
Expand Down

0 comments on commit a3b365b

Please sign in to comment.