mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
* refactor(web): migrate from Next.js to Vite + React Router
* fix: update build pipelines for Vite migration (out → dist)
- Dockerfile: npm run build → npx vite build, web/out → web/dist
- pyproject.toml: package-data web/out/** → web/dist/**
- paths.py: support both web/dist (Vite) and web/out (legacy) with fallback
* fix: remove .next from git tracking, add to .gitignore
1334 cached files from web/.next/ were accidentally committed.
Added .next/ to both root and web/.gitignore.
* fix: update build process to use Vite and correct output directory
* fix: update pnpm-lock.yaml and eslint config for Vite migration
* style: fix prettier formatting issues
* fix: add eslint-plugin-react-hooks for Vite migration
* fix: remove undefined eslint rule reference, downgrade react-hooks plugin to v5
* fix(web): clean up remaining Next.js artifacts in Vite migration
- Add vite-env.d.ts for import.meta.env and asset type declarations
- Remove dead layout.tsx (providers already in main.tsx)
- Fix useSearchParams destructuring to [searchParams] tuple (11 locations)
- Replace process.env.NEXT_PUBLIC_* with import.meta.env.VITE_*
- Fix langbotIcon.src to langbotIcon (Vite returns URL string)
- Fix Link href to Link to for react-router-dom
- Fix navigate({ scroll: false }) to { preventScrollReset: true }
- Fix [router] dependency arrays to [navigate]
- Remove Next.js plugin from tsconfig, set rsc: false in components.json
- Replace next lint with eslint in lint-staged
* feat: add tools API endpoint and tools-selector form type
Backend:
- Add GET /api/v1/tools — list all available tools (plugin + MCP)
- Add GET /api/v1/tools/<tool_name> — get specific tool details
Frontend:
- Add TOOLS_SELECTOR form type for plugin config forms
- Multi-select dialog with tool name and description
- Add PluginTool entity type and API client methods
* Revert "feat: add tools API endpoint and tools-selector form type"
This reverts commit 3c637fc563.
281 lines
9.1 KiB
TypeScript
281 lines
9.1 KiB
TypeScript
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
CardHeader,
|
|
CardTitle,
|
|
CardDescription,
|
|
} from '@/components/ui/card';
|
|
import { LanguageSelector } from '@/components/ui/language-selector';
|
|
import { useForm } from 'react-hook-form';
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
import * as z from 'zod';
|
|
import {
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage,
|
|
} from '@/components/ui/form';
|
|
import { useEffect, useState } from 'react';
|
|
import { httpClient } from '@/app/infra/http/HttpClient';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { Mail, Lock, Loader2, Info } from 'lucide-react';
|
|
import {
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
} from '@/components/ui/popover';
|
|
import langbotIcon from '@/app/assets/langbot-logo.webp';
|
|
import { toast } from 'sonner';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { ThemeToggle } from '@/components/ui/theme-toggle';
|
|
import { CustomApiError } from '@/app/infra/entities/common';
|
|
|
|
const formSchema = (t: (key: string) => string) =>
|
|
z.object({
|
|
email: z.string().email(t('common.invalidEmail')),
|
|
password: z.string().min(1, t('common.emptyPassword')),
|
|
});
|
|
|
|
export default function Register() {
|
|
const navigate = useNavigate();
|
|
const { t } = useTranslation();
|
|
const [spaceLoading, setSpaceLoading] = useState(false);
|
|
|
|
const form = useForm<z.infer<ReturnType<typeof formSchema>>>({
|
|
resolver: zodResolver(formSchema(t)),
|
|
defaultValues: {
|
|
email: '',
|
|
password: '',
|
|
},
|
|
});
|
|
|
|
useEffect(() => {
|
|
getIsInitialized();
|
|
}, []);
|
|
|
|
function getIsInitialized() {
|
|
httpClient
|
|
.checkIfInited()
|
|
.then((res) => {
|
|
if (res.initialized) {
|
|
navigate('/login');
|
|
}
|
|
})
|
|
.catch(() => {});
|
|
}
|
|
|
|
function onSubmit(values: z.infer<ReturnType<typeof formSchema>>) {
|
|
handleRegister(values.email, values.password);
|
|
}
|
|
|
|
function handleRegister(username: string, password: string) {
|
|
httpClient
|
|
.initUser(username, password)
|
|
.then(() => {
|
|
toast.success(t('register.initSuccess'));
|
|
navigate('/login');
|
|
})
|
|
.catch((err: Error) => {
|
|
toast.error(t('register.initFailed') + (err as CustomApiError).msg);
|
|
});
|
|
}
|
|
|
|
// Space OAuth redirect handler
|
|
const handleSpaceLoginClick = async () => {
|
|
setSpaceLoading(true);
|
|
|
|
try {
|
|
// Build the redirect URI to the OAuth callback page
|
|
const currentOrigin = window.location.origin;
|
|
const redirectUri = `${currentOrigin}/auth/space/callback`;
|
|
|
|
// Get the authorization URL from backend
|
|
const response = await httpClient.getSpaceAuthorizeUrl(redirectUri);
|
|
|
|
// Redirect to Space authorization page
|
|
window.location.href = response.authorize_url;
|
|
} catch {
|
|
toast.error(t('common.spaceLoginFailed'));
|
|
setSpaceLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center bg-gray-50 dark:bg-neutral-900">
|
|
<Card className="w-[375px] shadow-lg dark:shadow-white/10">
|
|
<CardHeader>
|
|
<div className="flex justify-between items-center mb-6">
|
|
<ThemeToggle />
|
|
<LanguageSelector />
|
|
</div>
|
|
<img
|
|
src={langbotIcon}
|
|
alt="LangBot"
|
|
className="w-16 h-16 mb-4 mx-auto"
|
|
/>
|
|
<CardTitle className="text-2xl text-center">
|
|
{t('register.title')}
|
|
</CardTitle>
|
|
<CardDescription className="text-center">
|
|
{t('register.description')}
|
|
<br />
|
|
{t('register.adminAccountNote')}
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent className="space-y-6">
|
|
{/* Space Login - Recommended */}
|
|
<div className="space-y-3">
|
|
<Button
|
|
type="button"
|
|
className="w-full cursor-pointer"
|
|
onClick={handleSpaceLoginClick}
|
|
disabled={spaceLoading}
|
|
>
|
|
{spaceLoading ? (
|
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
) : (
|
|
<svg
|
|
className="mr-2 h-4 w-4"
|
|
viewBox="0 0 24 24"
|
|
fill="none"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
>
|
|
<path
|
|
d="M12 2L2 7L12 12L22 7L12 2Z"
|
|
stroke="currentColor"
|
|
strokeWidth="2"
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
/>
|
|
<path
|
|
d="M2 17L12 22L22 17"
|
|
stroke="currentColor"
|
|
strokeWidth="2"
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
/>
|
|
<path
|
|
d="M2 12L12 17L22 12"
|
|
stroke="currentColor"
|
|
strokeWidth="2"
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
/>
|
|
</svg>
|
|
)}
|
|
{t('register.initWithSpace')}
|
|
</Button>
|
|
<p className="text-xs text-center text-muted-foreground flex items-center justify-center gap-1">
|
|
{t('register.spaceRecommended')}
|
|
<Popover>
|
|
<PopoverTrigger asChild>
|
|
<Info className="h-3.5 w-3.5 cursor-pointer hover:text-foreground transition-colors" />
|
|
</PopoverTrigger>
|
|
<PopoverContent side="right" className="w-80 text-sm">
|
|
<ul className="space-y-2 list-disc list-inside text-muted-foreground">
|
|
<li>{t('register.spaceInfoTip1')}</li>
|
|
<li>{t('register.spaceInfoTip2')}</li>
|
|
<li>{t('register.spaceInfoTip3')}</li>
|
|
</ul>
|
|
</PopoverContent>
|
|
</Popover>
|
|
</p>
|
|
</div>
|
|
|
|
<div className="relative">
|
|
<div className="absolute inset-0 flex items-center">
|
|
<span className="w-full border-t" />
|
|
</div>
|
|
<div className="relative flex justify-center text-xs uppercase">
|
|
<span className="bg-white dark:bg-card px-2 text-muted-foreground">
|
|
{t('common.or')}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Local Account Registration */}
|
|
<Form {...form}>
|
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
|
|
<FormField
|
|
control={form.control}
|
|
name="email"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>{t('common.email')}</FormLabel>
|
|
<FormControl>
|
|
<div className="relative">
|
|
<Mail className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
|
|
<Input
|
|
placeholder={t('common.enterEmail')}
|
|
className="pl-10"
|
|
{...field}
|
|
/>
|
|
</div>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<FormField
|
|
control={form.control}
|
|
name="password"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>{t('common.password')}</FormLabel>
|
|
<FormControl>
|
|
<div className="relative">
|
|
<Lock className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
|
|
<Input
|
|
type="password"
|
|
placeholder={t('common.enterPassword')}
|
|
className="pl-10"
|
|
{...field}
|
|
/>
|
|
</div>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<Button
|
|
type="submit"
|
|
variant="outline"
|
|
className="w-full cursor-pointer"
|
|
>
|
|
{t('register.registerWithPassword')}
|
|
</Button>
|
|
</form>
|
|
</Form>
|
|
|
|
<p className="text-xs text-center text-muted-foreground">
|
|
{t('common.agreementNotice')}{' '}
|
|
<a
|
|
href="https://langbot.app/privacy"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="underline hover:text-foreground transition-colors"
|
|
>
|
|
{t('common.privacyPolicy')}
|
|
</a>{' '}
|
|
{t('common.and')}{' '}
|
|
<a
|
|
href={t('common.dataCollectionPolicyUrl')}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="underline hover:text-foreground transition-colors"
|
|
>
|
|
{t('common.dataCollectionPolicy')}
|
|
</a>
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|