@@ -17,6 +17,7 @@ import {
1717 currencyFormatter ,
1818 pluralize ,
1919} from "@dub/utils" ;
20+ import { formatDuration } from "date-fns" ;
2021import { useRef } from "react" ;
2122import * as z from "zod/v4" ;
2223
@@ -118,6 +119,8 @@ export function ProgramRewardModifiersTooltipContent({
118119 ) ;
119120}
120121
122+ // TODO:
123+ // This became a bit of a mess, let's clean it up a bit.
121124const RewardItem = ( {
122125 reward,
123126 conditions,
@@ -169,7 +172,12 @@ const RewardItem = ({
169172 < span className = "min-w-0" >
170173 { idx === 0 ? "If" : capitalize ( operator . toLowerCase ( ) ) } { " " }
171174 { condition . entity } { " " }
172- { ( attribute ?. label ?? condition . attribute ) ?. toLowerCase ( ) } { " " }
175+ { (
176+ attribute ?. label ??
177+ ( condition . attribute === "subscriptionDuration"
178+ ? "Subscription duration"
179+ : condition . attribute )
180+ ) ?. toLowerCase ( ) } { " " }
173181 { CONDITION_OPERATOR_LABELS [ condition . operator ] } { " " }
174182 { condition . value &&
175183 ( condition . attribute === "country"
@@ -180,29 +188,36 @@ const RewardItem = ({
180188 . join ( ", " )
181189 : COUNTRIES [ condition . value ?. toString ( ) ] ??
182190 condition . value
183- : // Non-country value(s)
184- Array . isArray ( condition . value )
185- ? // Basic array
186- ( attribute ?. options
187- ? ( condition . value as string [ ] | number [ ] ) . map (
188- ( v ) =>
189- attribute . options ?. find ( ( o ) => o . id === v )
190- ?. label ?? v ,
191- )
192- : condition . value
193- ) . join ( ", " )
194- : condition . attribute === "productId" && condition . label
195- ? // Product label
196- condition . label
197- : attribute ?. type === "currency"
198- ? // Currency value
199- currencyFormatter ( Number ( condition . value ) )
200- : // Everything else
201- attribute ?. options
202- ? attribute . options . find (
203- ( o ) => o . id === condition . value ,
204- ) ?. label ?? condition . value . toString ( )
205- : condition . value . toString ( ) ) }
191+ : condition . attribute === "subscriptionDuration"
192+ ? Array . isArray ( condition . value )
193+ ? ( condition . value as number [ ] )
194+ . map ( formatSubscriptionDuration )
195+ . join ( ", " )
196+ : formatSubscriptionDuration ( Number ( condition . value ) )
197+ : // Non-country value(s)
198+ Array . isArray ( condition . value )
199+ ? // Basic array
200+ ( attribute ?. options
201+ ? ( condition . value as string [ ] | number [ ] ) . map (
202+ ( v ) =>
203+ attribute . options ?. find ( ( o ) => o . id === v )
204+ ?. label ?? v ,
205+ )
206+ : condition . value
207+ ) . join ( ", " )
208+ : condition . attribute === "productId" &&
209+ condition . label
210+ ? // Product label
211+ condition . label
212+ : attribute ?. type === "currency"
213+ ? // Currency value
214+ currencyFormatter ( Number ( condition . value ) )
215+ : // Everything else
216+ attribute ?. options
217+ ? attribute . options . find (
218+ ( o ) => o . id === condition . value ,
219+ ) ?. label ?? condition . value . toString ( )
220+ : condition . value . toString ( ) ) }
206221 </ span >
207222 </ li >
208223 ) ;
@@ -212,3 +227,9 @@ const RewardItem = ({
212227 </ div >
213228 ) ;
214229} ;
230+
231+ function formatSubscriptionDuration ( v : number ) : string {
232+ return formatDuration (
233+ v % 12 === 0 && v > 0 ? { years : v / 12 } : { months : v } ,
234+ ) ;
235+ }
0 commit comments