Spaces:
Running
Running
axeronis commited on
Commit ·
e67f01f
1
Parent(s): 6729b8b
feat: add OAuth Embedded Signup button for WhatsApp
Browse files- frontend/app/channels/page.tsx +99 -49
frontend/app/channels/page.tsx
CHANGED
|
@@ -309,7 +309,7 @@ function ChannelCard({ title, icon, gradient, isConnected, statusText, stats, on
|
|
| 309 |
|
| 310 |
function WhatsAppConnectModal({ onClose, onSuccess }: { onClose: () => void, onSuccess: () => void }) {
|
| 311 |
const toast = useToast()
|
| 312 |
-
const [
|
| 313 |
const [formData, setFormData] = useState({
|
| 314 |
accessToken: '',
|
| 315 |
phoneNumberId: '',
|
|
@@ -331,6 +331,12 @@ function WhatsAppConnectModal({ onClose, onSuccess }: { onClose: () => void, onS
|
|
| 331 |
}
|
| 332 |
})
|
| 333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
const handleSubmit = () => {
|
| 335 |
if (!formData.accessToken || !formData.phoneNumberId || !formData.businessAccountId) {
|
| 336 |
toast.warning('Заполните все поля')
|
|
@@ -350,65 +356,109 @@ function WhatsAppConnectModal({ onClose, onSuccess }: { onClose: () => void, onS
|
|
| 350 |
<div className="flex justify-between items-center mb-6 border-b border-white/10 pb-4">
|
| 351 |
<h3 className="text-xl font-bold text-white flex items-center gap-2">
|
| 352 |
<Smartphone className="w-6 h-6 text-emerald-500" />
|
| 353 |
-
WhatsApp
|
| 354 |
</h3>
|
| 355 |
<button onClick={onClose}><X className="text-slate-400 hover:text-white" /></button>
|
| 356 |
</div>
|
| 357 |
|
| 358 |
-
|
| 359 |
-
<div>
|
| 360 |
-
|
| 361 |
-
<
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
</div>
|
| 372 |
-
<div>
|
| 373 |
-
<label className="block text-xs uppercase text-slate-500 font-bold mb-1">Phone Number ID</label>
|
| 374 |
-
<div className="relative">
|
| 375 |
-
<Smartphone className="absolute left-3 top-3 w-4 h-4 text-slate-500" />
|
| 376 |
-
<input
|
| 377 |
-
type="text"
|
| 378 |
-
value={formData.phoneNumberId}
|
| 379 |
-
onChange={e => setFormData({ ...formData, phoneNumberId: e.target.value })}
|
| 380 |
-
className="w-full bg-[#0D0E18] border border-white/10 rounded-xl py-2.5 pl-10 text-white focus:border-emerald-500 outline-none transition-all"
|
| 381 |
-
placeholder="105..."
|
| 382 |
-
/>
|
| 383 |
-
</div>
|
| 384 |
-
</div>
|
| 385 |
-
<div>
|
| 386 |
-
<label className="block text-xs uppercase text-slate-500 font-bold mb-1">Business Account ID</label>
|
| 387 |
<div className="relative">
|
| 388 |
-
<
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
placeholder="100..."
|
| 395 |
-
/>
|
| 396 |
</div>
|
| 397 |
-
</div>
|
| 398 |
|
| 399 |
-
|
| 400 |
<button
|
| 401 |
-
onClick={
|
| 402 |
-
|
| 403 |
-
className="w-full py-3 bg-emerald-600 hover:bg-emerald-500 text-white rounded-xl font-bold transition-all shadow-lg shadow-emerald-900/20 flex items-center justify-center gap-2"
|
| 404 |
>
|
| 405 |
-
|
|
|
|
| 406 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
</div>
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
</motion.div>
|
| 413 |
</div>
|
| 414 |
)
|
|
|
|
| 309 |
|
| 310 |
function WhatsAppConnectModal({ onClose, onSuccess }: { onClose: () => void, onSuccess: () => void }) {
|
| 311 |
const toast = useToast()
|
| 312 |
+
const [showManual, setShowManual] = useState(false)
|
| 313 |
const [formData, setFormData] = useState({
|
| 314 |
accessToken: '',
|
| 315 |
phoneNumberId: '',
|
|
|
|
| 331 |
}
|
| 332 |
})
|
| 333 |
|
| 334 |
+
const handleOAuthConnect = () => {
|
| 335 |
+
// Redirect to backend OAuth endpoint
|
| 336 |
+
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'https://api.microfunnel.online'
|
| 337 |
+
window.location.href = `${apiUrl}/api/v1/oauth/meta/connect?channel=whatsapp`
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
const handleSubmit = () => {
|
| 341 |
if (!formData.accessToken || !formData.phoneNumberId || !formData.businessAccountId) {
|
| 342 |
toast.warning('Заполните все поля')
|
|
|
|
| 356 |
<div className="flex justify-between items-center mb-6 border-b border-white/10 pb-4">
|
| 357 |
<h3 className="text-xl font-bold text-white flex items-center gap-2">
|
| 358 |
<Smartphone className="w-6 h-6 text-emerald-500" />
|
| 359 |
+
WhatsApp Business
|
| 360 |
</h3>
|
| 361 |
<button onClick={onClose}><X className="text-slate-400 hover:text-white" /></button>
|
| 362 |
</div>
|
| 363 |
|
| 364 |
+
{!showManual ? (
|
| 365 |
+
<div className="space-y-4">
|
| 366 |
+
{/* OAuth Button - Primary */}
|
| 367 |
+
<button
|
| 368 |
+
onClick={handleOAuthConnect}
|
| 369 |
+
className="w-full py-4 bg-[#1877F2] hover:bg-[#166FE5] text-white rounded-xl font-bold transition-all shadow-lg flex items-center justify-center gap-3"
|
| 370 |
+
>
|
| 371 |
+
<svg className="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
|
| 372 |
+
<path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z" />
|
| 373 |
+
</svg>
|
| 374 |
+
Подключить через Facebook
|
| 375 |
+
</button>
|
| 376 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
<div className="relative">
|
| 378 |
+
<div className="absolute inset-0 flex items-center">
|
| 379 |
+
<div className="w-full border-t border-white/10"></div>
|
| 380 |
+
</div>
|
| 381 |
+
<div className="relative flex justify-center text-sm">
|
| 382 |
+
<span className="px-2 bg-[#1E1F2E] text-slate-500">или</span>
|
| 383 |
+
</div>
|
|
|
|
|
|
|
| 384 |
</div>
|
|
|
|
| 385 |
|
| 386 |
+
{/* Manual Config Button - Secondary */}
|
| 387 |
<button
|
| 388 |
+
onClick={() => setShowManual(true)}
|
| 389 |
+
className="w-full py-3 bg-white/5 hover:bg-white/10 text-slate-300 rounded-xl font-medium transition-all border border-white/10 flex items-center justify-center gap-2"
|
|
|
|
| 390 |
>
|
| 391 |
+
<Settings2 className="w-4 h-4" />
|
| 392 |
+
Ручная настройка
|
| 393 |
</button>
|
| 394 |
+
|
| 395 |
+
<p className="text-xs text-center text-slate-500 pt-2">
|
| 396 |
+
Рекомендуем подключение через Facebook — это быстрее и безопаснее
|
| 397 |
+
</p>
|
| 398 |
</div>
|
| 399 |
+
) : (
|
| 400 |
+
<div className="space-y-4">
|
| 401 |
+
<button
|
| 402 |
+
onClick={() => setShowManual(false)}
|
| 403 |
+
className="text-sm text-slate-400 hover:text-white flex items-center gap-1 mb-2"
|
| 404 |
+
>
|
| 405 |
+
← Назад
|
| 406 |
+
</button>
|
| 407 |
+
|
| 408 |
+
<div>
|
| 409 |
+
<label className="block text-xs uppercase text-slate-500 font-bold mb-1">Access Token</label>
|
| 410 |
+
<div className="relative">
|
| 411 |
+
<Key className="absolute left-3 top-3 w-4 h-4 text-slate-500" />
|
| 412 |
+
<input
|
| 413 |
+
type="password"
|
| 414 |
+
value={formData.accessToken}
|
| 415 |
+
onChange={e => setFormData({ ...formData, accessToken: e.target.value })}
|
| 416 |
+
className="w-full bg-[#0D0E18] border border-white/10 rounded-xl py-2.5 pl-10 text-white focus:border-emerald-500 outline-none transition-all"
|
| 417 |
+
placeholder="EAA..."
|
| 418 |
+
/>
|
| 419 |
+
</div>
|
| 420 |
+
</div>
|
| 421 |
+
<div>
|
| 422 |
+
<label className="block text-xs uppercase text-slate-500 font-bold mb-1">Phone Number ID</label>
|
| 423 |
+
<div className="relative">
|
| 424 |
+
<Smartphone className="absolute left-3 top-3 w-4 h-4 text-slate-500" />
|
| 425 |
+
<input
|
| 426 |
+
type="text"
|
| 427 |
+
value={formData.phoneNumberId}
|
| 428 |
+
onChange={e => setFormData({ ...formData, phoneNumberId: e.target.value })}
|
| 429 |
+
className="w-full bg-[#0D0E18] border border-white/10 rounded-xl py-2.5 pl-10 text-white focus:border-emerald-500 outline-none transition-all"
|
| 430 |
+
placeholder="105..."
|
| 431 |
+
/>
|
| 432 |
+
</div>
|
| 433 |
+
</div>
|
| 434 |
+
<div>
|
| 435 |
+
<label className="block text-xs uppercase text-slate-500 font-bold mb-1">Business Account ID</label>
|
| 436 |
+
<div className="relative">
|
| 437 |
+
<Building2 className="absolute left-3 top-3 w-4 h-4 text-slate-500" />
|
| 438 |
+
<input
|
| 439 |
+
type="text"
|
| 440 |
+
value={formData.businessAccountId}
|
| 441 |
+
onChange={e => setFormData({ ...formData, businessAccountId: e.target.value })}
|
| 442 |
+
className="w-full bg-[#0D0E18] border border-white/10 rounded-xl py-2.5 pl-10 text-white focus:border-emerald-500 outline-none transition-all"
|
| 443 |
+
placeholder="100..."
|
| 444 |
+
/>
|
| 445 |
+
</div>
|
| 446 |
+
</div>
|
| 447 |
+
|
| 448 |
+
<div className="pt-4">
|
| 449 |
+
<button
|
| 450 |
+
onClick={handleSubmit}
|
| 451 |
+
disabled={connectMutation.isPending}
|
| 452 |
+
className="w-full py-3 bg-emerald-600 hover:bg-emerald-500 text-white rounded-xl font-bold transition-all shadow-lg shadow-emerald-900/20 flex items-center justify-center gap-2"
|
| 453 |
+
>
|
| 454 |
+
{connectMutation.isPending ? <Loader2 className="animate-spin" /> : 'Подключить'}
|
| 455 |
+
</button>
|
| 456 |
+
</div>
|
| 457 |
+
<p className="text-xs text-center text-slate-500">
|
| 458 |
+
Данные можно найти в <a href="https://developers.facebook.com/apps" target="_blank" className="text-emerald-400 hover:underline">Meta Developers Console</a>
|
| 459 |
+
</p>
|
| 460 |
+
</div>
|
| 461 |
+
)}
|
| 462 |
</motion.div>
|
| 463 |
</div>
|
| 464 |
)
|