inogen/app/admin/pages/EcosystemPage.tsx
2026-10-18 18:12:59 +03:30

35 lines
4.9 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Network, Pencil, Plus } from "lucide-react";
import { useEffect, useState } from "react";
import { Link } from "react-router";
import { Card, EmptyState, ErrorBanner, PageTitle, Select } from "../components/Ui";
import { api } from "../lib/api";
import type { EcosystemActorItem, PagedResult } from "../types";
import { RecordAvatar, useFirstImages } from "../components/RecordImage";
import { ListToolbar, PaginationControls, useDebouncedValue } from "../components/ListControls";
import { ArchiveButton } from "../components/ArchiveButton";
import { BulkArchiveActions, SelectionCheckbox } from "../components/BulkArchive";
export const actorLabels = ["", "دانشگاه/مؤسسه پژوهشی", "مشاور", "شرکت دانش‌بنیان", "استارتاپ", "تأمین‌کننده", "صندوق", "شتاب‌دهنده", "مرکز نوآوری و رشد"];
export function EcosystemPage() {
const [data,setData]=useState<PagedResult<EcosystemActorItem>|null>(null); const [error,setError]=useState("");
const [actorType,setActorType]=useState(""); const [loading,setLoading]=useState(true); const [page,setPage]=useState(1);const[pageSize,setPageSize]=useState(25);const[search,setSearch]=useState("");const debouncedSearch=useDebouncedValue(search);
const [selected,setSelected]=useState<Set<string>>(new Set());
useEffect(()=>{let active=true;setLoading(true);setError("");const query=new URLSearchParams({page:String(page),pageSize:String(pageSize)});if(actorType)query.set("actorType",actorType);if(debouncedSearch)query.set("search",debouncedSearch);
void api<PagedResult<EcosystemActorItem>>(`/api/v1/ecosystem-actors?${query}`)
.then(result=>{if(active)setData(result);}).catch(e=>{if(active)setError(e.message);})
.finally(()=>{if(active)setLoading(false);});return()=>{active=false;};},[actorType,page,pageSize,debouncedSearch]);
const images=useFirstImages("EcosystemActor",data?.items.map(x=>x.id));
const remove=(id:string)=>setData(old=>old?{...old,items:old.items.filter(x=>x.id!==id),totalCount:old.totalCount-1}:old);
return <><PageTitle title="زیست‌بوم فناوری و نوآوری" description="مدیریت یکپارچه هشت نوع بازیگر مستند"
action={<Link className="button link-button" to="/admin/ecosystem/new"><Plus size={18}/>بازیگر جدید</Link>}/>{error&&<ErrorBanner message={error}/>}<Card>
<ListToolbar search={search} onSearch={value=>{setSearch(value);setPage(1);}} total={data?.totalCount??0} placeholder="نام، مدیر یا حوزه فعالیت"><label className="list-filter">نوع بازیگر
<Select value={actorType} onChange={e=>{setActorType(e.target.value);setPage(1);}}><option value="">همه انواع</option>
{actorLabels.map((label,value)=>value>0&&<option key={value} value={value}>{label}</option>)}</Select></label>
</ListToolbar>
{data?.items.length?<BulkArchiveActions entityType="EcosystemActor" records={data.items} selected={selected} onSelectionChange={setSelected} onArchived={ids=>setData(old=>old?{...old,items:old.items.filter(x=>!ids.includes(x.id)),totalCount:old.totalCount-ids.length}:old)}/>:null}
{!data?<div className="loading-line">در حال دریافت اطلاعات…</div>:data.items.length===0?<EmptyState title={actorType||search?"رکوردی برای این فیلتر یافت نشد":"زیست‌بوم هنوز خالی است"} description={actorType||search?"فیلتر یا عبارت جست‌وجو را تغییر دهید.":"دانشگاه، مشاور، شرکت، استارتاپ، صندوق و سایر بازیگران را ثبت کنید."}/>:<><div className={`table-wrap${loading?" is-loading":""}`}><table><thead><tr><th>انتخاب</th><th>تصویر</th><th>نام بازیگر</th><th>نوع</th><th>شروع همکاری</th><th>مدیر</th><th>نیرو</th><th>تفاهم‌نامه</th><th>عملیات</th></tr></thead><tbody>{data.items.map(x=><tr key={x.id}><td><SelectionCheckbox checked={selected.has(x.id)} onChange={checked=>setSelected(old=>{const next=new Set(old);checked?next.add(x.id):next.delete(x.id);return next;})} label={`انتخاب ${x.fullName}`}/></td><td><RecordAvatar attachmentId={images[x.id]??x.imageAttachmentId} label={x.fullName}/></td><td><Network size={15}/> {x.fullName}</td><td>{actorLabels[x.actorType]}</td><td className="latin">{x.collaborationStartDate}</td><td>{String(x.managerName??"—")}</td><td>{String(x.staffCount??"—")}</td><td>{String(x.mouCount??0)}</td><td><div className="row-actions"><Link className="row-action" to={`/admin/ecosystem/${x.id}/edit`}><Pencil size={15}/>ویرایش</Link><ArchiveButton entityType="EcosystemActor" id={x.id} rowVersion={x.rowVersion} onArchived={()=>remove(x.id)}/></div></td></tr>)}</tbody></table></div><PaginationControls page={page} pageSize={pageSize} total={data.totalCount} loading={loading} onPage={setPage} onPageSize={value=>{setPageSize(value);setPage(1);}}/></>}
</Card></>;
}