Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 16s
Features: - User registration and login with JWT tokens - All data is now user-specific (multi-tenancy) - Profile page with integrations and logout - Automatic migration of existing data to first user Backend changes: - Added users and refresh_tokens tables - Added user_id to all data tables (projects, entries, nodes, dictionaries, words, progress, configs, telegram_integrations, weekly_goals) - JWT authentication middleware - claimOrphanedData() for data migration Frontend changes: - AuthContext for state management - Login/Register forms - Profile page (replaced Integrations) - All API calls use authFetch with Bearer token Migration notes: - On first deploy, backend automatically adds user_id columns - First user to login claims all existing data
93 lines
3.2 KiB
JavaScript
93 lines
3.2 KiB
JavaScript
import React, { useState, useEffect } from 'react'
|
|
import { useAuth } from './auth/AuthContext'
|
|
import './Integrations.css'
|
|
|
|
function TodoistIntegration({ onBack }) {
|
|
const { authFetch } = useAuth()
|
|
const [webhookURL, setWebhookURL] = useState('')
|
|
const [loading, setLoading] = useState(true)
|
|
const [copied, setCopied] = useState(false)
|
|
|
|
useEffect(() => {
|
|
fetchWebhookURL()
|
|
}, [])
|
|
|
|
const fetchWebhookURL = async () => {
|
|
try {
|
|
setLoading(true)
|
|
const response = await authFetch('/api/integrations/todoist/webhook-url')
|
|
if (!response.ok) {
|
|
throw new Error('Ошибка при загрузке URL webhook')
|
|
}
|
|
const data = await response.json()
|
|
setWebhookURL(data.webhook_url)
|
|
} catch (error) {
|
|
console.error('Error fetching webhook URL:', error)
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
const copyToClipboard = async () => {
|
|
try {
|
|
await navigator.clipboard.writeText(webhookURL)
|
|
setCopied(true)
|
|
setTimeout(() => setCopied(false), 2000)
|
|
} catch (error) {
|
|
console.error('Error copying to clipboard:', error)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="p-4 md:p-6">
|
|
<button className="close-x-button" onClick={onBack} title="Закрыть">
|
|
✕
|
|
</button>
|
|
|
|
<h1 className="text-2xl font-bold mb-6">TODOist интеграция</h1>
|
|
|
|
<div className="bg-white rounded-lg shadow-md p-6 mb-6">
|
|
<h2 className="text-lg font-semibold mb-4">Webhook URL</h2>
|
|
{loading ? (
|
|
<div className="text-gray-500">Загрузка...</div>
|
|
) : (
|
|
<div className="flex items-center gap-2">
|
|
<input
|
|
type="text"
|
|
value={webhookURL}
|
|
readOnly
|
|
className="flex-1 px-4 py-2 border border-gray-300 rounded-lg bg-gray-50 text-sm"
|
|
/>
|
|
<button
|
|
onClick={copyToClipboard}
|
|
className="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors whitespace-nowrap"
|
|
>
|
|
{copied ? 'Скопировано!' : 'Копировать'}
|
|
</button>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="bg-blue-50 border border-blue-200 rounded-lg p-6">
|
|
<h3 className="text-lg font-semibold mb-3 text-blue-900">
|
|
Как использовать в приложении TODOist
|
|
</h3>
|
|
<ol className="list-decimal list-inside space-y-2 text-gray-700">
|
|
<li>Откройте приложение TODOist на вашем устройстве</li>
|
|
<li>Перейдите в настройки проекта или задачи</li>
|
|
<li>Найдите раздел "Интеграции" или "Webhooks"</li>
|
|
<li>Вставьте скопированный URL webhook в соответствующее поле</li>
|
|
<li>Сохраните настройки</li>
|
|
<li>
|
|
Теперь при закрытии задач в TODOist они будут автоматически
|
|
обрабатываться системой
|
|
</li>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default TodoistIntegration
|
|
|