MCPcopy Create free account
hub / github.com/dailydotdev/apps / BoostPostModal

Function BoostPostModal

packages/shared/src/features/boost/BoostPostModal.tsx:57–313  ·  view source on GitHub ↗
({
  post,
  ...props
}: BoostPostModalProps)

Source from the content-addressed store, hash-verified

55export type Screens = keyof typeof SCREENS;
56
57export 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}

Callers

nothing calls this directly

Calls 10

useAuthContextFunction · 0.90
useLazyModalFunction · 0.90
useFeaturesReadyContextFunction · 0.90
largeNumberFormatFunction · 0.90
usePostBoostEstimationFunction · 0.90
useCampaignMutationFunction · 0.90
updatePostCacheFunction · 0.90
usePostImageFunction · 0.90
useDebounceFnFunction · 0.85
getFeatureValueFunction · 0.50

Tested by

no test coverage detected