({
post,
...props
}: BoostPostModalProps)
| 55 | export type Screens = keyof typeof SCREENS; |
| 56 | |
| 57 | export function BoostPostModal({ |
| 58 | post, |
| 59 | ...props |
| 60 | }: BoostPostModalProps): ReactElement { |
| 61 | const { user } = useAuthContext(); |
| 62 | const { openModal } = useLazyModal(); |
| 63 | const client = useQueryClient(); |
| 64 | const { getFeatureValue } = useFeaturesReadyContext(); |
| 65 | const [activeScreen, setActiveScreen] = useState<Screens>(SCREENS.FORM); |
| 66 | const boostSettings = getFeatureValue(boostSettingsFeature); |
| 67 | const [coresPerDay, setCoresPerDay] = React.useState( |
| 68 | boostSettings.default_cores, |
| 69 | ); |
| 70 | const [totalDays, setTotalDays] = React.useState(boostSettings.default_days); |
| 71 | const [estimate, setEstimate] = useState({ coresPerDay, totalDays }); |
| 72 | const [updateEstimate] = useDebounceFn(setEstimate, 400); |
| 73 | const totalSpendInt = coresPerDay * totalDays; |
| 74 | const totalSpend = largeNumberFormat(totalSpendInt); |
| 75 | const { estimatedReach, canBoost, isLoading } = usePostBoostEstimation({ |
| 76 | post, |
| 77 | query: { budget: estimate.coresPerDay }, |
| 78 | }); |
| 79 | const { onStartBoost: onBoostPost } = useCampaignMutation({ |
| 80 | onBoostSuccess: (data, vars) => { |
| 81 | if (data.referenceId) { |
| 82 | updatePostCache(client, vars.value, (old) => ({ |
| 83 | flags: { ...old.flags, campaignId: data.referenceId }, |
| 84 | })); |
| 85 | } |
| 86 | |
| 87 | setActiveScreen(SCREENS.SUCCESS); |
| 88 | }, |
| 89 | }); |
| 90 | const image = usePostImage(post); |
| 91 | |
| 92 | const onButtonClick = () => { |
| 93 | if (user.balance.amount < totalSpendInt) { |
| 94 | return setActiveScreen(SCREENS.BUY_CORES); |
| 95 | } |
| 96 | |
| 97 | return onBoostPost({ |
| 98 | duration: totalDays, |
| 99 | budget: coresPerDay, |
| 100 | value: post.id, |
| 101 | type: CampaignType.Post, |
| 102 | }); |
| 103 | }; |
| 104 | |
| 105 | if (activeScreen === SCREENS.BUY_CORES) { |
| 106 | return ( |
| 107 | <BuyCoresModal |
| 108 | isOpen |
| 109 | product={null} |
| 110 | onCompletion={() => setActiveScreen(SCREENS.FORM)} |
| 111 | onRequestClose={() => setActiveScreen(SCREENS.FORM)} |
| 112 | amountNeededCopy={ |
| 113 | <Typography |
| 114 | type={TypographyType.Callout} |
nothing calls this directly
no test coverage detected