Skip to content

Commit e5ddebe

Browse files
authored
Merge pull request #1587 from basedosdados/feat/trial-chatbot
Feat: Trial chatbot wip staging
2 parents 43e021c + d718774 commit e5ddebe

5 files changed

Lines changed: 70 additions & 26 deletions

File tree

next/components/organisms/PaymentSystem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default function PaymentSystem({
9191
const [clientSecret, setClientSecret] = useState("")
9292

9393
useEffect(() => {
94-
if (clientSecret === null) onSucess()
94+
if (clientSecret === null) onSucess(true)
9595
}, [clientSecret])
9696

9797
const appearance = {

next/components/organisms/componentsUserPage/PlansAndPayment.js

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ export default function PlansAndPayment ({ userData }) {
147147
const [toggleAnual, setToggleAnual] = useState(true)
148148
const [subscriptionToCancel, setSubscriptionToCancel] = useState("bd_pro")
149149
const [checkoutStep, setCheckoutStep] = useState("plan")
150+
const [isChatbotTrialSuccess, setIsChatbotTrialSuccess] = useState(false)
151+
const [isStartingChatbotTrial, setIsStartingChatbotTrial] = useState(false)
150152
const successCheckoutKindRef = useRef(null)
151153

152154
const internalSubscriptions = userData?.internalSubscription?.edges?.map((edge) => edge?.node) || []
@@ -266,7 +268,7 @@ export default function PlansAndPayment ({ userData }) {
266268
if (!checkoutAlreadyVisible) {
267269
if (isChatbotType) {
268270
if (!hasSubscribedChatbot) {
269-
openCheckoutPaymentStep()
271+
startChatbotTrialFlow()
270272
} else {
271273
openCheckoutPlanStep()
272274
}
@@ -357,6 +359,30 @@ export default function PlansAndPayment ({ userData }) {
357359
PaymentModal.onOpen()
358360
}
359361

362+
async function startChatbotTrialFlow() {
363+
setIsStartingChatbotTrial(true)
364+
365+
try {
366+
const trial = await fetch(`/api/stripe/startChatbotTrial?p=${btoa(plan)}`, {
367+
method: "GET",
368+
}).then((res) => res.json())
369+
370+
if (trial?.started) {
371+
successCheckoutKindRef.current = "chatbot"
372+
setIsChatbotTrialSuccess(true)
373+
SucessPaymentModal.onOpen()
374+
return
375+
}
376+
377+
openCheckoutPaymentStep()
378+
} catch (error) {
379+
console.error(error)
380+
openCheckoutPaymentStep()
381+
} finally {
382+
setIsStartingChatbotTrial(false)
383+
}
384+
}
385+
360386
function goBackFromPlanStep() {
361387
PaymentModal.onClose()
362388
if (isChatbotCheckout) {
@@ -512,11 +538,12 @@ export default function PlansAndPayment ({ userData }) {
512538
)
513539
}
514540

515-
const openModalSucess = () => {
541+
const openModalSucess = (isTrial = false) => {
516542
const isChatbotPurchase =
517543
checkoutInfos?.productName?.toLowerCase().includes("chatbot") ||
518544
checkoutInfos?.productSlug?.toLowerCase().includes("chatbot")
519545
successCheckoutKindRef.current = isChatbotPurchase ? "chatbot" : "bd_pro"
546+
setIsChatbotTrialSuccess(isTrial)
520547
PaymentModal.onClose()
521548
SucessPaymentModal.onOpen()
522549
}
@@ -571,6 +598,7 @@ export default function PlansAndPayment ({ userData }) {
571598
}
572599

573600
successCheckoutKindRef.current = null
601+
setIsChatbotTrialSuccess(false)
574602

575603
if(isLoadingH === true) return window.open("/", "_self")
576604
window.open(`/user/${userData.username}?plans_and_payment`, "_self")
@@ -718,6 +746,7 @@ export default function PlansAndPayment ({ userData }) {
718746
useEffect(() => {
719747
const onPopState = () => {
720748
successCheckoutKindRef.current = null
749+
setIsChatbotTrialSuccess(false)
721750
setIsLoading(false)
722751
setIsLoadingH(false)
723752
SucessPaymentModal.onClose()
@@ -729,7 +758,7 @@ export default function PlansAndPayment ({ userData }) {
729758
return (
730759
<Stack spacing={0}>
731760
<Box
732-
display={isLoading || isLoadingH ? "flex" : "none"}
761+
display={isLoading || isLoadingH || isStartingChatbotTrial ? "flex" : "none"}
733762
position="fixed"
734763
top="0"
735764
left="0"
@@ -1008,7 +1037,7 @@ export default function PlansAndPayment ({ userData }) {
10081037
userData={userData}
10091038
plan={plan}
10101039
coupon={coupon}
1011-
onSucess={() => openModalSucess()}
1040+
onSucess={(isTrial) => openModalSucess(isTrial)}
10121041
onErro={() => openModalErro()}
10131042
isLoading={(e) => setIsLoadingClientSecret(e)}
10141043
/>
@@ -1166,27 +1195,35 @@ export default function PlansAndPayment ({ userData }) {
11661195
<SuccessIcon width="90px" height="64px" fill="#34A15A" />
11671196
<TitleText>
11681197
{isChatbotCheckout
1169-
? t("username.chatbotSubscriptionSuccessTitle")
1198+
? isChatbotTrialSuccess
1199+
? t("username.chatbotTrialSuccessTitle")
1200+
: t("username.chatbotSubscriptionSuccessTitle")
11701201
: t("username.congratulations")}
11711202
</TitleText>
11721203
{isChatbotCheckout ? (
1173-
<BodyText color="#464A51">
1174-
<Trans
1175-
t={t}
1176-
i18nKey="username.chatbotSubscriptionSuccessDescription"
1177-
components={{
1178-
1: (
1179-
<Text
1180-
as="a"
1181-
href="/contact"
1182-
target="_self"
1183-
color="#0068C5"
1184-
_hover={{ color: "#0057A4" }}
1185-
/>
1186-
),
1187-
}}
1188-
/>
1189-
</BodyText>
1204+
isChatbotTrialSuccess ? (
1205+
<BodyText color="#464A51">
1206+
{t("username.chatbotTrialSuccessDescription")}
1207+
</BodyText>
1208+
) : (
1209+
<BodyText color="#464A51">
1210+
<Trans
1211+
t={t}
1212+
i18nKey="username.chatbotSubscriptionSuccessDescription"
1213+
components={{
1214+
1: (
1215+
<Text
1216+
as="a"
1217+
href="/contact"
1218+
target="_self"
1219+
color="#0068C5"
1220+
_hover={{ color: "#0057A4" }}
1221+
/>
1222+
),
1223+
}}
1224+
/>
1225+
</BodyText>
1226+
)
11901227
) : (
11911228
<BodyText color="#464A51">
11921229
{t("username.BQEmailDescription4")}{" "}
@@ -1232,6 +1269,7 @@ export default function PlansAndPayment ({ userData }) {
12321269
width={{ base: "100%", lg: "50%" }}
12331270
onClick={() => {
12341271
successCheckoutKindRef.current = null;
1272+
setIsChatbotTrialSuccess(false);
12351273
setIsLoading(false);
12361274
setIsLoadingH(false);
12371275
SucessPaymentModal.onClose();

next/public/locales/en/user.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,11 @@
277277
"chatbotSectionSubtitle": "Learn about and subscribe to our Chatbot plans.",
278278
"chatbotSectionTagline": "Turn your questions into analyses with the power of AI, alongside Brazil’s largest public datalake. Learn more <1>here</1>.",
279279
"subscribeChatbot": "Subscribe to Chatbot",
280-
"cancelChatbotSubscription": "Cancel Chatbot subscription",
280+
"cancelChatbotSubscription": "Cancel chatbot subscription",
281281
"chatbotSubscriptionSuccessTitle": "Chatbot subscription activated!",
282282
"chatbotSubscriptionSuccessDescription": "Your payment was approved and your Chatbot plan is now active. If you need help setting up or using the product, <1>contact our support team</1>.",
283+
"chatbotTrialSuccessTitle": "You can now use the chatbot",
284+
"chatbotTrialSuccessDescription": "Enjoy the free trial period to explore all chatbot features.",
283285
"viewChatbotSubscription": "View subscription",
284286
"paymentFailed": "Payment failed",
285287
"paymentError": "An error occurred while processing your payment. Please try again or contact support:",

next/public/locales/es/user.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@
192192
"chatbotSectionSubtitle": "Conozca y suscríbase a nuestros planes de Chatbot.",
193193
"chatbotSectionTagline": "Convierte tus preguntas en análisis con el poder de la IA junto al mayor datalake público de Brasil. Más información <1>aquí</1>.",
194194
"subscribeChatbot": "Suscribirse al Chatbot",
195-
"cancelChatbotSubscription": "Cancelar suscripción al Chatbot",
195+
"cancelChatbotSubscription": "Cancelar suscripción al chatbot",
196196
"chatbotSubscriptionSuccessTitle": "¡Suscripción al Chatbot activada!",
197197
"chatbotSubscriptionSuccessDescription": "Su pago fue aprobado y su plan de Chatbot ya está activo. Si necesita ayuda para configurar o usar el producto, <1>contacte al soporte</1>.",
198+
"chatbotTrialSuccessTitle": "Ya puedes usar el chatbot",
199+
"chatbotTrialSuccessDescription": "Aprovecha el período de prueba gratuito para experimentar todas las funcionalidades del chatbot.",
198200
"viewChatbotSubscription": "Ver suscripción",
199201
"paymentFailed": "Pago fallido",
200202
"paymentError": "Ocurrió un error al procesar su pago. Por favor, intente nuevamente o contacte al soporte:",

next/public/locales/pt/user.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,11 @@
271271
"chatbotSectionSubtitle": "Conheça e assine os nossos planos para o Chatbot.",
272272
"chatbotSectionTagline": "Transforme suas perguntas em análises com o poder da IA junto do maior datalake público do Brasil. Saiba mais <1>aqui</1>.",
273273
"subscribeChatbot": "Assinar Chatbot",
274-
"cancelChatbotSubscription": "Cancelar assinatura do Chatbot",
274+
"cancelChatbotSubscription": "Cancelar assinatura do chatbot",
275275
"chatbotSubscriptionSuccessTitle": "Assinatura do Chatbot ativada!",
276276
"chatbotSubscriptionSuccessDescription": "Seu pagamento foi aprovado e seu plano do Chatbot já está ativo. Se precisar de ajuda para configurar ou usar o produto, <1>fale com o suporte</1>.",
277+
"chatbotTrialSuccessTitle": "Você já pode usar o chatbot",
278+
"chatbotTrialSuccessDescription": "Aproveite o período de teste grátis para experimentar todas as funcionalidades do chatbot.",
277279
"viewChatbotSubscription": "Ver assinatura",
278280
"paymentFailed": "Falha no pagamento",
279281
"paymentError": "Ocorreu um erro ao processar seu pagamento. Por favor, tente novamente ou entre em contato com o suporte:",

0 commit comments

Comments
 (0)