diff --git a/management/src/api.ts b/management/src/api.ts index 8bc4197..c239def 100644 --- a/management/src/api.ts +++ b/management/src/api.ts @@ -965,3 +965,20 @@ export const apiExam = { }>; }, }; + +export const apiQldt = { + getToken: async (): Promise<{ token: string }> => { + const res = await staffFetch('/qldt-token'); + if (!res.ok) await parseError(res, 'Không tải được token QLĐT'); + return res.json(); + }, + saveToken: async (token: string): Promise<{ ok: boolean; message: string }> => { + const res = await staffFetch('/qldt-token', { + method: 'POST', + body: JSON.stringify({ token }), + }); + if (!res.ok) await parseError(res, 'Lưu token thất bại'); + return res.json(); + }, +}; + diff --git a/management/src/components/AccountsTab.tsx b/management/src/components/AccountsTab.tsx index 3293b15..bec747d 100644 --- a/management/src/components/AccountsTab.tsx +++ b/management/src/components/AccountsTab.tsx @@ -1,8 +1,9 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useAuth } from '../auth/AuthContext'; import { useGitHubConnection } from '../hooks/useGitHubConnection'; import { GitHubReposPanel } from './GitHubReposPanel'; import { OrganizationSection } from './OrganizationSection'; +import { apiQldt } from '../api'; export function ChangePasswordPage({ forced }: { forced?: boolean }) { const { changePassword, logout } = useAuth(); @@ -85,6 +86,40 @@ export function MyAccountTab() { const [pwMsg, setPwMsg] = useState(''); const [pwErr, setPwErr] = useState(''); + // Cấu hình QLĐT Token (Chỉ cho phuocntb@rikkeiacademy.com) + const isQldtAdmin = staff?.email === 'phuocntb@rikkeiacademy.com'; + const [qldtToken, setQldtToken] = useState(''); + const [qldtMsg, setQldtMsg] = useState(''); + const [qldtErr, setQldtErr] = useState(''); + const [loadingQldt, setLoadingQldt] = useState(false); + + useEffect(() => { + if (!isQldtAdmin) return; + setLoadingQldt(true); + apiQldt.getToken() + .then((res) => { + setQldtToken(res.token || ''); + }) + .catch((err) => { + setQldtErr(err.message || 'Lỗi khi tải token QLĐT'); + }) + .finally(() => { + setLoadingQldt(false); + }); + }, [isQldtAdmin]); + + const saveQldtToken = async (e: React.FormEvent) => { + e.preventDefault(); + setQldtMsg(''); + setQldtErr(''); + try { + await apiQldt.saveToken(qldtToken); + setQldtMsg('Đã lưu cấu hình QLĐT token'); + } catch (err: any) { + setQldtErr(err.message || 'Lỗi khi lưu token QLĐT'); + } + }; + const submitPw = async (e: React.FormEvent) => { e.preventDefault(); setPwErr(''); @@ -165,6 +200,45 @@ export function MyAccountTab() { )} + {isQldtAdmin && ( +
+

Cấu hình QLĐT Token

+

+ Cấu hình token đồng bộ dữ liệu lớp học, môn học và điểm danh từ Cổng đào tạo (QLĐT). +

+ {loadingQldt ? ( +

Đang tải cấu hình...

+ ) : ( +
+