@@ -4,39 +4,43 @@ import { evaluateCondition } from "@/lib/partners/evaluate-application-requireme
44import usePartnerProfile from "@/lib/swr/use-partner-profile" ;
55import useProgramEnrollment from "@/lib/swr/use-program-enrollment" ;
66import { EligibilityConditionDB } from "@/lib/types" ;
7+ import { CountryFlag } from "@/ui/shared/country-flag" ;
78import { Lock } from "@dub/ui/icons" ;
89import { COUNTRIES } from "@dub/utils" ;
10+ import { ReactNode } from "react" ;
911
10- function oxfordJoin ( items : string [ ] ) : string {
11- if ( items . length === 0 ) return "" ;
12- if ( items . length === 1 ) return items [ 0 ] ;
13- if ( items . length === 2 ) return `${ items [ 0 ] } or ${ items [ 1 ] } ` ;
14- return `${ items . slice ( 0 , - 1 ) . join ( ", " ) } , or ${ items [ items . length - 1 ] } ` ;
15- }
16-
17- function formatConditionText ( condition : EligibilityConditionDB ) : string {
12+ function formatConditionContent (
13+ condition : EligibilityConditionDB ,
14+ ) : ReactNode | null {
1815 if ( condition . key === "country" ) {
19- const countryNames = condition . value . map ( ( code ) => COUNTRIES [ code ] ?? code ) ;
20- const joined = oxfordJoin ( countryNames ) ;
16+ const intro =
17+ condition . operator === "is"
18+ ? "You can only apply to this program if you are from the following countries:"
19+ : "You cannot apply to this program if you are from the following countries:" ;
2120
22- if ( condition . operator === "is" ) {
23- return `Your country is ${ joined } ` ;
24- } else {
25- return `Your country is not ${ joined } ` ;
26- }
21+ return (
22+ < div className = "space-y-2 text-sm text-blue-800" >
23+ < p > { intro } </ p >
24+ < div className = "flex flex-wrap gap-1.5" >
25+ { condition . value . map ( ( code ) => (
26+ < span
27+ key = { code }
28+ className = "inline-flex h-7 items-center gap-1.5 rounded-full bg-blue-100 px-2.5 text-xs font-medium text-blue-900"
29+ >
30+ < CountryFlag countryCode = { code } className = "size-3.5 rounded-full" />
31+ { COUNTRIES [ code ] ?? code }
32+ </ span >
33+ ) ) }
34+ </ div >
35+ </ div >
36+ ) ;
2737 }
2838
2939 // emailDomain — commented out, preserved for future use
3040 // if (condition.key === "emailDomain") {
31- // const joined = oxfordJoin(condition.value);
32- // if (condition.operator === "is") {
33- // return `Your email domain is ${joined}`;
34- // } else {
35- // return `Your email domain is not ${joined}`;
36- // }
37- // }
41+ // ...
3842
39- return "" ;
43+ return null ;
4044}
4145
4246export function ProgramEligibilityCard ( {
@@ -67,9 +71,14 @@ export function ProgramEligibilityCard({
6771 } ) ,
6872 ) ;
6973
70- const unmetWithText = unmet . map ( formatConditionText ) . filter ( Boolean ) ;
74+ const unmetConditions = unmet
75+ . map ( ( condition ) => ( {
76+ condition,
77+ content : formatConditionContent ( condition ) ,
78+ } ) )
79+ . filter ( ( { content } ) => content !== null ) ;
7180
72- if ( unmetWithText . length === 0 ) return null ;
81+ if ( unmetConditions . length === 0 ) return null ;
7382
7483 return (
7584 < div className = "mt-4 space-y-3 rounded-[10px] border border-blue-200 bg-blue-50 p-4" >
@@ -78,11 +87,9 @@ export function ProgramEligibilityCard({
7887 Program eligibility
7988 </ div >
8089
81- < ul className = "list-disc space-y-1 pl-5 text-sm text-blue-800" >
82- { unmetWithText . map ( ( text , i ) => (
83- < li key = { i } > { text } </ li >
84- ) ) }
85- </ ul >
90+ { unmetConditions . map ( ( { condition, content } ) => (
91+ < div key = { `${ condition . key } -${ condition . operator } ` } > { content } </ div >
92+ ) ) }
8693 </ div >
8794 ) ;
8895}
0 commit comments