diff --git a/.changeset/quick-items-march.md b/.changeset/quick-items-march.md new file mode 100644 index 0000000000000..d5e91bd448c2b --- /dev/null +++ b/.changeset/quick-items-march.md @@ -0,0 +1,6 @@ +--- +"@medusajs/ui": patch +"@medusajs/dashboard": patch +--- + +fix(dashboard,ui): Bring ConditionBlock in line with design diff --git a/packages/admin/dashboard/src/components/inputs/combobox/combobox.tsx b/packages/admin/dashboard/src/components/inputs/combobox/combobox.tsx index e1670cea9629e..6302f036c71d6 100644 --- a/packages/admin/dashboard/src/components/inputs/combobox/combobox.tsx +++ b/packages/admin/dashboard/src/components/inputs/combobox/combobox.tsx @@ -9,6 +9,7 @@ import { Separator as PrimitiveSeparator, } from "@ariakit/react" import { + CheckMini, EllipseMiniSolid, PlusMini, TrianglesMini, @@ -290,7 +291,7 @@ const ComboboxImpl = ( ref={comboboxRef} onFocus={() => setOpen(true)} className={clx( - "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-subtle transition-fg size-full cursor-pointer bg-transparent pl-2 pr-8 outline-none focus:cursor-text", + "txt-compact-small text-ui-fg-base !placeholder:text-ui-fg-muted transition-fg size-full cursor-pointer bg-transparent pl-2 pr-8 outline-none focus:cursor-text", "hover:bg-ui-bg-field-hover", { "opacity-0": hideInput, @@ -349,7 +350,7 @@ const ComboboxImpl = ( )} > - + {isArrayValue ? : } {label} diff --git a/packages/admin/dashboard/src/routes/promotions/common/edit-rules/components/rule-value-form-field/rule-value-form-field.tsx b/packages/admin/dashboard/src/routes/promotions/common/edit-rules/components/rule-value-form-field/rule-value-form-field.tsx index 530fb5732b258..a86618fb7c7c0 100644 --- a/packages/admin/dashboard/src/routes/promotions/common/edit-rules/components/rule-value-form-field/rule-value-form-field.tsx +++ b/packages/admin/dashboard/src/routes/promotions/common/edit-rules/components/rule-value-form-field/rule-value-form-field.tsx @@ -1,6 +1,6 @@ import { RuleAttributeOptionsResponse, StoreDTO } from "@medusajs/types" import { Input, Select } from "@medusajs/ui" -import { RefCallBack, useWatch } from "react-hook-form" +import { useWatch } from "react-hook-form" import { Form } from "../../../../../../components/common/form" import { Combobox } from "../../../../../../components/inputs/combobox" import { usePromotionRuleValues } from "../../../../../../hooks/api/promotions" @@ -13,9 +13,8 @@ type RuleValueFormFieldType = { | "application_method.buy_rules" | "rules" | "application_method.target_rules" - valuesField: any - operatorsField: any - valuesRef: RefCallBack + name: string + operator: string fieldRule: any attributes: RuleAttributeOptionsResponse[] ruleType: "rules" | "target-rules" | "buy-rules" @@ -39,9 +38,8 @@ export const RuleValueFormField = ({ form, identifier, scope, - valuesField, - operatorsField, - valuesRef, + name, + operator, fieldRule, attributes, ruleType, @@ -65,13 +63,13 @@ export const RuleValueFormField = ({ const watchOperator = useWatch({ control: form.control, - name: operatorsField.name, + name: operator, }) return ( { if (attribute?.field_type === "number") { return ( @@ -82,7 +80,7 @@ export const RuleValueFormField = ({ type="number" onChange={onChange} className="bg-ui-bg-base" - ref={valuesRef} + ref={ref} min={1} disabled={!fieldRule.attribute} /> @@ -96,6 +94,7 @@ export const RuleValueFormField = ({ @@ -116,24 +130,16 @@ export const RulesFormField = ({ {fields.map((fieldRule: any, index) => { const identifier = fieldRule.id - const { ref: attributeRef, ...attributeField } = form.register( - `${scope}.${index}.attribute` - ) - const { ref: operatorRef, ...operatorsField } = form.register( - `${scope}.${index}.operator` - ) - const { ref: valuesRef, ...valuesField } = form.register( - `${scope}.${index}.values` - ) return (
{ + name={`${scope}.${index}.attribute`} + render={({ field }) => { + const { onChange, ref, ...fieldProps } = field + const existingAttributes = fields?.map((field: any) => field.attribute) || [] const attributeOptions = @@ -145,55 +151,71 @@ export const RulesFormField = ({ return !existingAttributes.includes(attr.value) }) || [] + const disabled = !!fieldRule.required + const onValueChange = (e: string) => { + const currentAttributeOption = attributeOptions.find( + (ao) => ao.id === e + ) + + update(index, { + ...fieldRule, + values: [], + disguised: currentAttributeOption?.disguised || false, + }) + onChange(e) + } + return ( {fieldRule.required && ( -

- {t("promotions.form.required")} -

+
+

+ {t("promotions.form.required")} +

+
)} - + + {attributeOptions?.map((c, i) => ( + + + {c.label} + + + ))} + + + ) : ( + ao.value === fieldRule.attribute + )?.label || "" + } + field={field} + /> + )}
@@ -203,43 +225,60 @@ export const RulesFormField = ({
{ - const currentAttributeOption = attributes.find( + name={`${scope}.${index}.operator`} + render={({ field }) => { + const { onChange, ref, ...fieldProps } = field + + const currentAttributeOption = attributes?.find( (attr) => attr.value === fieldRule.attribute ) + const options = + currentAttributeOption?.operators?.map((o, idx) => ({ + label: o.label, + value: o.value, + key: `${identifier}-operator-option-${idx}`, + })) || [] + + const disabled = + !!fieldRule.attribute && options?.length <= 1 + return ( - + ))} + + + ) : ( + o.value === fieldProps.value + )?.label || "" + } + field={field} + /> + )} @@ -251,9 +290,8 @@ export const RulesFormField = ({ form={form} identifier={identifier} scope={scope} - valuesField={valuesField} - operatorsField={operatorsField} - valuesRef={valuesRef} + name={`${scope}.${index}.values`} + operator={`${scope}.${index}.operator`} fieldRule={fieldRule} attributes={attributes} ruleType={ruleType} @@ -261,20 +299,25 @@ export const RulesFormField = ({
-
- { - if (!fieldRule.required) { - setRulesToRemove && - setRulesToRemove([...rulesToRemove, fieldRule]) - - remove(index) - } - }} - /> +
+ {!fieldRule.required && ( + { + if (!fieldRule.required) { + setRulesToRemove && + setRulesToRemove([...rulesToRemove, fieldRule]) + + remove(index) + } + }} + > + + + )}
@@ -291,7 +334,7 @@ export const RulesFormField = ({ ) })} -
+