'use client'; import { useEffect, useState } from 'react'; import { useRouter } from 'next/navigation'; import Image from 'next/image'; import { signIn } from 'next-auth/react'; import { Box, Button, Field, Flex, Input, Stack, Text } from '@chakra-ui/react'; import { reachYandexMetrikaGoal } from '#app/lib/yandexMetrika'; const FIRST_DASHBOARD_PATH = '/routes/dashboard/coinbase/crypto/BTCUSDT/15'; const Install = () => { const router = useRouter(); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(true); const [isSubmitting, setIsSubmitting] = useState(false); useEffect(() => { void fetch('/api/install') .then(async (response) => { if (!response.ok) throw new Error('Unable to check installation'); return (await response.json()) as { required?: boolean }; }) .then(({ required }) => { if (!required) { router.replace('/routes/signin'); return; } setIsLoading(false); }) .catch(() => { setError('Unable to connect to the local TradeJS infrastructure'); setIsLoading(false); }); }, [router]); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); setError(''); if (password.length < 8) { setError('Password must contain at least 8 characters'); return; } if (password !== confirmPassword) { setError('Passwords do not match'); return; } setIsSubmitting(true); const response = await fetch('/api/install', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ password, confirmPassword }), }); const payload = (await response.json().catch(() => null)) as { error?: string; } | null; if (!response.ok) { setError(payload?.error || 'Unable to install TradeJS'); setIsSubmitting(false); return; } reachYandexMetrikaGoal('scaffold_success'); const result = await signIn('credentials', { redirect: false, username: 'root', password, callbackUrl: FIRST_DASHBOARD_PATH, }); if (!result || result.error) { router.replace('/routes/signin'); return; } router.replace(FIRST_DASHBOARD_PATH); }; return (
INSTALL TRADEJS Create your local password This password protects the local root account. It is stored only in your TradeJS infrastructure. Password setPassword(event.target.value)} type="password" autoComplete="new-password" disabled={isLoading} /> Confirm password setConfirmPassword(event.target.value)} type="password" autoComplete="new-password" disabled={isLoading} /> {error ? ( {error} ) : null}
Market chart background
); }; export default Install;