Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/quest steps - TELEGRAM WEB APP #1930

Merged
merged 33 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c038489
wip
Lamperoyge Aug 7, 2023
41886a3
settings page
Lamperoyge Aug 8, 2023
e23462e
tg page
Lamperoyge Aug 9, 2023
c3ad996
tg integration
Lamperoyge Aug 10, 2023
f8527b0
remove unused stuff
Lamperoyge Aug 10, 2023
b788b76
update tg integration
Lamperoyge Aug 11, 2023
a4e3f2a
fix media
Lamperoyge Aug 17, 2023
c165a2a
yt telegram, wallet telegram
Lamperoyge Aug 18, 2023
c150ab2
wips
Lamperoyge Aug 23, 2023
5175044
more quest steps
Lamperoyge Aug 25, 2023
39a8b4d
more quest steps
Lamperoyge Aug 28, 2023
b02e948
merge staging
Lamperoyge Aug 28, 2023
b5e99ed
revert commented code
Lamperoyge Aug 28, 2023
fdd909a
remove console
Lamperoyge Aug 28, 2023
e6e428d
add media
Lamperoyge Aug 28, 2023
e4347f1
more edit stuff
Lamperoyge Aug 29, 2023
8686b8c
media stuff
Lamperoyge Aug 29, 2023
c3d578f
improvements
Lamperoyge Aug 29, 2023
2cc846c
fix media
Lamperoyge Aug 30, 2023
926ca9c
requirements not met stuff
Lamperoyge Aug 30, 2023
e2f0d40
verify token holdings
Lamperoyge Aug 30, 2023
a9259e6
data collection types
Lamperoyge Aug 30, 2023
23ba82c
bot name
Lamperoyge Aug 30, 2023
72f6a71
bugfixes
Lamperoyge Sep 1, 2023
645d13a
fix bugs
Lamperoyge Sep 1, 2023
2a0a054
fix num
Lamperoyge Sep 1, 2023
2aace81
moved attaches above step input
Lamperoyge Sep 1, 2023
5c2d1ec
twitter wip
Lamperoyge Sep 1, 2023
ce4a77b
twitter stuff
Lamperoyge Sep 1, 2023
f14fbd7
fixes
Lamperoyge Sep 4, 2023
b26345f
text wrap
Lamperoyge Sep 4, 2023
c66a360
keyboard effect
Lamperoyge Sep 4, 2023
b9c9a1d
Merge branch 'staging' into feat/quest-steps
Lamperoyge Sep 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
import { useContext } from 'react';
import { getTelegramBotLink } from 'utils/index';
import ConnectionContext from './ConnectionContext';
import * as yup from 'yup';
import { CONNECT_TELEGRAM_BOT } from 'graphql/mutations';
import { useMutation } from '@apollo/client';
import FooterButtons from './FooterButtons';
import ConnectionContext from './ConnectionContext';

const telegramGroupIdSchema = yup
.number()
.integer('ID must be an integer.')
.negative('ID must be negative.')
.required('ID is required.');

const validateTelegramGroupId = async (groupId) => {
try {
await telegramGroupIdSchema.validate(groupId);
return true;
} catch (error) {
console.error(error.message);
return false;
}
};

const TelegramIntegrationFooter = () => {
const { onClose, data } = useContext(ConnectionContext);
const tgLink = getTelegramBotLink();
const handleOnClick = () => window.open(tgLink, '_blank');
return <FooterButtons title="Connect Telegram" onClose={onClose} action={handleOnClick} />;
const [connectTelegram] = useMutation(CONNECT_TELEGRAM_BOT, {
refetchQueries: ['getOrgIntegrations', 'getPodIntegrations'],
});

const { onClose, data, setData, orgId, podId } = useContext(ConnectionContext);
const handleConnect = () => {
const { tgValue } = data;
validateTelegramGroupId(tgValue).then((isValid) => {
if (isValid) {
connectTelegram({ variables: { chatId: `${tgValue}`, orgId, podId } });
onClose();
} else {
setData((prev) => ({ ...prev, tgError: 'Invalid Group ID' }));
}
});
};

return <FooterButtons title="Connect Telegram" onClose={onClose} action={handleConnect} />;
};

