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