({
post,
origin,
lastBoost,
...props
}: BoostPostModalProps)
| 73 | export type Screens = keyof typeof SCREENS; |
| 74 | |
| 75 | export function BoostPostModal({ |
| 76 | post, |
| 77 | origin, |
| 78 | lastBoost, |
| 79 | ...props |
| 80 | }: BoostPostModalProps): ReactElement { |
| 81 | const { user } = useAuthContext(); |
| 82 | const client = useQueryClient(); |
| 83 | const { getFeatureValue } = useFeaturesReadyContext(); |
| 84 | const [activeScreen, setActiveScreen] = useState<Screens>(SCREENS.FORM); |
| 85 | const boostSettings = getFeatureValue(boostSettingsFeature); |
| 86 | const [mode, setMode] = useState( |
| 87 | lastBoost ? BoostBudgetMode.Custom : BoostBudgetMode.Quick, |
| 88 | ); |
| 89 | const [custom, setCustom] = useState({ |
| 90 | coresPerDay: lastBoost?.coresPerDay ?? boostSettings.default_cores, |
| 91 | totalDays: lastBoost?.totalDays ?? boostSettings.default_days, |
| 92 | }); |
| 93 | const { coresPerDay, totalDays } = |
| 94 | mode === BoostBudgetMode.Quick ? quickBoost : custom; |
| 95 | const postTags = post.tags?.length |
| 96 | ? post.tags |
| 97 | : (post.sharedPost?.tags ?? []); |
| 98 | const [audience, setAudience] = useState<BoostAudienceValue>({ |
| 99 | tags: postTags, |
| 100 | location: BoostLocation.Worldwide, |
| 101 | countries: [], |
| 102 | }); |
| 103 | const campaignAudience = toCampaignAudience(audience, postTags); |
| 104 | const [estimate, setEstimate] = useState<{ |
| 105 | coresPerDay: number; |
| 106 | audience?: CampaignAudience; |
| 107 | }>({ coresPerDay }); |
| 108 | const [updateEstimate] = useDebounceFn(setEstimate, 400); |
| 109 | const totalSpendInt = coresPerDay * totalDays; |
| 110 | const totalSpend = largeNumberFormat(totalSpendInt); |
| 111 | const squadId = |
| 112 | post.source?.type === SourceType.Squad ? post.source.id : undefined; |
| 113 | const { |
| 114 | squadWallet, |
| 115 | wallet, |
| 116 | setWallet, |
| 117 | balance, |
| 118 | selectedSquadWallet, |
| 119 | canBuyCores, |
| 120 | } = useBoostWallet(squadId); |
| 121 | const { estimatedReach, canBoost, isLoading } = usePostBoostEstimation({ |
| 122 | post, |
| 123 | query: { budget: estimate.coresPerDay, audience: estimate.audience }, |
| 124 | }); |
| 125 | const { logBoostEvent, logBuyCores } = useBoostLogging({ |
| 126 | type: CampaignType.Post, |
| 127 | referenceId: post.id, |
| 128 | origin, |
| 129 | }); |
| 130 | const { onStartBoost: onBoostPost } = useCampaignMutation({ |
| 131 | onBoostSuccess: (data, vars) => { |
| 132 | logBoostEvent(LogEvent.CompleteBoost, vars, { |
nothing calls this directly
no test coverage detected