@@ -11,7 +11,6 @@ import {
1111 NUMBER_CONDITION_OPERATORS ,
1212 REWARD_CONDITIONS ,
1313 RewardConditionEntityAttribute ,
14- SOURCE_CONDITION_OPERATORS ,
1514 STRING_CONDITION_OPERATORS ,
1615} from "@/lib/zod/schemas/rewards" ;
1716import { X } from "@/ui/shared/icons" ;
@@ -303,6 +302,31 @@ function ConditionLogic({
303302
304303 const [ displayProductLabel , setDisplayProductLabel ] = useState ( false ) ;
305304
305+ // Auto-set operator to "equals_to" for customer.source
306+ const isCustomerSourceCondition =
307+ condition . entity === "customer" && condition . attribute === "source" ;
308+
309+ useEffect ( ( ) => {
310+ if ( isCustomerSourceCondition && condition . operator !== "equals_to" ) {
311+ setValue (
312+ conditionKey ,
313+ {
314+ ...condition ,
315+ operator : "equals_to" ,
316+ } ,
317+ {
318+ shouldDirty : true ,
319+ } ,
320+ ) ;
321+ }
322+ } , [
323+ isCustomerSourceCondition ,
324+ condition . operator ,
325+ condition ,
326+ conditionKey ,
327+ setValue ,
328+ ] ) ;
329+
306330 return (
307331 < div className = "flex w-full flex-col" >
308332 < div className = "flex items-center justify-between p-2.5" >
@@ -369,53 +393,54 @@ function ConditionLogic({
369393 } ) ) }
370394 />
371395 </ InlineBadgePopover > { " " }
372- < InlineBadgePopover
373- text = {
374- condition . operator
375- ? CONDITION_OPERATOR_LABELS [ condition . operator ]
376- : "Condition"
377- }
378- invalid = { ! condition . operator }
379- >
380- < InlineBadgePopoverMenu
381- selectedValue = { condition . operator }
382- onSelect = { ( value ) =>
383- setValue (
384- conditionKey ,
385- {
386- ...condition ,
387- operator :
388- value as ( typeof CONDITION_OPERATORS ) [ number ] ,
389- // Update value to array / string / number if needed
390- ...( [ "in" , "not_in" ] . includes ( value )
391- ? ! Array . isArray ( condition . value )
392- ? { value : [ ] }
393- : null
394- : [ "number" , "currency" ] . includes ( attributeType )
395- ? typeof condition . value !== "number"
396- ? { value : "" }
397- : null
398- : typeof condition . value !== "string"
399- ? { value : "" }
400- : null ) ,
401- } ,
402- {
403- shouldDirty : true ,
404- } ,
405- )
396+ { isCustomerSourceCondition ? (
397+ < span className = "text-content-emphasis font-medium" > is </ span >
398+ ) : (
399+ < InlineBadgePopover
400+ text = {
401+ condition . operator
402+ ? CONDITION_OPERATOR_LABELS [ condition . operator ]
403+ : "Condition"
406404 }
407- items = { ( condition . entity === "customer" &&
408- condition . attribute === "source"
409- ? SOURCE_CONDITION_OPERATORS
410- : [ "number" , "currency" ] . includes ( attributeType )
405+ invalid = { ! condition . operator }
406+ >
407+ < InlineBadgePopoverMenu
408+ selectedValue = { condition . operator }
409+ onSelect = { ( value ) =>
410+ setValue (
411+ conditionKey ,
412+ {
413+ ...condition ,
414+ operator :
415+ value as ( typeof CONDITION_OPERATORS ) [ number ] ,
416+ // Update value to array / string / number if needed
417+ ...( [ "in" , "not_in" ] . includes ( value )
418+ ? ! Array . isArray ( condition . value )
419+ ? { value : [ ] }
420+ : null
421+ : [ "number" , "currency" ] . includes ( attributeType )
422+ ? typeof condition . value !== "number"
423+ ? { value : "" }
424+ : null
425+ : typeof condition . value !== "string"
426+ ? { value : "" }
427+ : null ) ,
428+ } ,
429+ {
430+ shouldDirty : true ,
431+ } ,
432+ )
433+ }
434+ items = { ( [ "number" , "currency" ] . includes ( attributeType )
411435 ? NUMBER_CONDITION_OPERATORS
412436 : STRING_CONDITION_OPERATORS
413- ) . map ( ( operator ) => ( {
414- text : CONDITION_OPERATOR_LABELS [ operator ] ,
415- value : operator ,
416- } ) ) }
417- />
418- </ InlineBadgePopover > { " " }
437+ ) . map ( ( operator ) => ( {
438+ text : CONDITION_OPERATOR_LABELS [ operator ] ,
439+ value : operator ,
440+ } ) ) }
441+ />
442+ </ InlineBadgePopover >
443+ ) } { " " }
419444 { condition . operator && (
420445 < >
421446 < InlineBadgePopover
0 commit comments