You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
// frontend/components/life/ConnectorsModule.tsx — 라이프 "연결" 모듈 (외부 데이터 소스)
|
|
"use client";
|
|
import { Icon } from "@/components/Icon";
|
|
import { useConnectors } from "@/lib/hooks/useConnectors";
|
|
import { connectorsApi } from "@/lib/connectors/api";
|
|
import { ConnectorCard } from "@/components/connectors/ConnectorCard";
|
|
import type { LifeProps } from "./types";
|
|
|
|
export function ConnectorsModule({ toast }: Pick<LifeProps, "toast">) {
|
|
const { data, isLoading, error, refresh } = useConnectors();
|
|
const connectors = data ?? [];
|
|
const total = connectors.length;
|
|
const connected = connectors.filter((c) => c.on).length;
|
|
|
|
const onSync = async (id: string) => {
|
|
const c = connectors.find((x) => x.id === id);
|
|
try {
|
|
const res = await connectorsApi.sync(id);
|
|
await refresh();
|
|
toast(`${c?.name ?? "소스"} · 새 항목 ${res.upserted}건`, c?.tone ?? "blue");
|
|
} catch {
|
|
toast("동기화에 실패했어요", "coral");
|
|
}
|
|
};
|
|
|
|
const onDisconnect = async (id: string) => {
|
|
const c = connectors.find((x) => x.id === id);
|
|
try {
|
|
await connectorsApi.disconnect(id);
|
|
await refresh();
|
|
toast(`${c?.name ?? "소스"} 연결을 해제했어요`, "faint");
|
|
} catch {
|
|
toast("연결 해제에 실패했어요", "coral");
|
|
}
|
|
};
|
|
|
|
const onImport = async (id: string, file: File) => {
|
|
try {
|
|
const res = await connectorsApi.importFile(id, file);
|
|
await refresh();
|
|
toast(res.detail || `${res.imported}건 가져왔어요`, "green");
|
|
} catch {
|
|
toast("이 소스는 파일 가져오기를 지원하지 않아요", "amber");
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<div className="mod-head">
|
|
<div className="mh-ic bg-green">
|
|
<Icon name="link" />
|
|
</div>
|
|
<div className="mh-txt">
|
|
<h2>연결된 데이터 소스</h2>
|
|
<div className="mh-sub">메일·일정·금융·건강·지식 외부 연동</div>
|
|
</div>
|
|
<div className="mh-act">
|
|
<span className="cn-count">
|
|
{connected}/{total} 연결됨
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
{error && (
|
|
<div className="card" role="alert">
|
|
연결 상태를 불러오지 못했어요
|
|
</div>
|
|
)}
|
|
{isLoading && !data && <div className="card">불러오는 중…</div>}
|
|
|
|
<div className="cn-grid" role="region" tabIndex={0} aria-label="연결된 데이터 소스 목록">
|
|
{connectors.map((c) => (
|
|
<ConnectorCard
|
|
key={c.id}
|
|
connector={c}
|
|
onSync={onSync}
|
|
onDisconnect={onDisconnect}
|
|
onImport={(file) => onImport(c.id, file)}
|
|
/>
|
|
))}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|