refactor(housekeeping): return result from bulkImport, remove dead server calls, sync i18n
Local Build and Deploy / deploy (push) Successful in 1m15s
Local Build and Deploy / deploy (push) Successful in 1m15s
- bulkImportPermissions now returns {count, errors} instead of void
- ImportSection shows per-entry error details in toast
- Remove testRankPermission server action (test is 100% client-side)
- Clean up unused testing state in TestSection
- Sync pages.admin.{import,translations} keys to all 20 languages
- Add importedWithErrors translation key to all locales
This commit is contained in:
1 parent
702ab9fc67
commit
d693d169dd
24 files changed
+722
-61
No files matched your search
@@ -10,7 +10,6 @@ import {
|
||||
clearAllPermissions,
|
||||
deletePermission,
|
||||
exportPermissions,
|
||||
testRankPermission,
|
||||
upsertPermission,
|
||||
} from "@/actions/admin-housekeeping";
|
||||
|
||||
@@ -429,24 +428,14 @@ export function TestSection({ permissions }: { permissions: HKPerm[] }) {
|
||||
rank: number;
|
||||
permissions: string[];
|
||||
} | null>(null);
|
||||
const [testing, setTesting] = useState(false);
|
||||
|
||||
const handleTest = useCallback(async () => {
|
||||
const handleTest = useCallback(() => {
|
||||
const rank = Number(testRank);
|
||||
if (!Number.isFinite(rank) || rank < 0)
|
||||
return toast.error(t("invalidRank"));
|
||||
setTesting(true);
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.set("testRank", testRank);
|
||||
await testRankPermission(fd);
|
||||
const matching = permissions.filter((p) => p.minRank <= rank);
|
||||
setTestResult({ rank, permissions: matching.map((p) => p.permission) });
|
||||
toast.success(t("testDone", { count: matching.length }));
|
||||
} catch {
|
||||
toast.error(t("errorOccurred"));
|
||||
}
|
||||
setTesting(false);
|
||||
const matching = permissions.filter((p) => p.minRank <= rank);
|
||||
setTestResult({ rank, permissions: matching.map((p) => p.permission) });
|
||||
toast.success(t("testDone", { count: matching.length }));
|
||||
}, [testRank, permissions, t]);
|
||||
|
||||
return (
|
||||
@@ -467,10 +456,9 @@ export function TestSection({ permissions }: { permissions: HKPerm[] }) {
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleTest}
|
||||
disabled={testing}
|
||||
className="btn btn-primary"
|
||||
>
|
||||
{testing ? t("testing") : t("test")}
|
||||
{t("test")}
|
||||
</button>
|
||||
</div>
|
||||
{testResult && (
|
||||
@@ -513,8 +501,17 @@ export function ImportSection() {
|
||||
|
||||
setImporting(true);
|
||||
try {
|
||||
await bulkImportPermissions(fd);
|
||||
toast.success(t("imported"));
|
||||
const result = await bulkImportPermissions(fd);
|
||||
if (result.errors.length > 0) {
|
||||
toast.error(
|
||||
t("importedWithErrors", {
|
||||
count: result.count,
|
||||
errors: result.errors.length,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
toast.success(t("imported", { count: result.count }));
|
||||
}
|
||||
if (textareaRef.current) textareaRef.current.value = "";
|
||||
router.refresh();
|
||||
} catch {
|
||||
|
||||
Reference in new issue
Block a user