|
|
import { SiteGoal, SiteIntent } from './constants'; |
|
|
|
|
|
interface Flags { |
|
|
isIntentCreateCourseGoalEnabled?: boolean; |
|
|
} |
|
|
|
|
|
export const goalsToIntent = ( goals: SiteGoal[], flags?: Flags ): SiteIntent => { |
|
|
const { isIntentCreateCourseGoalEnabled } = flags ?? {}; |
|
|
|
|
|
|
|
|
if ( goals.includes( SiteGoal.DIFM ) ) { |
|
|
return SiteIntent.DIFM; |
|
|
} |
|
|
|
|
|
if ( goals.includes( SiteGoal.Import ) ) { |
|
|
return SiteIntent.Import; |
|
|
} |
|
|
|
|
|
if ( goals.includes( SiteGoal.Courses ) && isIntentCreateCourseGoalEnabled ) { |
|
|
return SiteIntent.CreateCourseGoal; |
|
|
} |
|
|
|
|
|
|
|
|
if ( goals.includes( SiteGoal.Newsletter ) ) { |
|
|
return SiteIntent.NewsletterGoal; |
|
|
} |
|
|
|
|
|
|
|
|
if ( |
|
|
goals.some( ( goal ) => |
|
|
[ SiteGoal.Sell, SiteGoal.SellDigital, SiteGoal.SellPhysical ].includes( goal ) |
|
|
) |
|
|
) { |
|
|
return SiteIntent.Sell; |
|
|
} |
|
|
|
|
|
|
|
|
if ( goals.includes( SiteGoal.Promote ) ) { |
|
|
return SiteIntent.Build; |
|
|
} |
|
|
|
|
|
if ( goals.includes( SiteGoal.Write ) ) { |
|
|
return SiteIntent.Write; |
|
|
} |
|
|
|
|
|
return SiteIntent.Build; |
|
|
}; |
|
|
|
|
|
export const serializeGoals = ( goals: SiteGoal[] ): string => { |
|
|
|
|
|
const firstGoal = goals.find( ( goal ) => |
|
|
[ SiteGoal.Write, SiteGoal.Sell, SiteGoal.Promote, SiteGoal.DIFM, SiteGoal.Import ].includes( |
|
|
goal |
|
|
) |
|
|
); |
|
|
|
|
|
return ( firstGoal ? [ firstGoal ] : [] ) |
|
|
.concat( goals.filter( ( goal ) => goal !== firstGoal ).sort() ) |
|
|
.join( ',' ); |
|
|
}; |
|
|
|