支持自部署需求管理、交付流程与飞书集成
This commit is contained in:
1 parent
2149aeb6ed
commit
51a2e548f2
152 files changed
+8652
-6394
No files matched your search
@@ -0,0 +1,45 @@
|
||||
'use client';
|
||||
import { useState, type FormEvent } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import { appPath } from '@/lib/base-path';
|
||||
import type { FeishuBinding } from '@/lib/feishu';
|
||||
|
||||
export function FeishuAccount({ binding, configured, passwordSet = true }: { binding: FeishuBinding; configured: boolean; passwordSet?: boolean }) {
|
||||
const router = useRouter();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [success, setSuccess] = useState('');
|
||||
async function unbind(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget;
|
||||
const password = new FormData(form).get('password');
|
||||
setBusy(true); setError(''); setSuccess('');
|
||||
try {
|
||||
const response = await fetch(appPath('/api/account/feishu'), { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ password }) });
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || '解绑失败,请重试。');
|
||||
form.reset(); setSuccess('已解除飞书绑定,其他设备的登录已失效。'); router.replace('/account/feishu'); router.refresh();
|
||||
} catch (cause) { setError(cause instanceof Error ? cause.message : '网络异常,请重试。'); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
return <div>
|
||||
{error && <div className="error-banner" role="alert">{error}</div>}
|
||||
{success && <div className="account-success" role="status">{success}</div>}
|
||||
{binding ? <>
|
||||
<p className="feishu-binding-name">已绑定:<strong>{binding.name}</strong></p>
|
||||
{!passwordSet ? <>
|
||||
<p className="account-intro">当前账号通过飞书注册,尚未设置系统密码。请先设置密码,再解除绑定。</p>
|
||||
<Link className="btn" href="/account/password">设置系统密码</Link>
|
||||
</> : <>
|
||||
<p className="account-intro">解除绑定需验证系统密码,其他设备需重新登录。解绑后此飞书身份再次登录会创建新账号;原需求仍可通过当前账号密码访问。</p>
|
||||
<form className="account-form" onSubmit={unbind} aria-busy={busy}>
|
||||
<fieldset disabled={busy}><label className="account-field" htmlFor="unbind-password">当前系统密码<input id="unbind-password" name="password" type="password" autoComplete="current-password" required maxLength={128} /></label>
|
||||
<button className="btn" type="submit">{busy ? '正在解绑…' : '验证密码并解除绑定'}</button></fieldset>
|
||||
</form>
|
||||
</>}
|
||||
</> : configured ? <form action={appPath('/api/auth/feishu/start')} method="post">
|
||||
<input type="hidden" name="intent" value="bind" /><button type="submit" className="btn primary feishu-login-button">绑定我的飞书账号</button>
|
||||
</form> : <p className="account-intro">飞书登录尚未配置,请联系管理员完成飞书应用设置。</p>}
|
||||
</div>;
|
||||
}
|
||||
Reference in new issue
Block a user