|
|
@@ -8,6 +8,7 @@ import { useAuth } from "@/components/auth/authContext";
|
|
|
import { buildLoginUrl, LOGIN_REASONS } from "@/lib/frontend/authRedirect";
|
|
|
import { searchPath } from "@/lib/frontend/routes";
|
|
|
import { isValidBranchParam } from "@/lib/frontend/params";
|
|
|
+import { isAdminLike as isAdminLikeRole } from "@/lib/frontend/auth/roles";
|
|
|
|
|
|
import { parseSearchUrlState } from "@/lib/frontend/search/urlState";
|
|
|
import { normalizeSearchUrlStateForUser } from "@/lib/frontend/search/normalizeState";
|
|
|
@@ -45,8 +46,7 @@ export default function SearchPage({ branch: routeBranch }) {
|
|
|
const { status: authStatus, user } = useAuth();
|
|
|
|
|
|
const isAuthenticated = authStatus === "authenticated" && user;
|
|
|
- const isAdminDev =
|
|
|
- isAuthenticated && (user.role === "admin" || user.role === "dev");
|
|
|
+ const isAdminLike = isAuthenticated && isAdminLikeRole(user.role);
|
|
|
|
|
|
const parsedUrlState = React.useMemo(() => {
|
|
|
return parseSearchUrlState(searchParams, { routeBranch });
|
|
|
@@ -68,7 +68,7 @@ export default function SearchPage({ branch: routeBranch }) {
|
|
|
setQDraft(urlState.q || "");
|
|
|
}, [urlState.q]);
|
|
|
|
|
|
- const branchesQuery = useSearchBranches({ enabled: isAdminDev });
|
|
|
+ const branchesQuery = useSearchBranches({ enabled: isAdminLike });
|
|
|
|
|
|
const query = useSearchQuery({
|
|
|
searchKey,
|
|
|
@@ -138,24 +138,24 @@ export default function SearchPage({ branch: routeBranch }) {
|
|
|
|
|
|
const handleScopeChange = React.useCallback(
|
|
|
(nextScope) => {
|
|
|
- if (!isAdminDev) return;
|
|
|
+ if (!isAdminLike) return;
|
|
|
replaceStateToUrl(buildNextStateForScopeChange({ urlState, nextScope }));
|
|
|
},
|
|
|
- [isAdminDev, urlState, replaceStateToUrl],
|
|
|
+ [isAdminLike, urlState, replaceStateToUrl],
|
|
|
);
|
|
|
|
|
|
const handleToggleBranch = React.useCallback(
|
|
|
(branchId) => {
|
|
|
- if (!isAdminDev) return;
|
|
|
+ if (!isAdminLike) return;
|
|
|
replaceStateToUrl(buildNextStateForToggleBranch({ urlState, branchId }));
|
|
|
},
|
|
|
- [isAdminDev, urlState, replaceStateToUrl],
|
|
|
+ [isAdminLike, urlState, replaceStateToUrl],
|
|
|
);
|
|
|
|
|
|
const handleClearAllBranches = React.useCallback(() => {
|
|
|
- if (!isAdminDev) return;
|
|
|
+ if (!isAdminLike) return;
|
|
|
replaceStateToUrl(buildNextStateForClearAllBranches({ urlState }));
|
|
|
- }, [isAdminDev, urlState, replaceStateToUrl]);
|
|
|
+ }, [isAdminLike, urlState, replaceStateToUrl]);
|
|
|
|
|
|
const handleLimitChange = React.useCallback(
|
|
|
(nextLimit) => {
|
|
|
@@ -166,7 +166,7 @@ export default function SearchPage({ branch: routeBranch }) {
|
|
|
|
|
|
const handleSingleBranchChange = React.useCallback(
|
|
|
(nextBranch) => {
|
|
|
- if (!isAdminDev) return;
|
|
|
+ if (!isAdminLike) return;
|
|
|
if (!isValidBranchParam(nextBranch)) return;
|
|
|
|
|
|
const href = buildHrefForSingleBranchSwitch({ nextBranch, urlState });
|
|
|
@@ -174,7 +174,7 @@ export default function SearchPage({ branch: routeBranch }) {
|
|
|
|
|
|
router.push(href);
|
|
|
},
|
|
|
- [isAdminDev, urlState, router],
|
|
|
+ [isAdminLike, urlState, router],
|
|
|
);
|
|
|
|
|
|
const handleDateRangeChange = React.useCallback(
|
|
|
@@ -218,7 +218,7 @@ export default function SearchPage({ branch: routeBranch }) {
|
|
|
: "Geben Sie einen Suchbegriff ein, um zu starten.";
|
|
|
|
|
|
const needsBranchSelection = needsMultiBranchSelectionHint({
|
|
|
- isAdminDev,
|
|
|
+ isAdminDev: isAdminLike,
|
|
|
urlState,
|
|
|
});
|
|
|
|
|
|
@@ -239,7 +239,7 @@ export default function SearchPage({ branch: routeBranch }) {
|
|
|
onSubmit={handleSubmit}
|
|
|
currentQuery={urlState.q}
|
|
|
isSubmitting={query.status === "loading"}
|
|
|
- isAdminDev={isAdminDev}
|
|
|
+ isAdminDev={isAdminLike}
|
|
|
scope={urlState.scope}
|
|
|
onScopeChange={handleScopeChange}
|
|
|
onSingleBranchChange={handleSingleBranchChange}
|