Apply the public site UI checklist.
Align header, footer, brand, homepage course preview, faculty links, and the course catalog with the documented changes. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8886aa8640
commit
de800d27b1
139 files changed
+3311
-1547
No files matched your search
@@ -0,0 +1,78 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState, useTransition } from "react";
|
||||
import { RefreshCw } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
type SyncPayload = {
|
||||
ok?: boolean;
|
||||
error?: string;
|
||||
data?: {
|
||||
total: number;
|
||||
inserted: number;
|
||||
updated: number;
|
||||
imagesSaved: number;
|
||||
};
|
||||
};
|
||||
|
||||
export function FacultySyncButton() {
|
||||
const router = useRouter();
|
||||
const [pending, startTransition] = useTransition();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
async function onSync() {
|
||||
setBusy(true);
|
||||
setMessage(null);
|
||||
setError(null);
|
||||
try {
|
||||
const res = await fetch("/api/admin/faculty/sync", { method: "POST" });
|
||||
const body = (await res.json()) as SyncPayload;
|
||||
if (!res.ok || !body.ok || !body.data) {
|
||||
setError(body.error ?? "همگامسازی ناموفق بود");
|
||||
return;
|
||||
}
|
||||
const { total, inserted, updated, imagesSaved } = body.data;
|
||||
setMessage(
|
||||
`${total} استاد خوانده شد — ${inserted} جدید، ${updated} بهروز` +
|
||||
(imagesSaved > 0 ? `، ${imagesSaved} تصویر` : ""),
|
||||
);
|
||||
startTransition(() => {
|
||||
router.refresh();
|
||||
});
|
||||
} catch {
|
||||
setError("ارتباط با سرور برقرار نشد");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
const loading = busy || pending;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-stretch gap-1.5 sm:items-end">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={onSync}
|
||||
disabled={loading}
|
||||
className="gap-2"
|
||||
>
|
||||
<RefreshCw className={loading ? "size-4 animate-spin" : "size-4"} />
|
||||
{loading ? "در حال بروزرسانی…" : "بروزرسانی از شبکه اساتید"}
|
||||
</Button>
|
||||
{message ? (
|
||||
<p className="max-w-xs text-xs text-muted-foreground" role="status">
|
||||
{message}
|
||||
</p>
|
||||
) : null}
|
||||
{error ? (
|
||||
<p className="max-w-xs text-xs text-destructive" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user