Skip to content

Commit

Permalink
Merge pull request #71 from JustaName-id/hadi/telegram-static
Browse files Browse the repository at this point in the history
feat: telegram static page
  • Loading branch information
HadiKhai authored Nov 1, 2024
2 parents 819d46b + e1fa908 commit e54790b
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/telegram-static/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_APP_TELEGRAM_BOT_USERNAME=<your-telegram-bot-username>
VITE_APP_API_DOMAIN=<your-vc-api-domain>/verifications/v1
18 changes: 18 additions & 0 deletions apps/telegram-static/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
1 change: 1 addition & 0 deletions apps/telegram-static/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
10 changes: 10 additions & 0 deletions apps/telegram-static/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
VITE_APP_TELEGRAM_BOT_USERNAME: string;
VITE_APP_API_DOMAIN: string;
}

interface ImportMeta {
readonly env: ImportMetaEnv;
}
15 changes: 15 additions & 0 deletions apps/telegram-static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>TelegramStatic</title>
<base href="/" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions apps/telegram-static/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'telegram-static',
preset: '../../jest.preset.js',
transform: {
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/apps/telegram-static',
};
9 changes: 9 additions & 0 deletions apps/telegram-static/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "telegram-static",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/telegram-static/src",
"projectType": "application",
"tags": [],
"// targets": "to see all targets run: nx show project telegram-static --web",
"targets": {}
}
Binary file added apps/telegram-static/public/favicon.ico
Binary file not shown.
28 changes: 28 additions & 0 deletions apps/telegram-static/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {useEffect} from "react";

export function App() {
const telegramBotUsername = import.meta.env.VITE_APP_TELEGRAM_BOT_USERNAME;
const apiDomain = import.meta.env.VITE_APP_API_DOMAIN;
const state = new URLSearchParams(window.location.search).get('state');
const dataAuthUrl = `${apiDomain}/credentials/socials/telegram/callback?state=${state}`;

useEffect(() => {
const script = document.createElement('script');
script.src = "https://telegram.org/js/telegram-widget.js?15";
script.async = true;
script.setAttribute('data-telegram-login', telegramBotUsername);
script.setAttribute('data-size', 'large');
script.setAttribute('data-auth-url', dataAuthUrl);
script.setAttribute('data-request-access', 'write');

document.getElementById('telegram-widget-container')?.appendChild(script);

return () => {
// Cleanup script if component unmounts
document.getElementById('telegram-widget-container')?.removeChild(script);
};
}, [telegramBotUsername, dataAuthUrl]);

return <div id="telegram-widget-container"></div>;
}
export default App;
Empty file.
13 changes: 13 additions & 0 deletions apps/telegram-static/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { StrictMode } from 'react';
import * as ReactDOM from 'react-dom/client';

import App from './app/app';

const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);
root.render(
<StrictMode>
<App />
</StrictMode>
);
23 changes: 23 additions & 0 deletions apps/telegram-static/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts",
"vite/client"
]
},
"exclude": [
"src/**/*.spec.ts",
"src/**/*.test.ts",
"src/**/*.spec.tsx",
"src/**/*.test.tsx",
"src/**/*.spec.js",
"src/**/*.test.js",
"src/**/*.spec.jsx",
"src/**/*.test.jsx"
],
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
}
23 changes: 23 additions & 0 deletions apps/telegram-static/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"types": ["vite/client"]
},
"files": [],
"include": [
"env.d.ts"
],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"extends": "../../tsconfig.base.json"
}
25 changes: 25 additions & 0 deletions apps/telegram-static/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": [
"jest",
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
36 changes: 36 additions & 0 deletions apps/telegram-static/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// <reference types='vitest' />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';

export default defineConfig({
root: __dirname,
cacheDir: '../../node_modules/.vite/apps/telegram-static',

server: {
port: 4200,
host: 'localhost',
},

preview: {
port: 4300,
host: 'localhost',
},

plugins: [react(), nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],

// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },

build: {
outDir: '../../dist/apps/telegram-static',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export class CredentialsException extends Error {
}

static invalid() {
return new CredentialsException('Invalid data: Authentication failed');
return new CredentialsException('CredentialsException: Authentication failed');
}
}
}

0 comments on commit e54790b

Please sign in to comment.