Skip to content

Commit

Permalink
- working variant
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Zharich committed Jul 8, 2024
1 parent dee6ff5 commit 55b58c5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/api/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,22 @@ export interface paths {
patch?: never;
trace?: never;
};
"/backend/referrals/join": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
post: operations["ReferralsController_joinUserByReferralLink"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/backend/history/chat/{chatId}": {
parameters: {
query?: never;
Expand Down Expand Up @@ -679,6 +695,25 @@ export interface operations {
};
};
};
ReferralsController_joinUserByReferralLink: {
parameters: {
query?: never;
header: {
tmaInitData: string;
};
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
201: {
headers: {
[name: string]: unknown;
};
content?: never;
};
};
};
HistoryController_getUserHistory: {
parameters: {
query: {
Expand Down
22 changes: 21 additions & 1 deletion src/pages/Join.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FC } from 'react';
import { Typography } from '@mui/material';
import { Button, Title } from '@telegram-apps/telegram-ui';
import { MiniApp, useMiniApp, useUtils, Utils } from '@tma.js/sdk-react';
import axios from 'axios';
import styled from 'styled-components';

import { useCurrentUser } from '@/api/queries';
Expand Down Expand Up @@ -32,9 +33,28 @@ export const Join: FC<{ linkOwner: LinkOwner }> = ({ linkOwner }) => {
/* ignore */
}

console.log('linkOwner', linkOwner);

const { data: currentUser, isLoading } = useCurrentUser();

const handleJoin = () => {
const handleJoin = async () => {
try {
await axios.post(
`${import.meta.env.VITE_BACKEND_URL}/backend/referrals/join`,
{
chatId: Number(linkOwner.chatId),
ownerId: linkOwner.ownerId,
title: linkOwner.title
},
{
headers: { tmaInitData: window.Telegram.WebApp.initData }
}
);
} catch (error) {
console.error(error);
throw new Error(`${error}`);
}

if (utils) {
utils.openTelegramLink(linkOwner.telegramInviteLink);
} else {
Expand Down

0 comments on commit 55b58c5

Please sign in to comment.