import { Button, Form, Input } from "antd"; import axios from "axios"; import { t } from "i18next"; import { useState } from "react"; import { useNavigate } from "react-router-dom"; import { ACCOUNT_URL } from "@/config/endpoints"; import { setIMProfile } from "@/utils/storage"; interface LoginResult { code: number; msg: string; data?: { userID: string; nickname: string; imToken: string; expireTimeSeconds?: number; }; } type LoginFormProps = { onBanner: (text: string) => void; }; const LoginForm = ({ onBanner }: LoginFormProps) => { const navigate = useNavigate(); const [loading, setLoading] = useState(false); const onFinish = async (values: { staffNo: string; password: string }) => { setLoading(true); try { const { data: res } = await axios.post( `${ACCOUNT_URL}/api/login`, { staffNo: values.staffNo.trim(), password: values.password, platformID: window.electronAPI?.getPlatform() ?? 5, }, ); if (res.code !== 0 || !res.data) { onBanner(t("toast.staffOrPasswordWrong")); return; } const { userID, imToken } = res.data; setIMProfile({ chatToken: imToken, imToken, userID }); navigate("/chat"); } catch { onBanner(t("toast.networkRetry")); } finally { setLoading(false); } }; return ( <>
{t("placeholder.title")}
{t("placeholder.internalComms")}
{t("placeholder.agreeInternal")}
); }; export default LoginForm;