Skip to content

Commit d51ed0f

Browse files
authored
notify new users of credits (#274)
1 parent 3247da2 commit d51ed0f

File tree

2 files changed

+56
-19
lines changed

2 files changed

+56
-19
lines changed

web/src/components/common/Notify.tsx

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Text, VStack, HStack, Box, Icon } from '@chakra-ui/react';
1+
import { Text, VStack, HStack, Box, Icon, IconButton } from '@chakra-ui/react';
22
import { BiSolidInfoCircle } from 'react-icons/bi';
3-
import React from 'react';
3+
import { IoClose } from 'react-icons/io5';
4+
import React, { useState } from 'react';
45

56
interface NotifyProps {
67
children?: React.ReactNode;
@@ -11,12 +12,21 @@ interface NotifyProps {
1112
export const Notify = ({
1213
children,
1314
title = "Heads Up!",
14-
notificationType = "info"
15+
notificationType = "info",
1516
}: NotifyProps) => {
17+
const [isVisible, setIsVisible] = useState(true);
1618
const bgColor = 'white'
1719
const borderColor = notificationType === 'info' ? 'minusxGreen.800' : notificationType === 'warning' ? 'orange.500' : 'red.600'
1820
const iconColor = notificationType === 'info' ? 'minusxGreen.800' : notificationType === 'warning' ? 'orange.500' : 'red.600';
1921

22+
const handleDismiss = () => {
23+
setIsVisible(false);
24+
};
25+
26+
if (!isVisible) {
27+
return null;
28+
}
29+
2030
return (
2131
<Box
2232
bg={bgColor}
@@ -28,22 +38,35 @@ export const Notify = ({
2838
w="full"
2939
>
3040
<VStack align="flex-start" spacing={2} w="full">
31-
<HStack spacing={2} align="center">
32-
{
33-
notificationType === 'warning' ?
34-
<Icon as={BiSolidInfoCircle} size={16} color={"orange.500"} /> :
35-
notificationType === 'error' ?
36-
<Icon as={BiSolidInfoCircle} size={16} color={"red.600"} /> :
37-
<Icon as={BiSolidInfoCircle} size={16} color={"minusxGreen.800"} />
38-
}
39-
<Text
40-
fontSize="sm"
41-
fontWeight="semibold"
42-
m={0}
43-
color={iconColor}
44-
>
45-
{title}
46-
</Text>
41+
<HStack spacing={2} align="center" justify="space-between" w="full">
42+
<HStack spacing={2} align="center">
43+
{
44+
notificationType === 'warning' ?
45+
<Icon as={BiSolidInfoCircle} size={16} color={"orange.500"} /> :
46+
notificationType === 'error' ?
47+
<Icon as={BiSolidInfoCircle} size={16} color={"red.600"} /> :
48+
<Icon as={BiSolidInfoCircle} size={16} color={"minusxGreen.800"} />
49+
}
50+
<Text
51+
fontSize="sm"
52+
fontWeight="semibold"
53+
m={0}
54+
color={iconColor}
55+
>
56+
{title}
57+
</Text>
58+
</HStack>
59+
{notificationType != 'error' && (
60+
<IconButton
61+
aria-label="Dismiss notification"
62+
icon={<IoClose />}
63+
size="sm"
64+
variant="ghost"
65+
color="gray.500"
66+
onClick={handleDismiss}
67+
_hover={{ bg: notificationType === 'info' ? 'minusxGreen.800' : notificationType === 'warning' ? 'orange.500' : 'red.600', color: 'white' }}
68+
/>
69+
)}
4770
</HStack>
4871
{children && (
4972
<Text

web/src/components/common/TaskUI.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,13 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
106106
const credits = useSelector((state: RootState) => state.billing.credits)
107107
const infoLoaded = useSelector((state: RootState) => state.billing.infoLoaded)
108108
const analystMode = useSelector((state: RootState) => state.settings.analystMode)
109+
const proUser = useSelector((state: RootState) => state.billing.isSubscribed)
110+
const enterpriseUser = useSelector((state: RootState) => state.billing.isEnterpriseCustomer)
109111

110112
const creditsExhausted = () => (credits <= 0 && infoLoaded)
111113
const creditsLow = () => (credits <= LOW_CREDITS_THRESHOLD && infoLoaded)
114+
// approx check if this is a new user
115+
const newUserProxy = () => (credits >= 200 && infoLoaded) && !proUser && !enterpriseUser && messages.length < 2
112116
const lastThread = () => (thread === totalThreads - 1)
113117

114118
const relevantTables = toolContext.relevantTables || []
@@ -461,6 +465,16 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
461465
}
462466
};
463467
}
468+
if (newUserProxy()) {
469+
return {
470+
inputBox: true,
471+
alert: {
472+
message: "Welcome to MinusX! Since we like you so much, we are giving you **250 free credits** this week to try out the product! Happy querying!",
473+
type: "info",
474+
title: "Bonus credits, yay!"
475+
}
476+
};
477+
}
464478

465479
// 3. All cases when the input box should be enabled, and no alert shown
466480
return {

0 commit comments

Comments
 (0)