export default TelegramIntegrationFooter;
111 changes: 44 additions & 67 deletions wondrous-app/components/Settings/Integrations/TelegramIntegration.tsx
Original file line number Diff line number Diff line change
@@ -1,88 +1,65 @@
import { Grid, Typography } from '@mui/material';
import { Box, Grid, Typography } from '@mui/material';
import GradientHeading from 'components/GradientHeading';
import { UnstyledLink } from 'components/WorkspacePicker/styles';
import { NewTabIcon } from 'components/Icons/taskModalIcons';
import palette from 'theme/palette';
import { CopyContainer, CopyTypography } from 'components/Common/InviteLinkModal/styles';
import CopyIcon from 'components/Icons/copy';
import { useContext, useEffect, useState } from 'react';
import { useContext, useEffect, useRef, useState } from 'react';
import { useMutation } from '@apollo/client';
import { CONNECT_TELEGRAM } from 'graphql/mutations';
import { CONNECT_TELEGRAM_BOT } from 'graphql/mutations';
import { getTelegramBotLink } from 'utils/index';
import { TelegramBotInfo, TelegramLabel } from './styles';
import { ErrorText } from 'components/Common';
import { GroupInput, TelegramBotInfo, TelegramLabel } from './styles';
import ConnectionContext from './Helpers/ConnectionContext';

const TelegramIntegration = () => {
const { orgId, podId } = useContext(ConnectionContext);

const [copied, setCopied] = useState(false);

const [connectTelegram, { data }] = useMutation(CONNECT_TELEGRAM, {
variables: {
orgId,
podId,
},
});

const token = `token:${data?.connectTelegram}`;

useEffect(() => {
if (orgId) {
connectTelegram();
}
}, [orgId, podId]);

const handleOnCopy = () => {
navigator.clipboard.writeText(`${token}`);
setCopied(true);
};
const { data, setData } = useContext(ConnectionContext);
const { tgError } = data;

const tgLink = getTelegramBotLink();

return (
<Grid display="flex" direction="column" gap="12px">
<GradientHeading fontSize={16}>Setup instructions</GradientHeading>
<TelegramLabel>Step 1 speak to our bot</TelegramLabel>
<UnstyledLink href={tgLink} target="__blank">
<Grid
display="flex"
gap="8px"
alignItems="center"
bgcolor={palette.grey920}
borderRadius="6px"
padding="6px 10px 6px 8px"
height="32px"
width="fit-content"
>
<TelegramBotInfo>@wonderverse_bot</TelegramBotInfo>
<NewTabIcon />
</Grid>
</UnstyledLink>
<TelegramLabel>Step 2</TelegramLabel>
<Grid display="flex" gap="14px" alignItems="center">
<Grid
display="flex"
gap="8px"
alignItems="center"
bgcolor={palette.grey920}
borderRadius="6px"
padding="6px 10px 6px 8px"
height="32px"
width="100%"
>
<TelegramBotInfo>{token}</TelegramBotInfo>
</Grid>
<CopyContainer
$copied={copied}
onClick={handleOnCopy}
style={{
height: '32px',
}}
>
<CopyIcon color={copied ? palette.green30 : palette.blue20} />
<CopyTypography $copied={copied}>{copied ? 'Code copied' : 'Copy code'}</CopyTypography>
</CopyContainer>
<Grid display="flex" gap="12px">
<Box display="flex" flexDirection="column" gap="12px" width="100%" flex="1">
<TelegramLabel>Link WonderBot</TelegramLabel>
<UnstyledLink href={tgLink} target="__blank">
<Grid
display="flex"
gap="8px"
alignItems="center"
bgcolor={palette.grey920}
borderRadius="6px"
padding="6px 10px 6px 8px"
height="32px"
width="100%"
>
<TelegramBotInfo>@wonderverse_bot</TelegramBotInfo>
<NewTabIcon />
</Grid>
</UnstyledLink>
</Box>
<Box display="flex" flexDirection="column" gap="12px" width="100%" flex="1">
<TelegramLabel>Group ID</TelegramLabel>
<Grid display="flex" gap="14px" alignItems="center">
<Grid
display="flex"
gap="8px"
alignItems="center"
bgcolor={palette.grey920}
borderRadius="6px"
padding="6px 10px 6px 8px"
height="32px"
width="100%"
>
<GroupInput type="number" onChange={(e) => setData((prev) => ({ ...prev, tgValue: e.target.value }))} />
</Grid>
</Grid>
</Box>
</Grid>
{tgError ? <ErrorText>{tgError}</ErrorText> : null}
</Grid>
);
};
Expand Down
10 changes: 10 additions & 0 deletions wondrous-app/components/Settings/Integrations/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,13 @@ export const TelegramBotInfo = styled(Typography)`
line-height: 17px;
}
`;

