Skip to content

Commit a50c1c6

Browse files
committed
Banks Page.
1 parent 36b8502 commit a50c1c6

File tree

13 files changed

+1357
-6
lines changed

13 files changed

+1357
-6
lines changed

src/lib/config/navigation.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,29 @@ export function getActiveAccountAccessMenuItem(pathname: string) {
314314
return found || accountAccessItems[0]; // fallback to first item
315315
}
316316

317+
// Banks navigation items
318+
function buildBanksItems(): NavigationItem[] {
319+
const items: NavigationItem[] = [
320+
{ href: "/banks", label: "Banks", iconComponent: Building2 },
321+
{ href: "/banks/create", label: "Create Bank", iconComponent: Plus },
322+
];
323+
324+
return items;
325+
}
326+
327+
export const banksItems = buildBanksItems();
328+
329+
export function getActiveBanksMenuItem(pathname: string) {
330+
const found = banksItems.find((item) => {
331+
if (item.external) {
332+
return false;
333+
}
334+
return pathname.startsWith(item.href);
335+
});
336+
337+
return found || banksItems[0];
338+
}
339+
317340
// Dynamic Entities navigation items
318341
function buildDynamicEntitiesItems(): NavigationItem[] {
319342
const items: NavigationItem[] = [
@@ -466,6 +489,7 @@ export const navSections: NavigationSection[] = [
466489
{ id: "products", label: "API Products", iconComponent: Package, items: productsItems, basePaths: ["/products"] },
467490
{ id: "financial-products", label: "Financial Products", iconComponent: Banknote, items: financialProductsItems, basePaths: ["/products/financial", "/products/collections"] },
468491
{ id: "rbac", label: "RBAC", iconComponent: Shield, items: rbacItems, basePaths: ["/rbac"] },
492+
{ id: "banks", label: "Banks", iconComponent: Building2, items: banksItems, basePaths: ["/banks"] },
469493
{ id: "account-access", label: "Account Access", iconComponent: Landmark, items: accountAccessItems, basePaths: ["/account-access"] },
470494
{ id: "dynamic-entities", label: "Dynamic Entities", iconComponent: Box, items: dynamicEntitiesItems, basePaths: ["/dynamic-entities"] },
471495
{ id: "dynamic-endpoints", label: "Dynamic Endpoints", iconComponent: Plug, items: dynamicEndpointsItems, basePaths: ["/dynamic-endpoints"] },

src/lib/stores/currentBank.svelte.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class CurrentBankStore {
2121
bank = $state<Bank | null>(null);
2222
banks = $state<Bank[]>([]);
2323
loading = $state(false);
24+
justChanged = $state(false);
25+
private changeTimer: ReturnType<typeof setTimeout> | null = null;
2426

2527
get bankId(): string {
2628
return this.bank?.bank_id ?? "";
@@ -50,6 +52,15 @@ class CurrentBankStore {
5052
}
5153
}
5254
logger.info(`Selected bank: ${bank?.bank_id ?? "none"}`);
55+
56+
// Trigger the highlight animation
57+
if (bank && browser) {
58+
if (this.changeTimer) clearTimeout(this.changeTimer);
59+
this.justChanged = true;
60+
this.changeTimer = setTimeout(() => {
61+
this.justChanged = false;
62+
}, 1500);
63+
}
5364
}
5465

5566
selectById(bankId: string): void {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type { PageServerLoad } from "./$types";
2+
import { error } from "@sveltejs/kit";
3+
import { createLogger } from "$lib/utils/logger";
4+
import { SessionOAuthHelper } from "$lib/oauth/sessionHelper";
5+
import { obp_requests } from "$lib/obp/requests";
6+
7+
const logger = createLogger("BanksPageServer");
8+
9+
export const load: PageServerLoad = async ({ locals }) => {
10+
logger.info("=== Banks Page Load Started ===");
11+
12+
const session = locals.session;
13+
14+
if (!session?.data?.user) {
15+
logger.error("No user in session");
16+
throw error(401, "Unauthorized");
17+
}
18+
19+
const sessionOAuth = SessionOAuthHelper.getSessionOAuth(session);
20+
const accessToken = sessionOAuth?.accessToken;
21+
22+
if (!accessToken) {
23+
logger.error("No access token available");
24+
throw error(401, "No API access token available");
25+
}
26+
27+
logger.info("Access token present, fetching banks");
28+
29+
try {
30+
const endpoint = "/obp/v6.0.0/banks";
31+
logger.info(`Making API request to: ${endpoint}`);
32+
33+
const response = await obp_requests.get(endpoint, accessToken);
34+
35+
const banks = response.banks || [];
36+
logger.info(`Retrieved ${banks.length} banks`);
37+
38+
// Sort banks alphabetically by full_name
39+
banks.sort((a: any, b: any) => {
40+
const nameA = (a.full_name || "").toLowerCase();
41+
const nameB = (b.full_name || "").toLowerCase();
42+
return nameA.localeCompare(nameB);
43+
});
44+
45+
return {
46+
banks,
47+
};
48+
} catch (err: any) {
49+
logger.error("Error fetching banks:", err);
50+
return {
51+
banks: [],
52+
error:
53+
err instanceof Error ? err.message : "Failed to fetch banks",
54+
};
55+
}
56+
};

0 commit comments

Comments
 (0)