export const GroupInput = styled(InputBase)`
&& {
color: ${palette.white};
font-family: ${typography.fontFamily};
font-weight: 400;
font-size: 13px;
line-height: 17px;
}
`;
8 changes: 5 additions & 3 deletions wondrous-app/graphql/mutations/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ export const CONNECT_COORDINAPE_TO_ORG = gql`
}
`;

export const CONNECT_TELEGRAM = gql`
mutation connectTelegram($orgId: ID, $podId: ID) {
connectTelegram(orgId: $orgId, podId: $podId)
export const CONNECT_TELEGRAM_BOT = gql`
mutation connectTelegram($orgId: ID, $chatId: String, $podId: ID) {
connectTelegram(orgId: $orgId, chatId: $chatId, podId: $podId) {
success
}
}
`;

Expand Down
4 changes: 2 additions & 2 deletions wondrous-app/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const getBoardType = ({ orgBoard, podBoard, userBoard }) => {

export const getTelegramBotLink = () => {
if (process.env.NEXT_PUBLIC_PRODUCTION) {
return 'https://t.me/wonderverse_bot';
return 'https://t.me/wonderverse_bot?startgroup=true&admin=post_messages';
}
return 'https://t.me/wonderverse_staging_bot';
return 'https://t.me/wonderverse_test_bot?startgroup=true&admin=post_messages';
};
3 changes: 3 additions & 0 deletions wondrous-bot-admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
rel="stylesheet"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://telegram.org/js/telegram-web-app.js"></script>

<title>Wonderverse Communities</title>
</head>
<body>
<div id="root"></div>

<script type="module" src="/src/main.tsx"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions wondrous-bot-admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import VerifyLinkPage from "pages/verify-link";
import AnalyticsPage from "pages/analytics";
import PremiumFeatureDialog from "components/PremiumFeatureDialog";
import PaywallContext from "utils/context/PaywallContext";
import ConnectPage from "pages/settings/connect";
import TelegramStatQuest from "pages/telegram/start-quest";
import PaywallContextProvider from "utils/context/PaywallContext";

const router = createBrowserRouter([
Expand Down Expand Up @@ -74,6 +76,10 @@ const router = createBrowserRouter([
path: "/settings/billing",
element: <BillingPage />,
},
{
path: "/settings/connect",
element: <ConnectPage />,
},
{
path: "/",
element: <Home />,
Expand Down Expand Up @@ -162,6 +168,10 @@ const router = createBrowserRouter([
path: "/analytics",
element: <AnalyticsPage />,
},
{
path: "/telegram/start-quest/:id",
element: <TelegramStatQuest />,
},
],
},
]);
Expand Down
Loading
Loading