Compare commits
235 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5eecc72219 | ||
|
|
b1b348badb | ||
|
|
d2bc179d59 | ||
|
|
9fee74e2a9 | ||
|
|
7c06a1d8b9 | ||
|
|
d78f481192 | ||
|
|
b32853e8fd | ||
|
|
0750c41b7b | ||
|
|
1cd63731a3 | ||
|
|
38fddeb281 | ||
|
|
0205e5be0d | ||
|
|
ca7968cc3c | ||
|
|
e6da6ee9ab | ||
|
|
8802d24789 | ||
|
|
d3954f079b | ||
|
|
0b68038739 | ||
|
|
d36568da54 | ||
|
|
473f126d3e | ||
|
|
222bb2ec64 | ||
|
|
22ec0e36b1 | ||
|
|
0122913052 | ||
|
|
7f2a4634c5 | ||
|
|
704c3d4cb7 | ||
|
|
ef7c026db9 | ||
|
|
dc3522220a | ||
|
|
1693b3a50d | ||
|
|
460c5af6ea | ||
|
|
5a8614e019 | ||
|
|
ae5d034d4b | ||
|
|
d4edf69f2c | ||
|
|
d3a1696d4d | ||
|
|
24792744f9 | ||
|
|
b9ca74e7e6 | ||
|
|
a8f704129b | ||
|
|
62cd55e48f | ||
|
|
e4e3f885ea | ||
|
|
36d698f7ce | ||
|
|
d211a14703 | ||
|
|
c332642e64 | ||
|
|
27f3f2dbba | ||
|
|
02748181b9 | ||
|
|
dcb1f39ff1 | ||
|
|
eb38264c68 | ||
|
|
65404848aa | ||
|
|
3f2ff21eac | ||
|
|
61f9592095 | ||
|
|
76a30d23af | ||
|
|
e9924e9d96 | ||
|
|
340e1a3235 | ||
|
|
4ce56fdc04 | ||
|
|
dd24a0e0d3 | ||
|
|
ff9bccc0e9 | ||
|
|
83bb3fcef2 | ||
|
|
fbb9e33279 | ||
|
|
8228974c0c | ||
|
|
848eccb35b | ||
|
|
25747d7d37 | ||
|
|
b7d6cf8128 | ||
|
|
6589c2dd66 | ||
|
|
571072f6ac | ||
|
|
be4f7f8cec | ||
|
|
056c33b9c5 | ||
|
|
02c4f5c6ef | ||
|
|
30d7c2ed4e | ||
|
|
61442a598f | ||
|
|
b7da446fa5 | ||
|
|
5a626b5394 | ||
|
|
d9a39c30ab | ||
|
|
155a48d7dc | ||
|
|
8ab760815c | ||
|
|
2825dba2e9 | ||
|
|
3049a8cd2f | ||
|
|
86891441d6 | ||
|
|
81d7d16301 | ||
|
|
84e609a774 | ||
|
|
fb310a5953 | ||
|
|
c83386b1d5 | ||
|
|
bfb5a7ef76 | ||
|
|
95b3b93a8a | ||
|
|
9a2199873c | ||
|
|
82a12dadad | ||
|
|
33a7ad5ad2 | ||
|
|
3352e110b8 | ||
|
|
74a700ff87 | ||
|
|
66db34c712 | ||
|
|
eb27f19196 | ||
|
|
969776fb53 | ||
|
|
077e2bb1ad | ||
|
|
da98b7b2b7 | ||
|
|
2467cb2f5a | ||
|
|
5ae3a51d81 | ||
|
|
d09cf6d04c | ||
|
|
2c6e099596 | ||
|
|
990d0295b3 | ||
|
|
318ca517f7 | ||
|
|
0e645d9bae | ||
|
|
d51aa9429e | ||
|
|
c8f0a103c6 | ||
|
|
5987a759b8 | ||
|
|
6bfbed8fb6 | ||
|
|
b7e4ec4a1b | ||
|
|
35b6d98e6a | ||
|
|
3e248f95a8 | ||
|
|
e136fc4b75 | ||
|
|
692bee574e | ||
|
|
482f16c77e | ||
|
|
c6ac4455f8 | ||
|
|
ac0fedd8b2 | ||
|
|
06cf02f43f | ||
|
|
23aa8b08d4 | ||
|
|
2b69b1e27b | ||
|
|
4dec8113fe | ||
|
|
28534e97c0 | ||
|
|
43b6f32145 | ||
|
|
b3eab6ae26 | ||
|
|
a5d10b3539 | ||
|
|
1c901a9dda | ||
|
|
1e94333d8f | ||
|
|
4006dd128e | ||
|
|
7d9744a40e | ||
|
|
8654471042 | ||
|
|
e9711339bd | ||
|
|
0c030efef2 | ||
|
|
e4e04ea34e | ||
|
|
f4bf549b99 | ||
|
|
8cc4f567f8 | ||
|
|
a939b841f3 | ||
|
|
caa43e8eb0 | ||
|
|
0a8750ea36 | ||
|
|
2d6800eff8 | ||
|
|
544527f282 | ||
|
|
91020e32ea | ||
|
|
5a823d62f0 | ||
|
|
a00d6ce2ce | ||
|
|
f47644e8c6 | ||
|
|
c0ee21d6fa | ||
|
|
7dd33084f5 | ||
|
|
ca41b7af0a | ||
|
|
aa97f36819 | ||
|
|
d9c50d1298 | ||
|
|
61fafecb78 | ||
|
|
13e92ccd34 | ||
|
|
433ba3faf9 | ||
|
|
da6c7bbf3e | ||
|
|
90e58734ad | ||
|
|
03e16a9b54 | ||
|
|
53e08e8e4b | ||
|
|
84fe79b37b | ||
|
|
1a6578100a | ||
|
|
3270dc4585 | ||
|
|
8fabaf7b86 | ||
|
|
8006e5e1f6 | ||
|
|
5e0b8eb2a4 | ||
|
|
f2e05484dc | ||
|
|
37949a4e1f | ||
|
|
abf39abe74 | ||
|
|
957099786c | ||
|
|
2191fe9066 | ||
|
|
bc947183e3 | ||
|
|
16afa1ed8a | ||
|
|
541cb262ee | ||
|
|
eaaea6e459 | ||
|
|
34501f5f0d | ||
|
|
dcac53d181 | ||
|
|
cb2e70e42d | ||
|
|
417b77539f | ||
|
|
947342e196 | ||
|
|
c5fd26cb3e | ||
|
|
6c8b8ed3cc | ||
|
|
abacfd78c8 | ||
|
|
26487cff89 | ||
|
|
46f3f5c498 | ||
|
|
6bce7eb6be | ||
|
|
155c30559f | ||
|
|
ec8ef8346a | ||
|
|
de3da84dff | ||
|
|
47164e8546 | ||
|
|
34e793c75c | ||
|
|
4018b263f2 | ||
|
|
f0fee4fd82 | ||
|
|
91f53b35b1 | ||
|
|
73d6bd32db | ||
|
|
6b2c19778b | ||
|
|
355fa5cfb6 | ||
|
|
7cf471402b | ||
|
|
7480094419 | ||
|
|
d69bd5d115 | ||
|
|
ca29d527c9 | ||
|
|
4ed1bf5abe | ||
|
|
eb73401896 | ||
|
|
33006f8f43 | ||
|
|
6b2cb8a52f | ||
|
|
75ca7f177f | ||
|
|
7efbccfc90 | ||
|
|
e7662bc3dd | ||
|
|
59346334db | ||
|
|
c70a4e5cb8 | ||
|
|
a29bd1ab68 | ||
|
|
a8fb3ad931 | ||
|
|
effabf0695 | ||
|
|
758a3a2257 | ||
|
|
6f5b5dc679 | ||
|
|
6c44beda67 | ||
|
|
ebe0a2fe86 | ||
|
|
3cb38e2e9f | ||
|
|
ad40b2207a | ||
|
|
9402c2535b | ||
|
|
e0351a8771 | ||
|
|
b60ba068cd | ||
|
|
70cfe34476 | ||
|
|
3b1738bae4 | ||
|
|
332d4d51d0 | ||
|
|
7672533e86 | ||
|
|
410e600673 | ||
|
|
798a8f1880 | ||
|
|
7401ca62d2 | ||
|
|
e46634cf27 | ||
|
|
7b48bc080c | ||
|
|
0cb339366c | ||
|
|
3d36198b06 | ||
|
|
2352ea9e58 | ||
|
|
b559376116 | ||
|
|
cb6682ea2e | ||
|
|
6d2f1b7b2f | ||
|
|
fcb0f1edd7 | ||
|
|
0c8f68adfd | ||
|
|
7f71589af1 | ||
|
|
f7ef4b32ca | ||
|
|
ee30bff5ef | ||
|
|
4f2daa7953 | ||
|
|
d8aa1ef90d | ||
|
|
f3ad639a01 | ||
|
|
facf6ac94e | ||
|
|
d8fde49da4 | ||
|
|
460fed3ed0 |
@@ -1,3 +1,5 @@
|
|||||||
.git/
|
.git/
|
||||||
data/
|
data/
|
||||||
docker-compose.dev.yml
|
docker-compose.dev.yml
|
||||||
|
frontend/node_modules/
|
||||||
|
.venv/
|
||||||
|
|||||||
57
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["main", "dev"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["main", "dev"]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test-python:
|
||||||
|
name: Test Python
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: "!contains(github.event.head_commit.message, 'chore(ci): Bump version to')"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install uv
|
||||||
|
uses: astral-sh/setup-uv@v5
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version-file: "pyproject.toml"
|
||||||
|
|
||||||
|
- name: Create config directory for tests
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.config/leggen
|
||||||
|
cp config.example.toml ~/.config/leggen/config.toml
|
||||||
|
|
||||||
|
- name: Run Python tests
|
||||||
|
run: uv run pytest
|
||||||
|
|
||||||
|
test-frontend:
|
||||||
|
name: Test Frontend
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: "!contains(github.event.head_commit.message, 'chore(ci): Bump version to')"
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ./frontend
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "20"
|
||||||
|
cache: "npm"
|
||||||
|
cache-dependency-path: frontend/package-lock.json
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm install
|
||||||
|
|
||||||
|
- name: Run lint
|
||||||
|
run: npm run lint
|
||||||
|
|
||||||
|
- name: Run build
|
||||||
|
run: npm run build
|
||||||
133
.github/workflows/release.yml
vendored
@@ -6,30 +6,43 @@ on:
|
|||||||
- "**"
|
- "**"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-pypi:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
- name: Install uv
|
||||||
- name: Set up Python
|
uses: astral-sh/setup-uv@v5
|
||||||
uses: actions/setup-python@v4
|
- name: "Set up Python"
|
||||||
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: "3.12"
|
python-version-file: "pyproject.toml"
|
||||||
|
|
||||||
- name: Build Package
|
- name: Build Package
|
||||||
run: |
|
run: uv build
|
||||||
python -m pip install --upgrade pip
|
- name: Store the distribution packages
|
||||||
pip install poetry
|
uses: actions/upload-artifact@v4
|
||||||
poetry config virtualenvs.create false
|
with:
|
||||||
poetry build -f wheel
|
name: python-package-distributions
|
||||||
|
path: dist/
|
||||||
|
|
||||||
|
publish-to-pypi:
|
||||||
|
name: Publish Python distribution to PyPI
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
id-token: write # IMPORTANT: mandatory for trusted publishing
|
||||||
|
needs:
|
||||||
|
- build
|
||||||
|
steps:
|
||||||
|
- name: Download all the dists
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: python-package-distributions
|
||||||
|
path: dist/
|
||||||
|
- name: Install uv
|
||||||
|
uses: astral-sh/setup-uv@v5
|
||||||
- name: Publish package
|
- name: Publish package
|
||||||
env:
|
run: uv publish
|
||||||
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
|
|
||||||
run: poetry publish
|
|
||||||
|
|
||||||
push-docker:
|
push-docker-backend:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
@@ -49,10 +62,12 @@ jobs:
|
|||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Docker meta
|
- name: Docker meta backend
|
||||||
id: meta
|
id: meta-backend
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
|
flavor: |
|
||||||
|
latest=false
|
||||||
# list of Docker images to use as base name for tags
|
# list of Docker images to use as base name for tags
|
||||||
images: |
|
images: |
|
||||||
elisiariocouto/leggen
|
elisiariocouto/leggen
|
||||||
@@ -62,11 +77,87 @@ jobs:
|
|||||||
type=ref,event=tag
|
type=ref,event=tag
|
||||||
type=semver,pattern={{version}}
|
type=semver,pattern={{version}}
|
||||||
type=semver,pattern={{major}}.{{minor}}
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
- name: Build and push
|
type=raw,value=latest
|
||||||
|
- name: Build and push backend
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta-backend.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta-backend.outputs.labels }}
|
||||||
|
|
||||||
|
push-docker-frontend:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: elisiariocouto
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Docker meta frontend
|
||||||
|
id: meta-frontend
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
flavor: |
|
||||||
|
latest=false
|
||||||
|
# list of Docker images to use as base name for tags
|
||||||
|
images: |
|
||||||
|
elisiariocouto/leggen
|
||||||
|
ghcr.io/elisiariocouto/leggen
|
||||||
|
# generate Docker tags based on the following events/attributes
|
||||||
|
tags: |
|
||||||
|
type=ref,event=tag,suffix=-frontend
|
||||||
|
type=semver,pattern={{version}},suffix=-frontend
|
||||||
|
type=semver,pattern={{major}}.{{minor}},suffix=-frontend
|
||||||
|
type=raw,value=latest-frontend
|
||||||
|
- name: Build and push frontend
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: ./frontend
|
||||||
|
file: ./frontend/Dockerfile
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta-frontend.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta-frontend.outputs.labels }}
|
||||||
|
|
||||||
|
create-github-release:
|
||||||
|
name: Create GitHub Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [build, publish-to-pypi, push-docker-backend, push-docker-frontend]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Generate release notes
|
||||||
|
uses: orhun/git-cliff-action@v4
|
||||||
|
id: release_notes
|
||||||
|
with:
|
||||||
|
config: cliff.toml
|
||||||
|
args: --current
|
||||||
|
env:
|
||||||
|
GITHUB_REPO: ${{ github.repository }}
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
tag_name: ${{ github.ref_name }}
|
||||||
|
name: Release ${{ github.ref_name }}
|
||||||
|
body: ${{ steps.release_notes.outputs.content }}
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
|
|||||||
6
.gitignore
vendored
@@ -14,7 +14,6 @@ dist/
|
|||||||
downloads/
|
downloads/
|
||||||
eggs/
|
eggs/
|
||||||
.eggs/
|
.eggs/
|
||||||
lib/
|
|
||||||
lib64/
|
lib64/
|
||||||
parts/
|
parts/
|
||||||
sdist/
|
sdist/
|
||||||
@@ -162,3 +161,8 @@ data/
|
|||||||
docker-compose.dev.yml
|
docker-compose.dev.yml
|
||||||
nocodb/
|
nocodb/
|
||||||
sql/
|
sql/
|
||||||
|
leggen.db
|
||||||
|
*.db
|
||||||
|
config.toml
|
||||||
|
.claude/
|
||||||
|
.playwright-mcp/
|
||||||
|
|||||||
12
.mcp.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"shadcn": {
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["shadcn@latest", "mcp"]
|
||||||
|
},
|
||||||
|
"playwright": {
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["@playwright/mcp@latest"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,22 @@
|
|||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/psf/black
|
|
||||||
rev: 24.2.0
|
|
||||||
hooks:
|
|
||||||
- id: black
|
|
||||||
language_version: python3.12
|
|
||||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||||
# Ruff version.
|
rev: "v0.13.0"
|
||||||
rev: "v0.2.1"
|
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff-check
|
||||||
|
- id: ruff-format
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.5.0
|
rev: v6.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
exclude: ".*\\.md$"
|
exclude: ".*\\.md$"
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
- id: check-added-large-files
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: mypy
|
||||||
|
name: Static type check with mypy
|
||||||
|
entry: uv run mypy leggen --check-untyped-defs
|
||||||
|
files: "^leggen/.*"
|
||||||
|
language: "system"
|
||||||
|
types: ["python"]
|
||||||
|
always_run: true
|
||||||
|
pass_filenames: false
|
||||||
|
|||||||
141
AGENTS.md
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
# Agent Guidelines for Leggen
|
||||||
|
|
||||||
|
## Quick Setup for Development
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
- **uv** must be installed for Python dependency management (can be installed via `pip install uv`)
|
||||||
|
- **Configuration file**: Copy `config.example.toml` to `config.toml` before running any commands:
|
||||||
|
```bash
|
||||||
|
cp config.example.toml config.toml
|
||||||
|
```
|
||||||
|
|
||||||
|
### Generate Mock Database
|
||||||
|
The leggen CLI provides a command to generate a mock database for testing:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Generate sample database with default settings (3 accounts, 50 transactions each)
|
||||||
|
uv run leggen --config config.toml generate_sample_db --database /path/to/test.db --force
|
||||||
|
|
||||||
|
# Custom configuration
|
||||||
|
uv run leggen --config config.toml generate_sample_db --database ./test-data.db --accounts 5 --transactions 100 --force
|
||||||
|
```
|
||||||
|
|
||||||
|
The command outputs instructions for setting the required environment variable to use the generated database.
|
||||||
|
|
||||||
|
### Start the API Server
|
||||||
|
1. Install uv if not already installed: `pip install uv`
|
||||||
|
2. Set the database environment variable to point to your generated mock database:
|
||||||
|
```bash
|
||||||
|
export LEGGEN_DATABASE_PATH=/path/to/your/generated/database.db
|
||||||
|
```
|
||||||
|
3. Ensure the API can find the configuration file (choose one):
|
||||||
|
```bash
|
||||||
|
# Option 1: Copy config to the expected location
|
||||||
|
mkdir -p ~/.config/leggen && cp config.toml ~/.config/leggen/config.toml
|
||||||
|
|
||||||
|
# Option 2: Set environment variable to current config file
|
||||||
|
export LEGGEN_CONFIG_FILE=./config.toml
|
||||||
|
```
|
||||||
|
4. Start the API server:
|
||||||
|
```bash
|
||||||
|
uv run leggen server
|
||||||
|
```
|
||||||
|
- For development mode with auto-reload: `uv run leggen server --reload`
|
||||||
|
- API will be available at `http://localhost:8000` with docs at `http://localhost:8000/api/v1/docs`
|
||||||
|
|
||||||
|
### Start the Frontend
|
||||||
|
1. Navigate to the frontend directory: `cd frontend`
|
||||||
|
2. Install npm dependencies: `npm install`
|
||||||
|
3. Start the development server: `npm run dev`
|
||||||
|
- Frontend will be available at `http://localhost:3000`
|
||||||
|
- The frontend is configured to connect to the API at `http://localhost:8000/api/v1`
|
||||||
|
|
||||||
|
## Build/Lint/Test Commands
|
||||||
|
|
||||||
|
### Frontend (React/TypeScript)
|
||||||
|
- **Dev server**: `cd frontend && npm run dev`
|
||||||
|
- **Build**: `cd frontend && npm run build`
|
||||||
|
- **Lint**: `cd frontend && npm run lint`
|
||||||
|
|
||||||
|
### Backend (Python)
|
||||||
|
- **Lint**: `uv run ruff check .`
|
||||||
|
- **Format**: `uv run ruff format .`
|
||||||
|
- **Type check**: `uv run mypy leggen --check-untyped-defs`
|
||||||
|
- **All checks**: `uv run pre-commit run --all-files`
|
||||||
|
- **Run all tests**: `uv run pytest`
|
||||||
|
- **Run single test**: `uv run pytest tests/unit/test_api_accounts.py::TestAccountsAPI::test_get_all_accounts_success -v`
|
||||||
|
- **Run tests by marker**: `uv run pytest -m "api"` or `uv run pytest -m "unit"`
|
||||||
|
|
||||||
|
## Code Style Guidelines
|
||||||
|
|
||||||
|
### Python
|
||||||
|
- **Imports**: Standard library → Third-party → Local (blank lines between groups)
|
||||||
|
- **Naming**: snake_case for variables/functions, PascalCase for classes
|
||||||
|
- **Types**: Use type hints for all function parameters and return values
|
||||||
|
- **Error handling**: Use specific exceptions, loguru for logging
|
||||||
|
- **Path handling**: Use `pathlib.Path` instead of `os.path`
|
||||||
|
- **CLI**: Use Click framework with proper option decorators
|
||||||
|
|
||||||
|
### TypeScript/React
|
||||||
|
- **Imports**: React hooks first, then third-party, then local components/types
|
||||||
|
- **Naming**: PascalCase for components, camelCase for variables/functions
|
||||||
|
- **Types**: Use `import type` for type-only imports, define interfaces/types
|
||||||
|
- **Styling**: Tailwind CSS with `clsx` utility for conditional classes
|
||||||
|
- **UI Components**: shadcn/ui components for consistent design system
|
||||||
|
- **Icons**: lucide-react with consistent naming
|
||||||
|
- **Data fetching**: @tanstack/react-query with proper error handling
|
||||||
|
- **Components**: Functional components with hooks, proper TypeScript typing
|
||||||
|
|
||||||
|
## Frontend Structure
|
||||||
|
|
||||||
|
### Layout Architecture
|
||||||
|
- **Root Layout**: `frontend/src/routes/__root.tsx` - Contains main app structure with Sidebar and Header
|
||||||
|
- **Header/Navbar**: `frontend/src/components/Header.tsx` - Top navigation bar (sticky on mobile only)
|
||||||
|
- **Sidebar**: `frontend/src/components/Sidebar.tsx` - Left navigation sidebar
|
||||||
|
- **Routes**: `frontend/src/routes/` - TanStack Router file-based routing
|
||||||
|
|
||||||
|
### Key Components Location
|
||||||
|
- **UI Components**: `frontend/src/components/ui/` - shadcn/ui components and reusable UI primitives
|
||||||
|
- **Feature Components**: `frontend/src/components/` - Main app components
|
||||||
|
- **Pages**: `frontend/src/routes/` - Route components (index.tsx, transactions.tsx, etc.)
|
||||||
|
- **Hooks**: `frontend/src/hooks/` - Custom React hooks
|
||||||
|
- **API**: `frontend/src/lib/api.ts` - API client configuration
|
||||||
|
- **Context**: `frontend/src/contexts/` - React contexts (ThemeContext, etc.)
|
||||||
|
|
||||||
|
### Routing Structure
|
||||||
|
- `/` - Overview/Dashboard (TransactionsTable component)
|
||||||
|
- `/transactions` - Transactions page
|
||||||
|
- `/analytics` - Analytics page
|
||||||
|
- `/notifications` - Notifications page
|
||||||
|
- `/settings` - Settings page
|
||||||
|
|
||||||
|
### General
|
||||||
|
- **Formatting**: ruff for Python, ESLint for TypeScript
|
||||||
|
- **Commits**: Use conventional commits with optional scopes, run pre-commit hooks before pushing
|
||||||
|
- Format: `type(scope): Description starting with uppercase and ending with period.`
|
||||||
|
- Scopes: `cli`, `api`, `frontend` (optional)
|
||||||
|
- Types: `feat`, `fix`, `refactor` (avoid too many different types)
|
||||||
|
- Examples:
|
||||||
|
- `feat(frontend): Add support for S3 backups.`
|
||||||
|
- `fix(api): Resolve authentication timeout issues.`
|
||||||
|
- `refactor(cli): Improve error handling for missing config.`
|
||||||
|
- Avoid including specific numbers, counts, or data-dependent information that may become outdated
|
||||||
|
- **Security**: Never log sensitive data, use environment variables for secrets
|
||||||
|
|
||||||
|
## AI Development Support
|
||||||
|
|
||||||
|
### shadcn/ui Integration
|
||||||
|
This project uses shadcn/ui for consistent UI components. The MCP server is configured for AI agents to:
|
||||||
|
- Search and browse available shadcn/ui components
|
||||||
|
- View component implementation details and examples
|
||||||
|
- Generate proper installation commands for new components
|
||||||
|
|
||||||
|
Use the shadcn MCP tools when working with UI components to ensure consistency with the existing design system.
|
||||||
|
|
||||||
|
## Contributing Guidelines
|
||||||
|
|
||||||
|
This repository follows conventional changelog practices. Refer to `CONTRIBUTING.md` for detailed contribution guidelines including:
|
||||||
|
- Commit message format and scoping
|
||||||
|
- Release process using `scripts/release.sh`
|
||||||
|
- Pre-commit hooks setup with `pre-commit install`
|
||||||
|
- When the pre-commit fails, the commit is canceled
|
||||||
1048
CHANGELOG.md
@@ -1,9 +1,19 @@
|
|||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
Install Poetry and run `poetry install` to install dependencies. Then run `poetry shell` to activate the virtual environment.
|
This project uses **uv** for Python dependency management and **shadcn/ui** for frontend components.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
Install uv and run `uv sync` to install dependencies.
|
||||||
|
|
||||||
Run `pre-commit install` to install the pre-commit hooks.
|
Run `pre-commit install` to install the pre-commit hooks.
|
||||||
|
|
||||||
|
## Frontend Development
|
||||||
|
The frontend uses shadcn/ui components for consistent design. When adding new UI components:
|
||||||
|
- Check if a shadcn/ui component exists for your use case
|
||||||
|
- Follow the existing component patterns in `frontend/src/components/ui/`
|
||||||
|
- Use Tailwind CSS classes for styling
|
||||||
|
- Ensure components are accessible and follow the design system
|
||||||
|
|
||||||
## Commit messages
|
## Commit messages
|
||||||
|
|
||||||
type(scope/[subscope]): Title starting with uppercase and sentence ending with period.
|
type(scope/[subscope]): Title starting with uppercase and sentence ending with period.
|
||||||
|
|||||||
37
Dockerfile
@@ -1,24 +1,33 @@
|
|||||||
FROM python:3.12-alpine as builder
|
FROM python:3.13-alpine AS builder
|
||||||
ARG POETRY_VERSION="1.7.1"
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN apk add --no-cache gcc libffi-dev musl-dev && \
|
|
||||||
pip install --no-cache-dir --upgrade pip && \
|
|
||||||
pip install --no-cache-dir -q poetry=="${POETRY_VERSION}"
|
|
||||||
COPY . .
|
|
||||||
RUN poetry config virtualenvs.create false && poetry build -f wheel
|
|
||||||
|
|
||||||
FROM python:3.12-alpine
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||||
|
--mount=type=bind,source=uv.lock,target=uv.lock \
|
||||||
|
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
|
||||||
|
uv sync --locked --no-install-project --no-editable
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||||
|
uv sync --locked --no-editable --no-group dev
|
||||||
|
|
||||||
|
FROM python:3.13-alpine
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source="https://github.com/elisiariocouto/leggen"
|
LABEL org.opencontainers.image.source="https://github.com/elisiariocouto/leggen"
|
||||||
LABEL org.opencontainers.image.authors="Elisiário Couto <elisiario@couto.io>"
|
LABEL org.opencontainers.image.authors="Elisiário Couto <elisiario@couto.io>"
|
||||||
LABEL org.opencontainers.image.licenses="MIT"
|
LABEL org.opencontainers.image.licenses="MIT"
|
||||||
LABEL org.opencontainers.image.title="leggen"
|
LABEL org.opencontainers.image.title="Leggen API"
|
||||||
LABEL org.opencontainers.image.description="An Open Banking CLI"
|
LABEL org.opencontainers.image.description="Open Banking API for Leggen"
|
||||||
LABEL org.opencontainers.image.url="https://github.com/elisiariocouto/leggen"
|
LABEL org.opencontainers.image.url="https://github.com/elisiariocouto/leggen"
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /app/dist/ /app/
|
|
||||||
RUN pip --no-cache-dir install leggen*.whl && \
|
COPY --from=builder /app/.venv /app/.venv
|
||||||
rm leggen*.whl
|
|
||||||
ENTRYPOINT ["/usr/local/bin/leggen"]
|
EXPOSE 8000
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s CMD wget -q --spider http://127.0.0.1:8000/api/v1/health || exit 1
|
||||||
|
|
||||||
|
CMD ["/app/.venv/bin/leggen", "server"]
|
||||||
|
|||||||
167
README.md
@@ -1,77 +1,136 @@
|
|||||||
# 💲 leggen
|
# 💲 leggen
|
||||||
|
|
||||||
An Open Banking CLI.
|
|
||||||
|
|
||||||
This tool aims to provide a simple way to connect to banks using the GoCardless Open Banking API.
|
A self hosted Open Banking Dashboard, API and CLI for managing bank connections and transactions.
|
||||||
|
|
||||||
Having a simple CLI tool to connect to banks and list transactions can be very useful for developers and companies that need to access bank data.
|
Having your bank data accessible through both CLI and REST API gives you the power to backup, analyze, create reports, and integrate with other applications.
|
||||||
|
|
||||||
Having your bank data in a database, gives you the power to backup, analyze and create reports with your data.
|

|
||||||
|
|
||||||
## 🛠️ Technologies
|
## 🛠️ Technologies
|
||||||
- Python: for the CLI
|
|
||||||
|
### Frontend
|
||||||
|
- [React](https://reactjs.org/): Modern web interface with TypeScript
|
||||||
|
- [Vite](https://vitejs.dev/): Fast build tool and development server
|
||||||
|
- [Tailwind CSS](https://tailwindcss.com/): Utility-first CSS framework
|
||||||
|
- [shadcn/ui](https://ui.shadcn.com/): Modern component system built on Radix UI
|
||||||
|
- [TanStack Query](https://tanstack.com/query): Powerful data synchronization for React
|
||||||
|
|
||||||
|
### 🔌 API & Backend
|
||||||
|
- [FastAPI](https://fastapi.tiangolo.com/): High-performance async API backend (integrated into `leggen server`)
|
||||||
- [GoCardless Open Banking API](https://developer.gocardless.com/bank-account-data/overview): for connecting to banks
|
- [GoCardless Open Banking API](https://developer.gocardless.com/bank-account-data/overview): for connecting to banks
|
||||||
|
- [APScheduler](https://apscheduler.readthedocs.io/): Background job scheduling with configurable cron
|
||||||
|
|
||||||
|
### 📦 Storage
|
||||||
- [SQLite](https://www.sqlite.org): for storing transactions, simple and easy to use
|
- [SQLite](https://www.sqlite.org): for storing transactions, simple and easy to use
|
||||||
- [MongoDB](https://www.mongodb.com/docs/): alternative store for transactions, good balance between performance and query capabilities
|
|
||||||
- [Ofelia](https://github.com/mcuadros/ofelia): for scheduling regular syncs with the database when using Docker
|
|
||||||
|
|
||||||
## ✨ Features
|
## ✨ Features
|
||||||
- Connect to banks using GoCardless Open Banking API
|
|
||||||
- List all connected banks and their status
|
|
||||||
- List balances of all connected accounts
|
|
||||||
- List transactions for all connected accounts
|
|
||||||
- Sync all transactions with a MongoDB database
|
|
||||||
|
|
||||||
## 🚀 Installation and Configuration
|
### 🎯 Core Banking Features
|
||||||
|
- Connect to banks using GoCardless Open Banking API (30+ EU countries)
|
||||||
|
- List all connected banks and their connection statuses
|
||||||
|
- View balances of all connected accounts
|
||||||
|
- List and filter transactions across all accounts
|
||||||
|
- Support for both booked and pending transactions
|
||||||
|
|
||||||
In order to use `leggen`, you need to create a GoCardless account. GoCardless is a service that provides access to Open Banking APIs. You can create an account at https://gocardless.com/bank-account-data/.
|
### 🔄 Data Management
|
||||||
|
- Sync all transactions with SQLite database
|
||||||
|
- Background sync scheduling with configurable cron expressions
|
||||||
|
- Automatic transaction deduplication and status tracking
|
||||||
|
- Real-time sync status monitoring
|
||||||
|
|
||||||
After creating an account and getting your API keys, the best way is to use the [compose file](docker-compose.yml). Open the file and adapt it to your needs. Then run the following command:
|
### 📡 API & Integration
|
||||||
|
- **REST API**: Complete FastAPI backend with comprehensive endpoints
|
||||||
|
- **CLI Interface**: Enhanced command-line tools with new options
|
||||||
|
|
||||||
|
### 🔔 Notifications & Monitoring
|
||||||
|
- Discord and Telegram notifications for filtered transactions
|
||||||
|
- Configurable transaction filters (case-sensitive/insensitive)
|
||||||
|
- Account expiry notifications and status alerts
|
||||||
|
- Comprehensive logging and error handling
|
||||||
|
|
||||||
|
## 🚀 Quick Start
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
1. Create a GoCardless account at [https://gocardless.com/bank-account-data/](https://gocardless.com/bank-account-data/)
|
||||||
|
2. Get your API credentials (key and secret)
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
#### Docker Compose (Recommended)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker compose up -d
|
# Clone the repository
|
||||||
|
git clone https://github.com/elisiariocouto/leggen.git
|
||||||
|
cd leggen
|
||||||
|
|
||||||
|
# Create your configuration
|
||||||
|
mkdir -p data && cp config.example.toml data/config.toml
|
||||||
|
# Edit data/config.toml with your GoCardless credentials
|
||||||
|
|
||||||
|
# Start all services
|
||||||
|
docker compose up -d
|
||||||
|
|
||||||
|
# Access the web interface at http://localhost:3000
|
||||||
|
# API documentation at http://localhost:3000/api/v1/docs
|
||||||
```
|
```
|
||||||
|
|
||||||
The leggen container will exit, this is expected. Now you can run the following command to create the configuration file:
|
### Configuration
|
||||||
|
|
||||||
|
Create a configuration file at `./data/config.toml` (for Docker) or `~/.config/leggen/config.toml` (for local development):
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[gocardless]
|
||||||
|
key = "your-api-key"
|
||||||
|
secret = "your-secret-key"
|
||||||
|
url = "https://bankaccountdata.gocardless.com/api/v2"
|
||||||
|
|
||||||
|
[database]
|
||||||
|
sqlite = true
|
||||||
|
|
||||||
|
# Optional: Background sync scheduling
|
||||||
|
[scheduler.sync]
|
||||||
|
enabled = true
|
||||||
|
hour = 3 # 3 AM
|
||||||
|
minute = 0
|
||||||
|
# cron = "0 3 * * *" # Alternative: use cron expression
|
||||||
|
|
||||||
|
# Optional: Discord notifications
|
||||||
|
[notifications.discord]
|
||||||
|
webhook = "https://discord.com/api/webhooks/..."
|
||||||
|
enabled = true
|
||||||
|
|
||||||
|
# Optional: Telegram notifications
|
||||||
|
[notifications.telegram]
|
||||||
|
token = "your-bot-token"
|
||||||
|
chat_id = 12345
|
||||||
|
enabled = true
|
||||||
|
|
||||||
|
# Optional: Transaction filters for notifications
|
||||||
|
[filters]
|
||||||
|
case_insensitive = ["salary", "utility"]
|
||||||
|
case_sensitive = ["SpecificStore"]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📖 Usage
|
||||||
|
|
||||||
|
### Web Interface
|
||||||
|
Access the React web interface at `http://localhost:3000` after starting the services.
|
||||||
|
|
||||||
|
### API Service
|
||||||
|
Visit `http://localhost:3000/api/v1/docs` for interactive API documentation.
|
||||||
|
|
||||||
|
### CLI Commands
|
||||||
```bash
|
```bash
|
||||||
$ docker compose run leggen init
|
leggen status # Check connection status
|
||||||
|
leggen bank add # Connect to a new bank
|
||||||
|
leggen balances # View account balances
|
||||||
|
leggen transactions # List transactions
|
||||||
|
leggen sync # Trigger background sync
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you need to connect your bank accounts. Run the following command and follow the instructions:
|
For more options, run `leggen --help` or `leggen <command> --help`.
|
||||||
|
|
||||||
```bash
|
## ⚠️ Notes
|
||||||
$ docker compose run leggen bank add
|
- This project is in active development
|
||||||
```
|
|
||||||
|
|
||||||
To sync all transactions with the database, run the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ docker compose run leggen sync
|
|
||||||
```
|
|
||||||
|
|
||||||
## 👩🏫 Usage
|
|
||||||
|
|
||||||
```
|
|
||||||
$ leggen --help
|
|
||||||
Usage: leggen [OPTIONS] COMMAND [ARGS]...
|
|
||||||
|
|
||||||
Leggen: An Open Banking CLI
|
|
||||||
|
|
||||||
Options:
|
|
||||||
--version Show the version and exit.
|
|
||||||
-h, --help Show this message and exit.
|
|
||||||
|
|
||||||
Command Groups:
|
|
||||||
bank Manage banks connections
|
|
||||||
|
|
||||||
Commands:
|
|
||||||
balances List balances of all connected accounts
|
|
||||||
init Create configuration file
|
|
||||||
status List all connected banks and their status
|
|
||||||
sync Sync all transactions with database
|
|
||||||
transactions List transactions for an account
|
|
||||||
```
|
|
||||||
|
|
||||||
## ⚠️ Caveats
|
|
||||||
- This project is still in early development, breaking changes may occur.
|
|
||||||
|
|||||||
25
compose.dev.yml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
services:
|
||||||
|
# React frontend service
|
||||||
|
frontend:
|
||||||
|
build:
|
||||||
|
context: ./frontend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
restart: "unless-stopped"
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:3000:80"
|
||||||
|
environment:
|
||||||
|
- API_BACKEND_URL=${API_BACKEND_URL:-http://leggen-server:8000}
|
||||||
|
depends_on:
|
||||||
|
leggen-server:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
|
# FastAPI backend service
|
||||||
|
leggen-server:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
restart: "unless-stopped"
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8000:8000"
|
||||||
|
volumes:
|
||||||
|
- "./data:/root/.config/leggen"
|
||||||
19
compose.yml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
services:
|
||||||
|
# React frontend service
|
||||||
|
frontend:
|
||||||
|
image: ghcr.io/elisiariocouto/leggen:latest-frontend
|
||||||
|
restart: "unless-stopped"
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:3000:80"
|
||||||
|
depends_on:
|
||||||
|
leggen-server:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
|
# FastAPI backend service
|
||||||
|
leggen-server:
|
||||||
|
image: ghcr.io/elisiariocouto/leggen:latest
|
||||||
|
restart: "unless-stopped"
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8000:8000"
|
||||||
|
volumes:
|
||||||
|
- "./data:/root/.config/leggen" # Configuration and database directory
|
||||||
40
config.example.toml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[gocardless]
|
||||||
|
key = "your-api-key"
|
||||||
|
secret = "your-secret-key"
|
||||||
|
url = "https://bankaccountdata.gocardless.com/api/v2"
|
||||||
|
|
||||||
|
[database]
|
||||||
|
sqlite = true
|
||||||
|
|
||||||
|
# Optional: Background sync scheduling
|
||||||
|
[scheduler.sync]
|
||||||
|
enabled = true
|
||||||
|
hour = 3 # 3 AM
|
||||||
|
minute = 0
|
||||||
|
# cron = "0 3 * * *" # Alternative: use cron expression
|
||||||
|
|
||||||
|
# Optional: Discord notifications
|
||||||
|
[notifications.discord]
|
||||||
|
webhook = "https://discord.com/api/webhooks/..."
|
||||||
|
enabled = true
|
||||||
|
|
||||||
|
# Optional: Telegram notifications
|
||||||
|
[notifications.telegram]
|
||||||
|
token = "your-bot-token"
|
||||||
|
chat_id = 12345
|
||||||
|
enabled = true
|
||||||
|
|
||||||
|
# Optional: Transaction filters for notifications
|
||||||
|
[filters]
|
||||||
|
case_insensitive = ["salary", "utility"]
|
||||||
|
case_sensitive = ["SpecificStore"]
|
||||||
|
|
||||||
|
# Optional: S3 backup configuration
|
||||||
|
[backup.s3]
|
||||||
|
access_key_id = "your-s3-access-key"
|
||||||
|
secret_access_key = "your-s3-secret-key"
|
||||||
|
bucket_name = "your-bucket-name"
|
||||||
|
region = "us-east-1"
|
||||||
|
# endpoint_url = "https://custom-s3-endpoint.com" # Optional: for custom S3-compatible endpoints
|
||||||
|
path_style = false # Set to true for path-style addressing
|
||||||
|
enabled = true
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
version: '3.1'
|
|
||||||
|
|
||||||
services:
|
|
||||||
# Defaults to `sync` command.
|
|
||||||
leggen:
|
|
||||||
image: elisiariocouto/leggen:latest
|
|
||||||
command: sync
|
|
||||||
restart: "no"
|
|
||||||
environment:
|
|
||||||
LEGGEN_GC_API_KEY: "changeme"
|
|
||||||
LEGGEN_GC_API_SECRET: "changeme"
|
|
||||||
# Uncomment the following lines if you use MongoDB
|
|
||||||
# LEGGEN_MONGO_URI: "mongodb://leggen:changeme@mongo:27017/leggen"
|
|
||||||
volumes:
|
|
||||||
- "./leggen:/root"
|
|
||||||
depends_on:
|
|
||||||
- mongo
|
|
||||||
|
|
||||||
nocodb:
|
|
||||||
image: nocodb/nocodb:latest
|
|
||||||
restart: "unless-stopped"
|
|
||||||
volumes:
|
|
||||||
- "./nocodb:/usr/app/data/"
|
|
||||||
- "./leggen:/usr/leggen:ro"
|
|
||||||
ports:
|
|
||||||
- "127.0.0.1:8080:8080"
|
|
||||||
|
|
||||||
# Recommended: Run `leggen sync` every day.
|
|
||||||
ofelia:
|
|
||||||
image: mcuadros/ofelia:latest
|
|
||||||
restart: "unless-stopped"
|
|
||||||
depends_on:
|
|
||||||
- leggen
|
|
||||||
command: daemon --docker -f label=com.docker.compose.project=${COMPOSE_PROJECT_NAME}
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
|
||||||
labels:
|
|
||||||
ofelia.job-run.leggen-sync.schedule: "0 0 3 * * *"
|
|
||||||
ofelia.job-run.leggen-sync.container: ${COMPOSE_PROJECT_NAME}-leggen-1
|
|
||||||
|
|
||||||
# Optional: If you want to have a mongodb, uncomment the following lines
|
|
||||||
# mongo:
|
|
||||||
# image: mongo:7
|
|
||||||
# restart: "unless-stopped"
|
|
||||||
# # If you want to expose the mongodb port to the host, uncomment the following lines
|
|
||||||
# # ports:
|
|
||||||
# # - 127.0.0.1:27017:27017
|
|
||||||
# volumes:
|
|
||||||
# - "./data:/data/db"
|
|
||||||
# environment:
|
|
||||||
# MONGO_INITDB_ROOT_USERNAME: "leggen"
|
|
||||||
# MONGO_INITDB_ROOT_PASSWORD: "changeme"
|
|
||||||
|
|
||||||
# Optional: If you want to have an admin interface for your mongodb, uncomment the following lines
|
|
||||||
# mongo-express:
|
|
||||||
# image: mongo-express
|
|
||||||
# restart: "unless-stopped"
|
|
||||||
# # By default, we are exposing the mongo-express port to the host
|
|
||||||
# ports:
|
|
||||||
# - 127.0.0.1:8081:8081
|
|
||||||
# environment:
|
|
||||||
# ME_CONFIG_MONGODB_URL: "mongodb://leggen:changeme@mongo:27017/"
|
|
||||||
# ME_CONFIG_BASICAUTH_USERNAME: ""
|
|
||||||
# depends_on:
|
|
||||||
# - mongo
|
|
||||||
BIN
docs/leggen_demo.gif
Normal file
|
After Width: | Height: | Size: 548 KiB |
25
frontend/.gitignore
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
dev-dist
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
34
frontend/Dockerfile
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# Build stage
|
||||||
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package files
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN npm i
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the application
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
# Copy built application from builder stage
|
||||||
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
|
# Copy server configuration template
|
||||||
|
COPY default.conf.template /etc/nginx/templates/default.conf.template
|
||||||
|
|
||||||
|
# Set default API backend URL (can be overridden at runtime)
|
||||||
|
ENV API_BACKEND_URL=http://leggen-server:8000
|
||||||
|
|
||||||
|
# Expose port 80
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
# Start nginx
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
124
frontend/README.md
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
# Leggen Frontend
|
||||||
|
|
||||||
|
A modern React dashboard for the Leggen Open Banking CLI tool. This frontend provides a user-friendly interface to view bank accounts, transactions, and balances.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **Modern Dashboard**: Clean, responsive interface built with React and TypeScript
|
||||||
|
- **Bank Accounts Overview**: View all connected bank accounts with real-time balances
|
||||||
|
- **Transaction Management**: Browse, search, and filter transactions across all accounts
|
||||||
|
- **Responsive Design**: Works seamlessly on desktop, tablet, and mobile devices
|
||||||
|
- **Real-time Data**: Powered by React Query for efficient data fetching and caching
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- Node.js 18+ and npm
|
||||||
|
- Leggen API server running (configurable via environment variables)
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
1. **Install dependencies:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Start the development server:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Open your browser to:**
|
||||||
|
```
|
||||||
|
http://localhost:5173
|
||||||
|
```
|
||||||
|
|
||||||
|
## Available Scripts
|
||||||
|
|
||||||
|
- `npm run dev` - Start development server
|
||||||
|
- `npm run build` - Build for production
|
||||||
|
- `npm run preview` - Preview production build
|
||||||
|
- `npm run lint` - Run ESLint
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
### Key Technologies
|
||||||
|
|
||||||
|
- **React 18** - Modern React with hooks and concurrent features
|
||||||
|
- **TypeScript** - Type-safe JavaScript development
|
||||||
|
- **Vite** - Fast build tool and development server
|
||||||
|
- **Tailwind CSS** - Utility-first CSS framework
|
||||||
|
- **React Query** - Data fetching and caching
|
||||||
|
- **Axios** - HTTP client for API calls
|
||||||
|
- **Lucide React** - Modern icon library
|
||||||
|
|
||||||
|
### Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
src/
|
||||||
|
├── components/ # React components
|
||||||
|
│ ├── Dashboard.tsx # Main dashboard layout
|
||||||
|
│ ├── AccountsOverview.tsx
|
||||||
|
│ └── TransactionsList.tsx
|
||||||
|
├── lib/ # Utilities and API client
|
||||||
|
│ ├── api.ts # API client and endpoints
|
||||||
|
│ └── utils.ts # Helper functions
|
||||||
|
├── types/ # TypeScript type definitions
|
||||||
|
│ └── api.ts # API response types
|
||||||
|
└── App.tsx # Main application component
|
||||||
|
```
|
||||||
|
|
||||||
|
## API Integration
|
||||||
|
|
||||||
|
The frontend connects to the Leggen API server (configurable via environment variables). The API client handles:
|
||||||
|
|
||||||
|
- Account retrieval and management
|
||||||
|
- Transaction fetching with filtering
|
||||||
|
- Balance information
|
||||||
|
- Error handling and loading states
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
### API URL Configuration
|
||||||
|
|
||||||
|
The frontend supports configurable API URLs through environment variables:
|
||||||
|
|
||||||
|
**Development:**
|
||||||
|
|
||||||
|
- Set `VITE_API_URL` to call external APIs during development
|
||||||
|
- Example: `VITE_API_URL=https://staging-api.example.com npm run dev`
|
||||||
|
|
||||||
|
**Production:**
|
||||||
|
|
||||||
|
- Uses relative URLs (`/api/v1`) that nginx proxies to the backend
|
||||||
|
- Configure nginx proxy target via `API_BACKEND_URL` environment variable
|
||||||
|
- Default: `http://leggen-server:8000`
|
||||||
|
|
||||||
|
**Docker Compose:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Override API backend URL
|
||||||
|
API_BACKEND_URL=https://prod-api.example.com docker-compose up
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
The dashboard is designed to work with the Leggen CLI tool's API endpoints. Make sure your Leggen server is running before starting the frontend development server.
|
||||||
|
|
||||||
|
### Adding New Features
|
||||||
|
|
||||||
|
1. Define TypeScript types in `src/types/api.ts`
|
||||||
|
2. Add API methods to `src/lib/api.ts`
|
||||||
|
3. Create React components in `src/components/`
|
||||||
|
4. Use React Query for data fetching and state management
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
Build the application for production:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
The built files will be in the `dist/` directory, ready to be served by any static web server.
|
||||||
22
frontend/components.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://ui.shadcn.com/schema.json",
|
||||||
|
"style": "new-york",
|
||||||
|
"rsc": false,
|
||||||
|
"tsx": true,
|
||||||
|
"tailwind": {
|
||||||
|
"config": "tailwind.config.js",
|
||||||
|
"css": "src/index.css",
|
||||||
|
"baseColor": "slate",
|
||||||
|
"cssVariables": true,
|
||||||
|
"prefix": ""
|
||||||
|
},
|
||||||
|
"iconLibrary": "lucide",
|
||||||
|
"aliases": {
|
||||||
|
"components": "@/components",
|
||||||
|
"utils": "@/lib/utils",
|
||||||
|
"ui": "@/components/ui",
|
||||||
|
"lib": "@/lib",
|
||||||
|
"hooks": "@/hooks"
|
||||||
|
},
|
||||||
|
"registries": {}
|
||||||
|
}
|
||||||
102
frontend/default.conf.template
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
server {
|
||||||
|
|
||||||
|
# MIME types for PWA
|
||||||
|
include mime.types;
|
||||||
|
types {
|
||||||
|
application/manifest+json webmanifest;
|
||||||
|
}
|
||||||
|
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
# Trust proxy headers from Caddy/upstream proxy
|
||||||
|
set_real_ip_from 0.0.0.0/0;
|
||||||
|
real_ip_header X-Forwarded-For;
|
||||||
|
real_ip_recursive on;
|
||||||
|
|
||||||
|
# Security headers
|
||||||
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||||
|
add_header X-XSS-Protection "1; mode=block" always;
|
||||||
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||||
|
|
||||||
|
# Enable gzip compression
|
||||||
|
gzip on;
|
||||||
|
gzip_vary on;
|
||||||
|
gzip_min_length 1024;
|
||||||
|
gzip_proxied expired no-cache no-store private auth;
|
||||||
|
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json application/manifest+json image/svg+xml;
|
||||||
|
|
||||||
|
# Service worker - no cache, must revalidate
|
||||||
|
location ~ ^/(sw\.js|workbox-.*\.js)$ {
|
||||||
|
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
|
||||||
|
add_header Pragma "no-cache" always;
|
||||||
|
add_header Expires "0" always;
|
||||||
|
add_header Service-Worker-Allowed "/" always;
|
||||||
|
types {
|
||||||
|
application/javascript js;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# PWA manifest - short cache with revalidation
|
||||||
|
location ~ ^/manifest\.webmanifest$ {
|
||||||
|
add_header Cache-Control "public, max-age=3600, must-revalidate" always;
|
||||||
|
types {
|
||||||
|
application/manifest+json webmanifest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Handle client-side routing (SPA)
|
||||||
|
location / {
|
||||||
|
autoindex off;
|
||||||
|
expires off;
|
||||||
|
add_header Cache-Control "public, max-age=0, s-maxage=0, must-revalidate" always;
|
||||||
|
try_files $uri $uri/ /index.html =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
# API proxy to backend (configurable via API_BACKEND_URL env var)
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass ${API_BACKEND_URL};
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
|
||||||
|
proxy_set_header X-Forwarded-Host $http_x_forwarded_host;
|
||||||
|
proxy_redirect off;
|
||||||
|
|
||||||
|
# Timeouts
|
||||||
|
proxy_connect_timeout 60s;
|
||||||
|
proxy_send_timeout 60s;
|
||||||
|
proxy_read_timeout 60s;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Cache static assets with immutable flag
|
||||||
|
location ~* \.(css|js)$ {
|
||||||
|
expires 1y;
|
||||||
|
add_header Cache-Control "public, immutable" always;
|
||||||
|
access_log off;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Cache images and icons
|
||||||
|
location ~* \.(png|jpg|jpeg|gif|ico|svg|webp)$ {
|
||||||
|
expires 1y;
|
||||||
|
add_header Cache-Control "public, immutable" always;
|
||||||
|
access_log off;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Cache fonts (if any are added later)
|
||||||
|
location ~* \.(woff|woff2|ttf|eot|otf)$ {
|
||||||
|
expires 1y;
|
||||||
|
add_header Cache-Control "public, immutable" always;
|
||||||
|
add_header Access-Control-Allow-Origin "*" always;
|
||||||
|
access_log off;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Other static files
|
||||||
|
location ~* \.(xml|txt)$ {
|
||||||
|
expires 1d;
|
||||||
|
add_header Cache-Control "public, must-revalidate" always;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
frontend/eslint.config.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import js from "@eslint/js";
|
||||||
|
import globals from "globals";
|
||||||
|
import reactHooks from "eslint-plugin-react-hooks";
|
||||||
|
import reactRefresh from "eslint-plugin-react-refresh";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
import { globalIgnores } from "eslint/config";
|
||||||
|
|
||||||
|
export default tseslint.config([
|
||||||
|
globalIgnores(["dist", "dev-dist"]),
|
||||||
|
{
|
||||||
|
files: ["**/*.{ts,tsx}"],
|
||||||
|
extends: [
|
||||||
|
js.configs.recommended,
|
||||||
|
tseslint.configs.recommended,
|
||||||
|
reactHooks.configs["recommended-latest"],
|
||||||
|
reactRefresh.configs.vite,
|
||||||
|
],
|
||||||
|
languageOptions: {
|
||||||
|
ecmaVersion: 2020,
|
||||||
|
globals: globals.browser,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
"react-refresh/only-export-components": [
|
||||||
|
"warn",
|
||||||
|
{ allowConstantExport: true },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ["src/components/**/*.{ts,tsx}", "src/contexts/**/*.{ts,tsx}"],
|
||||||
|
rules: {
|
||||||
|
"react-refresh/only-export-components": "off",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
53
frontend/index.html
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" href="/favicon.ico" sizes="48x48" />
|
||||||
|
<link rel="icon" href="/favicon.svg" sizes="any" type="image/svg+xml" />
|
||||||
|
<meta
|
||||||
|
name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1.0, viewport-fit=cover"
|
||||||
|
/>
|
||||||
|
<title>Leggen</title>
|
||||||
|
|
||||||
|
<!-- PWA Meta Tags -->
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
content="Personal finance management application"
|
||||||
|
/>
|
||||||
|
<meta name="application-name" content="Leggen" />
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||||
|
<meta name="apple-mobile-web-app-title" content="Leggen" />
|
||||||
|
<meta name="format-detection" content="telephone=no" />
|
||||||
|
<meta name="mobile-web-app-capable" content="yes" />
|
||||||
|
<meta name="msapplication-config" content="/browserconfig.xml" />
|
||||||
|
<meta name="msapplication-TileColor" content="#0b74de" />
|
||||||
|
<meta name="msapplication-tap-highlight" content="no" />
|
||||||
|
|
||||||
|
<!-- Dynamic theme-color - will be updated by JavaScript -->
|
||||||
|
<meta name="theme-color" content="#0b74de" id="theme-color-meta" />
|
||||||
|
<meta
|
||||||
|
name="msapplication-navbutton-color"
|
||||||
|
content="#0b74de"
|
||||||
|
id="ms-theme-color-meta"
|
||||||
|
/>
|
||||||
|
<meta
|
||||||
|
name="apple-mobile-web-app-status-bar-style"
|
||||||
|
content="default"
|
||||||
|
id="apple-status-bar-meta"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Icons -->
|
||||||
|
<link rel="apple-touch-icon" href="/apple-touch-icon-180x180.png" />
|
||||||
|
<link rel="mask-icon" href="/favicon.svg" color="#0b74de" />
|
||||||
|
<link rel="shortcut icon" href="/favicon.ico" />
|
||||||
|
|
||||||
|
<!-- Manifest -->
|
||||||
|
<link rel="manifest" href="/manifest.webmanifest" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
14637
frontend/package-lock.json
generated
Normal file
76
frontend/package.json
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "VITE_API_URL=http://localhost:8000/api/v1 vite",
|
||||||
|
"build": "tsc -b && vite build",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@dnd-kit/core": "^6.3.1",
|
||||||
|
"@dnd-kit/modifiers": "^9.0.0",
|
||||||
|
"@dnd-kit/sortable": "^10.0.0",
|
||||||
|
"@dnd-kit/utilities": "^3.2.2",
|
||||||
|
"@radix-ui/react-avatar": "^1.1.10",
|
||||||
|
"@radix-ui/react-checkbox": "^1.3.3",
|
||||||
|
"@radix-ui/react-dialog": "^1.1.15",
|
||||||
|
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
||||||
|
"@radix-ui/react-label": "^2.1.7",
|
||||||
|
"@radix-ui/react-popover": "^1.1.15",
|
||||||
|
"@radix-ui/react-progress": "^1.1.7",
|
||||||
|
"@radix-ui/react-select": "^2.2.6",
|
||||||
|
"@radix-ui/react-separator": "^1.1.7",
|
||||||
|
"@radix-ui/react-slot": "^1.2.3",
|
||||||
|
"@radix-ui/react-switch": "^1.2.6",
|
||||||
|
"@radix-ui/react-tabs": "^1.1.13",
|
||||||
|
"@radix-ui/react-toggle": "^1.1.10",
|
||||||
|
"@radix-ui/react-toggle-group": "^1.1.11",
|
||||||
|
"@radix-ui/react-tooltip": "^1.2.8",
|
||||||
|
"@tabler/icons-react": "^3.35.0",
|
||||||
|
"@tailwindcss/forms": "^0.5.10",
|
||||||
|
"@tanstack/react-query": "^5.87.1",
|
||||||
|
"@tanstack/react-router": "^1.131.36",
|
||||||
|
"@tanstack/react-table": "^8.21.3",
|
||||||
|
"@tanstack/router-cli": "^1.131.36",
|
||||||
|
"autoprefixer": "^10.4.21",
|
||||||
|
"axios": "^1.11.0",
|
||||||
|
"class-variance-authority": "^0.7.1",
|
||||||
|
"clsx": "^2.1.1",
|
||||||
|
"cmdk": "^1.1.1",
|
||||||
|
"date-fns": "^4.1.0",
|
||||||
|
"lucide-react": "^0.542.0",
|
||||||
|
"next-themes": "^0.4.6",
|
||||||
|
"postcss": "^8.5.6",
|
||||||
|
"react": "^19.1.1",
|
||||||
|
"react-day-picker": "^9.10.0",
|
||||||
|
"react-dom": "^19.1.1",
|
||||||
|
"recharts": "^2.15.4",
|
||||||
|
"sonner": "^2.0.7",
|
||||||
|
"tailwind-merge": "^3.3.1",
|
||||||
|
"tailwindcss": "^3.4.17",
|
||||||
|
"tailwindcss-animate": "^1.0.7",
|
||||||
|
"vaul": "^1.1.2",
|
||||||
|
"zod": "^3.25.76"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^9.33.0",
|
||||||
|
"@tanstack/router-vite-plugin": "^1.131.36",
|
||||||
|
"@types/react": "^19.1.10",
|
||||||
|
"@types/react-dom": "^19.1.7",
|
||||||
|
"@vite-pwa/assets-generator": "^1.0.1",
|
||||||
|
"@vitejs/plugin-react": "^5.0.0",
|
||||||
|
"eslint": "^9.33.0",
|
||||||
|
"eslint-plugin-react-hooks": "^5.2.0",
|
||||||
|
"eslint-plugin-react-refresh": "^0.4.20",
|
||||||
|
"globals": "^16.3.0",
|
||||||
|
"shadcn": "^3.3.1",
|
||||||
|
"sharp": "^0.34.3",
|
||||||
|
"typescript": "~5.8.3",
|
||||||
|
"typescript-eslint": "^8.39.1",
|
||||||
|
"vite": "^7.1.2",
|
||||||
|
"vite-plugin-pwa": "^1.0.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
6
frontend/postcss.config.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export default {
|
||||||
|
plugins: {
|
||||||
|
tailwindcss: {},
|
||||||
|
autoprefixer: {},
|
||||||
|
},
|
||||||
|
};
|
||||||
BIN
frontend/public/apple-touch-icon-180x180.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
9
frontend/public/browserconfig.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<browserconfig>
|
||||||
|
<msapplication>
|
||||||
|
<tile>
|
||||||
|
<square150x150logo src="/pwa-192x192.png"/>
|
||||||
|
<TileColor>#3B82F6</TileColor>
|
||||||
|
</tile>
|
||||||
|
</msapplication>
|
||||||
|
</browserconfig>
|
||||||
BIN
frontend/public/favicon.ico
Normal file
|
After Width: | Height: | Size: 813 B |
27
frontend/public/favicon.svg
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="32" height="32"
|
||||||
|
viewBox="0 0 32 32"
|
||||||
|
role="img" aria-labelledby="title desc">
|
||||||
|
<title id="title">leggen — stylized italic L</title>
|
||||||
|
<desc id="desc">Square gradient background with italic white L.</desc>
|
||||||
|
|
||||||
|
<defs>
|
||||||
|
<linearGradient id="bg" x1="0" y1="0" x2="1" y2="1">
|
||||||
|
<stop offset="0%" stop-color="#0b74de"/>
|
||||||
|
<stop offset="100%" stop-color="#06b6d4"/>
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
|
||||||
|
<!-- Square background -->
|
||||||
|
<rect width="32" height="32" fill="url(#bg)" rx="4"/>
|
||||||
|
|
||||||
|
<!-- Italic L -->
|
||||||
|
<text x="11" y="22"
|
||||||
|
font-family="Inter, Roboto, Arial, sans-serif"
|
||||||
|
font-weight="700"
|
||||||
|
font-size="20"
|
||||||
|
font-style="italic"
|
||||||
|
fill="#fff">
|
||||||
|
L
|
||||||
|
</text>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 769 B |
BIN
frontend/public/maskable-icon-512x512.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
frontend/public/pwa-192x192.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
frontend/public/pwa-512x512.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
frontend/public/pwa-64x64.png
Normal file
|
After Width: | Height: | Size: 701 B |
4
frontend/public/robots.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
User-agent: *
|
||||||
|
Allow: /
|
||||||
|
|
||||||
|
Sitemap: /sitemap.xml
|
||||||
1
frontend/public/vite.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||||
|
After Width: | Height: | Size: 1.5 KiB |
4
frontend/pwa-assets.config.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"preset": "minimal-2023",
|
||||||
|
"images": ["public/favicon.svg"]
|
||||||
|
}
|
||||||
1
frontend/src/App.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/* Additional styles if needed */
|
||||||
1
frontend/src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||||
|
After Width: | Height: | Size: 4.0 KiB |
373
frontend/src/components/AccountSettings.tsx
Normal file
@@ -0,0 +1,373 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
CreditCard,
|
||||||
|
TrendingUp,
|
||||||
|
TrendingDown,
|
||||||
|
Building2,
|
||||||
|
RefreshCw,
|
||||||
|
AlertCircle,
|
||||||
|
Edit2,
|
||||||
|
Check,
|
||||||
|
X,
|
||||||
|
Plus,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import { formatCurrency, formatDate } from "../lib/utils";
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from "./ui/card";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "./ui/alert";
|
||||||
|
import AccountsSkeleton from "./AccountsSkeleton";
|
||||||
|
import type { Account, Balance } from "../types/api";
|
||||||
|
|
||||||
|
// Helper function to get status indicator color and styles
|
||||||
|
const getStatusIndicator = (status: string) => {
|
||||||
|
const statusLower = status.toLowerCase();
|
||||||
|
|
||||||
|
switch (statusLower) {
|
||||||
|
case "ready":
|
||||||
|
return {
|
||||||
|
color: "bg-green-500",
|
||||||
|
tooltip: "Ready",
|
||||||
|
};
|
||||||
|
case "pending":
|
||||||
|
return {
|
||||||
|
color: "bg-amber-500",
|
||||||
|
tooltip: "Pending",
|
||||||
|
};
|
||||||
|
case "error":
|
||||||
|
case "failed":
|
||||||
|
return {
|
||||||
|
color: "bg-destructive",
|
||||||
|
tooltip: "Error",
|
||||||
|
};
|
||||||
|
case "inactive":
|
||||||
|
return {
|
||||||
|
color: "bg-muted-foreground",
|
||||||
|
tooltip: "Inactive",
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
color: "bg-primary",
|
||||||
|
tooltip: status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function AccountSettings() {
|
||||||
|
const {
|
||||||
|
data: accounts,
|
||||||
|
isLoading: accountsLoading,
|
||||||
|
error: accountsError,
|
||||||
|
refetch: refetchAccounts,
|
||||||
|
} = useQuery<Account[]>({
|
||||||
|
queryKey: ["accounts"],
|
||||||
|
queryFn: apiClient.getAccounts,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: balances } = useQuery<Balance[]>({
|
||||||
|
queryKey: ["balances"],
|
||||||
|
queryFn: () => apiClient.getBalances(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const [editingAccountId, setEditingAccountId] = useState<string | null>(null);
|
||||||
|
const [editingName, setEditingName] = useState("");
|
||||||
|
const [failedImages, setFailedImages] = useState<Set<string>>(new Set());
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const updateAccountMutation = useMutation({
|
||||||
|
mutationFn: ({ id, display_name }: { id: string; display_name: string }) =>
|
||||||
|
apiClient.updateAccount(id, { display_name }),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||||
|
setEditingAccountId(null);
|
||||||
|
setEditingName("");
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error("Failed to update account:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleEditStart = (account: Account) => {
|
||||||
|
setEditingAccountId(account.id);
|
||||||
|
// Use display_name if available, otherwise fall back to name
|
||||||
|
setEditingName(account.display_name || account.name || "");
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditSave = () => {
|
||||||
|
if (editingAccountId && editingName.trim()) {
|
||||||
|
updateAccountMutation.mutate({
|
||||||
|
id: editingAccountId,
|
||||||
|
display_name: editingName.trim(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditCancel = () => {
|
||||||
|
setEditingAccountId(null);
|
||||||
|
setEditingName("");
|
||||||
|
};
|
||||||
|
|
||||||
|
if (accountsLoading) {
|
||||||
|
return <AccountsSkeleton />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accountsError) {
|
||||||
|
return (
|
||||||
|
<Alert variant="destructive">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<AlertTitle>Failed to load accounts</AlertTitle>
|
||||||
|
<AlertDescription className="space-y-3">
|
||||||
|
<p>
|
||||||
|
Unable to connect to the Leggen API. Please check your configuration
|
||||||
|
and ensure the API server is running.
|
||||||
|
</p>
|
||||||
|
<Button onClick={() => refetchAccounts()} variant="outline" size="sm">
|
||||||
|
<RefreshCw className="h-4 w-4 mr-2" />
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
{/* Account Management Section */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Account Management</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Manage your connected bank accounts and customize their display
|
||||||
|
names
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
{!accounts || accounts.length === 0 ? (
|
||||||
|
<CardContent className="p-6 text-center">
|
||||||
|
<CreditCard className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
No accounts found
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground mb-4">
|
||||||
|
Connect your first bank account to get started with Leggen.
|
||||||
|
</p>
|
||||||
|
<Button disabled className="flex items-center space-x-2">
|
||||||
|
<Plus className="h-4 w-4" />
|
||||||
|
<span>Add Bank Account</span>
|
||||||
|
</Button>
|
||||||
|
<p className="text-xs text-muted-foreground mt-2">
|
||||||
|
Coming soon: Add new bank connections
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
) : (
|
||||||
|
<CardContent className="p-0">
|
||||||
|
<div className="divide-y divide-border">
|
||||||
|
{accounts.map((account) => {
|
||||||
|
// Get balance from account's balances array or fallback to balances query
|
||||||
|
const accountBalance = account.balances?.[0];
|
||||||
|
const fallbackBalance = balances?.find(
|
||||||
|
(b) => b.account_id === account.id,
|
||||||
|
);
|
||||||
|
const balance =
|
||||||
|
accountBalance?.amount ||
|
||||||
|
fallbackBalance?.balance_amount ||
|
||||||
|
0;
|
||||||
|
const currency =
|
||||||
|
accountBalance?.currency ||
|
||||||
|
fallbackBalance?.currency ||
|
||||||
|
account.currency ||
|
||||||
|
"EUR";
|
||||||
|
const isPositive = balance >= 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={account.id}
|
||||||
|
className="p-4 sm:p-6 hover:bg-accent transition-colors"
|
||||||
|
>
|
||||||
|
{/* Mobile layout - stack vertically */}
|
||||||
|
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 sm:gap-4">
|
||||||
|
<div className="flex items-start sm:items-center space-x-3 sm:space-x-4 min-w-0 flex-1">
|
||||||
|
<div className="flex-shrink-0 w-10 h-10 sm:w-12 sm:h-12 rounded-full overflow-hidden bg-muted flex items-center justify-center">
|
||||||
|
{account.logo && !failedImages.has(account.id) ? (
|
||||||
|
<img
|
||||||
|
src={account.logo}
|
||||||
|
alt={`${account.institution_id} logo`}
|
||||||
|
className="w-full h-full object-contain"
|
||||||
|
onError={() => {
|
||||||
|
console.warn(
|
||||||
|
`Failed to load bank logo for ${account.institution_id}: ${account.logo}`,
|
||||||
|
);
|
||||||
|
setFailedImages(
|
||||||
|
(prev) => new Set([...prev, account.id]),
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Building2 className="h-5 w-5 sm:h-6 sm:w-6 text-muted-foreground" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
{editingAccountId === account.id ? (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={editingName}
|
||||||
|
onChange={(e) =>
|
||||||
|
setEditingName(e.target.value)
|
||||||
|
}
|
||||||
|
className="flex-1 px-3 py-1 text-base sm:text-lg font-medium border border-input rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-ring focus:border-ring"
|
||||||
|
placeholder="Custom account name"
|
||||||
|
name="search"
|
||||||
|
autoComplete="off"
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") handleEditSave();
|
||||||
|
if (e.key === "Escape") handleEditCancel();
|
||||||
|
}}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
onClick={handleEditSave}
|
||||||
|
disabled={
|
||||||
|
!editingName.trim() ||
|
||||||
|
updateAccountMutation.isPending
|
||||||
|
}
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-8 w-8 text-green-600 hover:text-green-700 hover:bg-green-100"
|
||||||
|
title="Save changes"
|
||||||
|
>
|
||||||
|
<Check className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={handleEditCancel}
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-8 w-8"
|
||||||
|
title="Cancel editing"
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-muted-foreground truncate">
|
||||||
|
{account.institution_id}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center space-x-2 min-w-0">
|
||||||
|
<h4 className="text-base sm:text-lg font-medium text-foreground truncate">
|
||||||
|
{account.display_name ||
|
||||||
|
account.name ||
|
||||||
|
"Unnamed Account"}
|
||||||
|
</h4>
|
||||||
|
<Button
|
||||||
|
onClick={() => handleEditStart(account)}
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-7 w-7 flex-shrink-0"
|
||||||
|
title="Edit account name"
|
||||||
|
>
|
||||||
|
<Edit2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-muted-foreground truncate">
|
||||||
|
{account.institution_id}
|
||||||
|
</p>
|
||||||
|
{account.iban && (
|
||||||
|
<p className="text-xs text-muted-foreground mt-1 font-mono break-all sm:break-normal">
|
||||||
|
IBAN: {account.iban}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Balance and date section */}
|
||||||
|
<div className="flex items-center justify-between sm:flex-col sm:items-end sm:text-right flex-shrink-0">
|
||||||
|
{/* Mobile: date/status on left, balance on right */}
|
||||||
|
{/* Desktop: balance on top, date/status on bottom */}
|
||||||
|
|
||||||
|
{/* Date and status indicator - left on mobile, bottom on desktop */}
|
||||||
|
<div className="flex items-center space-x-2 order-1 sm:order-2">
|
||||||
|
<div
|
||||||
|
className={`w-3 h-3 rounded-full ${getStatusIndicator(account.status).color} relative group cursor-help`}
|
||||||
|
role="img"
|
||||||
|
aria-label={`Account status: ${getStatusIndicator(account.status).tooltip}`}
|
||||||
|
>
|
||||||
|
{/* Tooltip */}
|
||||||
|
<div className="absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 hidden group-hover:block bg-gray-900 text-white text-xs rounded py-1 px-2 whitespace-nowrap z-10">
|
||||||
|
{getStatusIndicator(account.status).tooltip}
|
||||||
|
<div className="absolute top-full left-1/2 transform -translate-x-1/2 border-2 border-transparent border-t-gray-900"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs sm:text-sm text-muted-foreground whitespace-nowrap">
|
||||||
|
Updated{" "}
|
||||||
|
{formatDate(
|
||||||
|
account.last_accessed || account.created,
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Balance - right on mobile, top on desktop */}
|
||||||
|
<div className="flex items-center space-x-2 order-2 sm:order-1">
|
||||||
|
{isPositive ? (
|
||||||
|
<TrendingUp className="h-4 w-4 text-green-500" />
|
||||||
|
) : (
|
||||||
|
<TrendingDown className="h-4 w-4 text-red-500" />
|
||||||
|
)}
|
||||||
|
<p
|
||||||
|
className={`text-base sm:text-lg font-semibold ${
|
||||||
|
isPositive ? "text-green-600" : "text-red-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{formatCurrency(balance, currency)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Add Bank Section (Future Feature) */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Add New Bank Account</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Connect additional bank accounts to track all your finances in one
|
||||||
|
place
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="p-6">
|
||||||
|
<div className="text-center space-y-4">
|
||||||
|
<div className="p-4 bg-muted rounded-lg">
|
||||||
|
<Plus className="h-8 w-8 text-muted-foreground mx-auto mb-2" />
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Bank connection functionality is coming soon. Stay tuned for
|
||||||
|
updates!
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button disabled variant="outline">
|
||||||
|
<Plus className="h-4 w-4 mr-2" />
|
||||||
|
Connect Bank Account
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
386
frontend/src/components/AccountsOverview.tsx
Normal file
@@ -0,0 +1,386 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
CreditCard,
|
||||||
|
TrendingUp,
|
||||||
|
TrendingDown,
|
||||||
|
Building2,
|
||||||
|
RefreshCw,
|
||||||
|
AlertCircle,
|
||||||
|
Edit2,
|
||||||
|
Check,
|
||||||
|
X,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import { formatCurrency, formatDate } from "../lib/utils";
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from "./ui/card";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "./ui/alert";
|
||||||
|
import AccountsSkeleton from "./AccountsSkeleton";
|
||||||
|
import type { Account, Balance } from "../types/api";
|
||||||
|
|
||||||
|
// Helper function to get status indicator color and styles
|
||||||
|
const getStatusIndicator = (status: string) => {
|
||||||
|
const statusLower = status.toLowerCase();
|
||||||
|
|
||||||
|
switch (statusLower) {
|
||||||
|
case "ready":
|
||||||
|
return {
|
||||||
|
color: "bg-green-500",
|
||||||
|
tooltip: "Ready",
|
||||||
|
};
|
||||||
|
case "pending":
|
||||||
|
return {
|
||||||
|
color: "bg-amber-500",
|
||||||
|
tooltip: "Pending",
|
||||||
|
};
|
||||||
|
case "error":
|
||||||
|
case "failed":
|
||||||
|
return {
|
||||||
|
color: "bg-destructive",
|
||||||
|
tooltip: "Error",
|
||||||
|
};
|
||||||
|
case "inactive":
|
||||||
|
return {
|
||||||
|
color: "bg-muted-foreground",
|
||||||
|
tooltip: "Inactive",
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
color: "bg-primary",
|
||||||
|
tooltip: status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function AccountsOverview() {
|
||||||
|
const {
|
||||||
|
data: accounts,
|
||||||
|
isLoading: accountsLoading,
|
||||||
|
error: accountsError,
|
||||||
|
refetch: refetchAccounts,
|
||||||
|
} = useQuery<Account[]>({
|
||||||
|
queryKey: ["accounts"],
|
||||||
|
queryFn: apiClient.getAccounts,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: balances } = useQuery<Balance[]>({
|
||||||
|
queryKey: ["balances"],
|
||||||
|
queryFn: () => apiClient.getBalances(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const [editingAccountId, setEditingAccountId] = useState<string | null>(null);
|
||||||
|
const [editingName, setEditingName] = useState("");
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const updateAccountMutation = useMutation({
|
||||||
|
mutationFn: ({ id, display_name }: { id: string; display_name: string }) =>
|
||||||
|
apiClient.updateAccount(id, { display_name }),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||||
|
setEditingAccountId(null);
|
||||||
|
setEditingName("");
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error("Failed to update account:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleEditStart = (account: Account) => {
|
||||||
|
setEditingAccountId(account.id);
|
||||||
|
// Use display_name if available, otherwise fall back to name
|
||||||
|
setEditingName(account.display_name || account.name || "");
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditSave = () => {
|
||||||
|
if (editingAccountId && editingName.trim()) {
|
||||||
|
updateAccountMutation.mutate({
|
||||||
|
id: editingAccountId,
|
||||||
|
display_name: editingName.trim(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditCancel = () => {
|
||||||
|
setEditingAccountId(null);
|
||||||
|
setEditingName("");
|
||||||
|
};
|
||||||
|
|
||||||
|
if (accountsLoading) {
|
||||||
|
return <AccountsSkeleton />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accountsError) {
|
||||||
|
return (
|
||||||
|
<Alert variant="destructive">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<AlertTitle>Failed to load accounts</AlertTitle>
|
||||||
|
<AlertDescription className="space-y-3">
|
||||||
|
<p>
|
||||||
|
Unable to connect to the Leggen API. Please check your configuration
|
||||||
|
and ensure the API server is running.
|
||||||
|
</p>
|
||||||
|
<Button onClick={() => refetchAccounts()} variant="outline" size="sm">
|
||||||
|
<RefreshCw className="h-4 w-4 mr-2" />
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalBalance =
|
||||||
|
accounts?.reduce((sum, account) => {
|
||||||
|
// Get the first available balance from the balances array
|
||||||
|
const primaryBalance = account.balances?.[0]?.amount || 0;
|
||||||
|
return sum + primaryBalance;
|
||||||
|
}, 0) || 0;
|
||||||
|
const totalAccounts = accounts?.length || 0;
|
||||||
|
const uniqueBanks = new Set(accounts?.map((acc) => acc.institution_id) || [])
|
||||||
|
.size;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
{/* Summary Cards */}
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||||
|
<Card>
|
||||||
|
<CardContent className="p-6">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium text-muted-foreground">
|
||||||
|
Total Balance
|
||||||
|
</p>
|
||||||
|
<p className="text-2xl font-bold text-foreground">
|
||||||
|
{formatCurrency(totalBalance)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="p-3 bg-green-100 dark:bg-green-900/20 rounded-full">
|
||||||
|
<TrendingUp className="h-6 w-6 text-green-600" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardContent className="p-6">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium text-muted-foreground">
|
||||||
|
Total Accounts
|
||||||
|
</p>
|
||||||
|
<p className="text-2xl font-bold text-foreground">
|
||||||
|
{totalAccounts}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="p-3 bg-blue-100 dark:bg-blue-900/20 rounded-full">
|
||||||
|
<CreditCard className="h-6 w-6 text-blue-600" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardContent className="p-6">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium text-muted-foreground">
|
||||||
|
Connected Banks
|
||||||
|
</p>
|
||||||
|
<p className="text-2xl font-bold text-foreground">
|
||||||
|
{uniqueBanks}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="p-3 bg-muted rounded-full">
|
||||||
|
<Building2 className="h-6 w-6 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Accounts List */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Bank Accounts</CardTitle>
|
||||||
|
<CardDescription>Manage your connected bank accounts</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
{!accounts || accounts.length === 0 ? (
|
||||||
|
<CardContent className="p-6 text-center">
|
||||||
|
<CreditCard className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
No accounts found
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Connect your first bank account to get started with Leggen.
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
) : (
|
||||||
|
<CardContent className="p-0">
|
||||||
|
<div className="divide-y divide-border">
|
||||||
|
{accounts.map((account) => {
|
||||||
|
// Get balance from account's balances array or fallback to balances query
|
||||||
|
const accountBalance = account.balances?.[0];
|
||||||
|
const fallbackBalance = balances?.find(
|
||||||
|
(b) => b.account_id === account.id,
|
||||||
|
);
|
||||||
|
const balance =
|
||||||
|
accountBalance?.amount ||
|
||||||
|
fallbackBalance?.balance_amount ||
|
||||||
|
0;
|
||||||
|
const currency =
|
||||||
|
accountBalance?.currency ||
|
||||||
|
fallbackBalance?.currency ||
|
||||||
|
account.currency ||
|
||||||
|
"EUR";
|
||||||
|
const isPositive = balance >= 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={account.id}
|
||||||
|
className="p-4 sm:p-6 hover:bg-accent transition-colors"
|
||||||
|
>
|
||||||
|
{/* Mobile layout - stack vertically */}
|
||||||
|
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 sm:gap-4">
|
||||||
|
<div className="flex items-start sm:items-center space-x-3 sm:space-x-4 min-w-0 flex-1">
|
||||||
|
<div className="flex-shrink-0 p-2 sm:p-3 bg-muted rounded-full">
|
||||||
|
<Building2 className="h-5 w-5 sm:h-6 sm:w-6 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
{editingAccountId === account.id ? (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={editingName}
|
||||||
|
onChange={(e) =>
|
||||||
|
setEditingName(e.target.value)
|
||||||
|
}
|
||||||
|
className="flex-1 px-3 py-1 text-base sm:text-lg font-medium border border-input rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-ring focus:border-ring"
|
||||||
|
placeholder="Custom account name"
|
||||||
|
name="search"
|
||||||
|
autoComplete="off"
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") handleEditSave();
|
||||||
|
if (e.key === "Escape") handleEditCancel();
|
||||||
|
}}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
onClick={handleEditSave}
|
||||||
|
disabled={
|
||||||
|
!editingName.trim() ||
|
||||||
|
updateAccountMutation.isPending
|
||||||
|
}
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-8 w-8 text-green-600 hover:text-green-700 hover:bg-green-100"
|
||||||
|
title="Save changes"
|
||||||
|
>
|
||||||
|
<Check className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={handleEditCancel}
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-8 w-8"
|
||||||
|
title="Cancel editing"
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-muted-foreground truncate">
|
||||||
|
{account.institution_id}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center space-x-2 min-w-0">
|
||||||
|
<h4 className="text-base sm:text-lg font-medium text-foreground truncate">
|
||||||
|
{account.display_name ||
|
||||||
|
account.name ||
|
||||||
|
"Unnamed Account"}
|
||||||
|
</h4>
|
||||||
|
<Button
|
||||||
|
onClick={() => handleEditStart(account)}
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-7 w-7 flex-shrink-0"
|
||||||
|
title="Edit account name"
|
||||||
|
>
|
||||||
|
<Edit2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-muted-foreground truncate">
|
||||||
|
{account.institution_id}
|
||||||
|
</p>
|
||||||
|
{account.iban && (
|
||||||
|
<p className="text-xs text-muted-foreground mt-1 font-mono break-all sm:break-normal">
|
||||||
|
IBAN: {account.iban}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Balance and date section */}
|
||||||
|
<div className="flex items-center justify-between sm:flex-col sm:items-end sm:text-right flex-shrink-0">
|
||||||
|
{/* Mobile: date/status on left, balance on right */}
|
||||||
|
{/* Desktop: balance on top, date/status on bottom */}
|
||||||
|
|
||||||
|
{/* Date and status indicator - left on mobile, bottom on desktop */}
|
||||||
|
<div className="flex items-center space-x-2 order-1 sm:order-2">
|
||||||
|
<div
|
||||||
|
className={`w-3 h-3 rounded-full ${getStatusIndicator(account.status).color} relative group cursor-help`}
|
||||||
|
role="img"
|
||||||
|
aria-label={`Account status: ${getStatusIndicator(account.status).tooltip}`}
|
||||||
|
>
|
||||||
|
{/* Tooltip */}
|
||||||
|
<div className="absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 hidden group-hover:block bg-gray-900 text-white text-xs rounded py-1 px-2 whitespace-nowrap z-10">
|
||||||
|
{getStatusIndicator(account.status).tooltip}
|
||||||
|
<div className="absolute top-full left-1/2 transform -translate-x-1/2 border-2 border-transparent border-t-gray-900"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs sm:text-sm text-muted-foreground whitespace-nowrap">
|
||||||
|
Updated{" "}
|
||||||
|
{formatDate(
|
||||||
|
account.last_accessed || account.created,
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Balance - right on mobile, top on desktop */}
|
||||||
|
<div className="flex items-center space-x-2 order-2 sm:order-1">
|
||||||
|
{isPositive ? (
|
||||||
|
<TrendingUp className="h-4 w-4 text-green-500" />
|
||||||
|
) : (
|
||||||
|
<TrendingDown className="h-4 w-4 text-red-500" />
|
||||||
|
)}
|
||||||
|
<p
|
||||||
|
className={`text-base sm:text-lg font-semibold ${
|
||||||
|
isPositive ? "text-green-600" : "text-red-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{formatCurrency(balance, currency)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
61
frontend/src/components/AccountsSkeleton.tsx
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import { Skeleton } from "./ui/skeleton";
|
||||||
|
import { Card, CardContent, CardHeader } from "./ui/card";
|
||||||
|
|
||||||
|
export default function AccountsSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
{/* Summary Cards Skeleton */}
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||||
|
{Array.from({ length: 3 }).map((_, i) => (
|
||||||
|
<Card key={i}>
|
||||||
|
<CardContent className="p-6">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-4 w-20" />
|
||||||
|
<Skeleton className="h-8 w-24" />
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-12 w-12 rounded-full" />
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Accounts List Skeleton */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<Skeleton className="h-6 w-32" />
|
||||||
|
<Skeleton className="h-4 w-48" />
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="p-0">
|
||||||
|
<div className="divide-y divide-border">
|
||||||
|
{Array.from({ length: 4 }).map((_, i) => (
|
||||||
|
<div key={i} className="p-4 sm:p-6">
|
||||||
|
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 sm:gap-4">
|
||||||
|
<div className="flex items-start sm:items-center space-x-3 sm:space-x-4 min-w-0 flex-1">
|
||||||
|
<Skeleton className="h-10 w-10 sm:h-12 sm:w-12 rounded-full flex-shrink-0" />
|
||||||
|
<div className="flex-1 space-y-2">
|
||||||
|
<Skeleton className="h-5 w-48" />
|
||||||
|
<Skeleton className="h-4 w-32" />
|
||||||
|
<Skeleton className="h-3 w-40" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between sm:flex-col sm:items-end sm:text-right flex-shrink-0">
|
||||||
|
<div className="flex items-center space-x-2 order-1 sm:order-2">
|
||||||
|
<Skeleton className="h-3 w-3 rounded-full" />
|
||||||
|
<Skeleton className="h-4 w-20" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2 order-2 sm:order-1">
|
||||||
|
<Skeleton className="h-4 w-4" />
|
||||||
|
<Skeleton className="h-5 w-24" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
203
frontend/src/components/AddBankAccountDrawer.tsx
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||||
|
import { Plus, Building2, ExternalLink } from "lucide-react";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { Label } from "./ui/label";
|
||||||
|
import {
|
||||||
|
Drawer,
|
||||||
|
DrawerClose,
|
||||||
|
DrawerContent,
|
||||||
|
DrawerDescription,
|
||||||
|
DrawerFooter,
|
||||||
|
DrawerHeader,
|
||||||
|
DrawerTitle,
|
||||||
|
DrawerTrigger,
|
||||||
|
} from "./ui/drawer";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "./ui/select";
|
||||||
|
import { Alert, AlertDescription } from "./ui/alert";
|
||||||
|
|
||||||
|
export default function AddBankAccountDrawer() {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const [selectedCountry, setSelectedCountry] = useState<string>("");
|
||||||
|
const [selectedBank, setSelectedBank] = useState<string>("");
|
||||||
|
|
||||||
|
const { data: countries } = useQuery({
|
||||||
|
queryKey: ["supportedCountries"],
|
||||||
|
queryFn: apiClient.getSupportedCountries,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: banks, isLoading: banksLoading } = useQuery({
|
||||||
|
queryKey: ["bankInstitutions", selectedCountry],
|
||||||
|
queryFn: () => apiClient.getBankInstitutions(selectedCountry),
|
||||||
|
enabled: !!selectedCountry,
|
||||||
|
});
|
||||||
|
|
||||||
|
const connectBankMutation = useMutation({
|
||||||
|
mutationFn: (institutionId: string) =>
|
||||||
|
apiClient.createBankConnection(institutionId),
|
||||||
|
onSuccess: (data) => {
|
||||||
|
// Redirect to the bank's authorization link
|
||||||
|
if (data.link) {
|
||||||
|
window.open(data.link, "_blank");
|
||||||
|
setOpen(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error("Failed to create bank connection:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleCountryChange = (country: string) => {
|
||||||
|
setSelectedCountry(country);
|
||||||
|
setSelectedBank("");
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleConnect = () => {
|
||||||
|
if (selectedBank) {
|
||||||
|
connectBankMutation.mutate(selectedBank);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetForm = () => {
|
||||||
|
setSelectedCountry("");
|
||||||
|
setSelectedBank("");
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Drawer
|
||||||
|
open={open}
|
||||||
|
onOpenChange={(isOpen) => {
|
||||||
|
setOpen(isOpen);
|
||||||
|
if (!isOpen) {
|
||||||
|
resetForm();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DrawerTrigger asChild>
|
||||||
|
<Button size="sm">
|
||||||
|
<Plus className="h-4 w-4 mr-2" />
|
||||||
|
Add New Account
|
||||||
|
</Button>
|
||||||
|
</DrawerTrigger>
|
||||||
|
<DrawerContent className="max-h-[80vh]">
|
||||||
|
<DrawerHeader>
|
||||||
|
<DrawerTitle>Connect Bank Account</DrawerTitle>
|
||||||
|
<DrawerDescription>
|
||||||
|
Select your country and bank to connect your account to Leggen
|
||||||
|
</DrawerDescription>
|
||||||
|
</DrawerHeader>
|
||||||
|
|
||||||
|
<div className="px-6 space-y-6 overflow-y-auto">
|
||||||
|
{/* Country Selection */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="country">Country</Label>
|
||||||
|
<Select value={selectedCountry} onValueChange={handleCountryChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Select your country" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{countries?.map((country) => (
|
||||||
|
<SelectItem key={country.code} value={country.code}>
|
||||||
|
{country.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Bank Selection */}
|
||||||
|
{selectedCountry && (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="bank">Bank</Label>
|
||||||
|
{banksLoading ? (
|
||||||
|
<div className="p-4 text-center text-muted-foreground">
|
||||||
|
Loading banks...
|
||||||
|
</div>
|
||||||
|
) : banks && banks.length > 0 ? (
|
||||||
|
<Select value={selectedBank} onValueChange={setSelectedBank}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Select your bank" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{banks.map((bank) => (
|
||||||
|
<SelectItem key={bank.id} value={bank.id}>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
{bank.logo ? (
|
||||||
|
<img
|
||||||
|
src={bank.logo}
|
||||||
|
alt={`${bank.name} logo`}
|
||||||
|
className="w-4 h-4 object-contain"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Building2 className="w-4 h-4" />
|
||||||
|
)}
|
||||||
|
<span>{bank.name}</span>
|
||||||
|
</div>
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
) : (
|
||||||
|
<Alert>
|
||||||
|
<AlertDescription>
|
||||||
|
No banks available for the selected country.
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Instructions */}
|
||||||
|
{selectedBank && (
|
||||||
|
<Alert>
|
||||||
|
<AlertDescription>
|
||||||
|
You'll be redirected to your bank's website to authorize the
|
||||||
|
connection. After approval, you'll return to Leggen and your
|
||||||
|
account will start syncing.
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Error Display */}
|
||||||
|
{connectBankMutation.isError && (
|
||||||
|
<Alert variant="destructive">
|
||||||
|
<AlertDescription>
|
||||||
|
Failed to create bank connection. Please try again.
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DrawerFooter>
|
||||||
|
<div className="flex space-x-2">
|
||||||
|
<Button
|
||||||
|
onClick={handleConnect}
|
||||||
|
disabled={!selectedBank || connectBankMutation.isPending}
|
||||||
|
className="flex-1"
|
||||||
|
>
|
||||||
|
<ExternalLink className="h-4 w-4 mr-2" />
|
||||||
|
{connectBankMutation.isPending
|
||||||
|
? "Connecting..."
|
||||||
|
: "Open Bank Authorization"}
|
||||||
|
</Button>
|
||||||
|
<DrawerClose asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
disabled={connectBankMutation.isPending}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</DrawerClose>
|
||||||
|
</div>
|
||||||
|
</DrawerFooter>
|
||||||
|
</DrawerContent>
|
||||||
|
</Drawer>
|
||||||
|
);
|
||||||
|
}
|
||||||
180
frontend/src/components/AppSidebar.tsx
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { Link, useLocation } from "@tanstack/react-router";
|
||||||
|
import {
|
||||||
|
List,
|
||||||
|
BarChart3,
|
||||||
|
Activity,
|
||||||
|
Settings,
|
||||||
|
Building2,
|
||||||
|
TrendingUp,
|
||||||
|
ChevronDown,
|
||||||
|
ChevronUp,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { Logo } from "./ui/logo";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import { formatCurrency } from "../lib/utils";
|
||||||
|
import { useState } from "react";
|
||||||
|
import type { Account } from "../types/api";
|
||||||
|
import {
|
||||||
|
Sidebar,
|
||||||
|
SidebarContent,
|
||||||
|
SidebarFooter,
|
||||||
|
SidebarHeader,
|
||||||
|
SidebarMenu,
|
||||||
|
SidebarMenuButton,
|
||||||
|
SidebarMenuItem,
|
||||||
|
SidebarGroup,
|
||||||
|
SidebarGroupContent,
|
||||||
|
SidebarGroupLabel,
|
||||||
|
useSidebar,
|
||||||
|
} from "./ui/sidebar";
|
||||||
|
|
||||||
|
const navigation = [
|
||||||
|
{ name: "Overview", icon: List, to: "/" },
|
||||||
|
{ name: "Analytics", icon: BarChart3, to: "/analytics" },
|
||||||
|
{ name: "System", icon: Activity, to: "/system" },
|
||||||
|
{ name: "Settings", icon: Settings, to: "/settings" },
|
||||||
|
];
|
||||||
|
|
||||||
|
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
||||||
|
const location = useLocation();
|
||||||
|
const [accountsExpanded, setAccountsExpanded] = useState(false);
|
||||||
|
const { isMobile, setOpenMobile } = useSidebar();
|
||||||
|
|
||||||
|
const { data: accounts } = useQuery<Account[]>({
|
||||||
|
queryKey: ["accounts"],
|
||||||
|
queryFn: apiClient.getAccounts,
|
||||||
|
});
|
||||||
|
|
||||||
|
const totalBalance =
|
||||||
|
accounts?.reduce((sum, account) => {
|
||||||
|
const primaryBalance = account.balances?.[0]?.amount || 0;
|
||||||
|
return sum + primaryBalance;
|
||||||
|
}, 0) || 0;
|
||||||
|
|
||||||
|
// Handler to close mobile sidebar when navigation item is clicked
|
||||||
|
const handleNavigationClick = () => {
|
||||||
|
if (isMobile) {
|
||||||
|
setOpenMobile(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Sidebar collapsible="icon" {...props}>
|
||||||
|
<SidebarHeader>
|
||||||
|
<SidebarMenu>
|
||||||
|
<SidebarMenuItem>
|
||||||
|
<SidebarMenuButton
|
||||||
|
asChild
|
||||||
|
className="data-[slot=sidebar-menu-button]:!p-1.5"
|
||||||
|
>
|
||||||
|
<Link
|
||||||
|
to="/"
|
||||||
|
className="flex items-center space-x-2"
|
||||||
|
onClick={handleNavigationClick}
|
||||||
|
>
|
||||||
|
<Logo size={24} />
|
||||||
|
<span className="text-base font-semibold">Leggen</span>
|
||||||
|
</Link>
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
</SidebarMenu>
|
||||||
|
</SidebarHeader>
|
||||||
|
|
||||||
|
<SidebarContent>
|
||||||
|
<SidebarGroup>
|
||||||
|
<SidebarGroupContent>
|
||||||
|
<SidebarMenu>
|
||||||
|
{navigation.map((item) => (
|
||||||
|
<SidebarMenuItem key={item.to}>
|
||||||
|
<SidebarMenuButton
|
||||||
|
asChild
|
||||||
|
tooltip={item.name}
|
||||||
|
isActive={location.pathname === item.to}
|
||||||
|
>
|
||||||
|
<Link to={item.to} onClick={handleNavigationClick}>
|
||||||
|
<item.icon className="h-5 w-5" />
|
||||||
|
<span>{item.name}</span>
|
||||||
|
</Link>
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
))}
|
||||||
|
</SidebarMenu>
|
||||||
|
</SidebarGroupContent>
|
||||||
|
</SidebarGroup>
|
||||||
|
</SidebarContent>
|
||||||
|
|
||||||
|
<SidebarFooter>
|
||||||
|
{/* Account Summary Section */}
|
||||||
|
<SidebarGroup>
|
||||||
|
<SidebarGroupLabel>Account Summary</SidebarGroupLabel>
|
||||||
|
<div className="bg-muted rounded-lg p-1">
|
||||||
|
{/* Collapsible Header */}
|
||||||
|
<button
|
||||||
|
onClick={() => setAccountsExpanded(!accountsExpanded)}
|
||||||
|
className="w-full p-3 flex items-center justify-between hover:bg-muted/80 transition-colors rounded-lg"
|
||||||
|
>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<span className="text-sm font-medium text-muted-foreground">
|
||||||
|
Total Balance
|
||||||
|
</span>
|
||||||
|
<TrendingUp className="h-4 w-4 text-green-500" />
|
||||||
|
</div>
|
||||||
|
{accountsExpanded ? (
|
||||||
|
<ChevronUp className="h-4 w-4 text-muted-foreground" />
|
||||||
|
) : (
|
||||||
|
<ChevronDown className="h-4 w-4 text-muted-foreground" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div className="px-3 pb-2">
|
||||||
|
<p className="text-xl font-bold text-foreground">
|
||||||
|
{formatCurrency(totalBalance)}
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
{accounts?.length || 0} accounts
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Expanded Account Details */}
|
||||||
|
{accountsExpanded && accounts && accounts.length > 0 && (
|
||||||
|
<div className="border-t border-border/50 max-h-48 overflow-y-auto">
|
||||||
|
{accounts.map((account) => {
|
||||||
|
const primaryBalance = account.balances?.[0]?.amount || 0;
|
||||||
|
const currency =
|
||||||
|
account.balances?.[0]?.currency ||
|
||||||
|
account.currency ||
|
||||||
|
"EUR";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={account.id}
|
||||||
|
className="p-2 border-b border-border/30 last:border-b-0 hover:bg-muted/50 transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex items-start space-x-2">
|
||||||
|
<div className="flex-shrink-0 p-1 bg-background rounded">
|
||||||
|
<Building2 className="h-3 w-3 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1 min-w-0 flex-1">
|
||||||
|
<p className="text-xs font-medium text-foreground truncate">
|
||||||
|
{account.display_name ||
|
||||||
|
account.name ||
|
||||||
|
"Unnamed Account"}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs font-semibold text-foreground">
|
||||||
|
{formatCurrency(primaryBalance, currency)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</SidebarGroup>
|
||||||
|
</SidebarFooter>
|
||||||
|
</Sidebar>
|
||||||
|
);
|
||||||
|
}
|
||||||
200
frontend/src/components/DiscordConfigDrawer.tsx
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { MessageSquare, TestTube } from "lucide-react";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { Input } from "./ui/input";
|
||||||
|
import { Label } from "./ui/label";
|
||||||
|
import { Switch } from "./ui/switch";
|
||||||
|
import { EditButton } from "./ui/edit-button";
|
||||||
|
import {
|
||||||
|
Drawer,
|
||||||
|
DrawerClose,
|
||||||
|
DrawerContent,
|
||||||
|
DrawerDescription,
|
||||||
|
DrawerFooter,
|
||||||
|
DrawerHeader,
|
||||||
|
DrawerTitle,
|
||||||
|
DrawerTrigger,
|
||||||
|
} from "./ui/drawer";
|
||||||
|
import type { NotificationSettings, DiscordConfig } from "../types/api";
|
||||||
|
|
||||||
|
interface DiscordConfigDrawerProps {
|
||||||
|
settings: NotificationSettings | undefined;
|
||||||
|
trigger?: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DiscordConfigDrawer({
|
||||||
|
settings,
|
||||||
|
trigger,
|
||||||
|
}: DiscordConfigDrawerProps) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const [config, setConfig] = useState<DiscordConfig>({
|
||||||
|
webhook: "",
|
||||||
|
enabled: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (settings?.discord) {
|
||||||
|
setConfig({ ...settings.discord });
|
||||||
|
}
|
||||||
|
}, [settings]);
|
||||||
|
|
||||||
|
const updateMutation = useMutation({
|
||||||
|
mutationFn: (discordConfig: DiscordConfig) =>
|
||||||
|
apiClient.updateNotificationSettings({
|
||||||
|
...settings,
|
||||||
|
discord: discordConfig,
|
||||||
|
filters: settings?.filters || {
|
||||||
|
case_insensitive: [],
|
||||||
|
case_sensitive: [],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["notificationSettings"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["notificationServices"] });
|
||||||
|
setOpen(false);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error("Failed to update Discord configuration:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const testMutation = useMutation({
|
||||||
|
mutationFn: () =>
|
||||||
|
apiClient.testNotification({
|
||||||
|
service: "discord",
|
||||||
|
message:
|
||||||
|
"Test notification from Leggen - Discord configuration is working!",
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
console.log("Test Discord notification sent successfully");
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error("Failed to send test Discord notification:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
updateMutation.mutate(config);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTest = () => {
|
||||||
|
testMutation.mutate();
|
||||||
|
};
|
||||||
|
|
||||||
|
const isConfigValid =
|
||||||
|
config.webhook.trim().length > 0 &&
|
||||||
|
config.webhook.includes("discord.com/api/webhooks");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Drawer open={open} onOpenChange={setOpen}>
|
||||||
|
<DrawerTrigger asChild>{trigger || <EditButton />}</DrawerTrigger>
|
||||||
|
<DrawerContent>
|
||||||
|
<div className="mx-auto w-full max-w-md">
|
||||||
|
<DrawerHeader>
|
||||||
|
<DrawerTitle className="flex items-center space-x-2">
|
||||||
|
<MessageSquare className="h-5 w-5 text-primary" />
|
||||||
|
<span>Discord Configuration</span>
|
||||||
|
</DrawerTitle>
|
||||||
|
<DrawerDescription>
|
||||||
|
Configure Discord webhook notifications for transaction alerts
|
||||||
|
</DrawerDescription>
|
||||||
|
</DrawerHeader>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="p-4 space-y-6">
|
||||||
|
{/* Enable/Disable Toggle */}
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<Label className="text-base font-medium">
|
||||||
|
Enable Discord Notifications
|
||||||
|
</Label>
|
||||||
|
<Switch
|
||||||
|
checked={config.enabled}
|
||||||
|
onCheckedChange={(enabled) => setConfig({ ...config, enabled })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Webhook URL */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="discord-webhook">Discord Webhook URL</Label>
|
||||||
|
<Input
|
||||||
|
id="discord-webhook"
|
||||||
|
type="url"
|
||||||
|
placeholder="https://discord.com/api/webhooks/..."
|
||||||
|
value={config.webhook}
|
||||||
|
onChange={(e) =>
|
||||||
|
setConfig({ ...config, webhook: e.target.value })
|
||||||
|
}
|
||||||
|
disabled={!config.enabled}
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Create a webhook in your Discord server settings under
|
||||||
|
Integrations → Webhooks
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Configuration Status */}
|
||||||
|
{config.enabled && (
|
||||||
|
<div className="p-3 bg-muted rounded-md">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<div
|
||||||
|
className={`w-2 h-2 rounded-full ${isConfigValid ? "bg-green-500" : "bg-red-500"}`}
|
||||||
|
/>
|
||||||
|
<span className="text-sm font-medium">
|
||||||
|
{isConfigValid
|
||||||
|
? "Configuration Valid"
|
||||||
|
: "Invalid Webhook URL"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{!isConfigValid && config.webhook.trim().length > 0 && (
|
||||||
|
<p className="text-xs text-muted-foreground mt-1">
|
||||||
|
Please enter a valid Discord webhook URL
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<DrawerFooter className="px-0">
|
||||||
|
<div className="flex space-x-2">
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
disabled={updateMutation.isPending || !config.enabled}
|
||||||
|
>
|
||||||
|
{updateMutation.isPending
|
||||||
|
? "Saving..."
|
||||||
|
: "Save Configuration"}
|
||||||
|
</Button>
|
||||||
|
{config.enabled && isConfigValid && (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleTest}
|
||||||
|
disabled={testMutation.isPending}
|
||||||
|
>
|
||||||
|
{testMutation.isPending ? (
|
||||||
|
<>
|
||||||
|
<TestTube className="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
Testing...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<TestTube className="h-4 w-4 mr-2" />
|
||||||
|
Test
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<DrawerClose asChild>
|
||||||
|
<Button variant="ghost">Cancel</Button>
|
||||||
|
</DrawerClose>
|
||||||
|
</DrawerFooter>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</DrawerContent>
|
||||||
|
</Drawer>
|
||||||
|
);
|
||||||
|
}
|
||||||
95
frontend/src/components/ErrorBoundary.tsx
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
import { Component } from "react";
|
||||||
|
import type { ErrorInfo, ReactNode } from "react";
|
||||||
|
import { AlertTriangle, RefreshCw } from "lucide-react";
|
||||||
|
import { Card, CardContent } from "./ui/card";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "./ui/alert";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: ReactNode;
|
||||||
|
fallback?: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
hasError: boolean;
|
||||||
|
error?: Error;
|
||||||
|
errorInfo?: ErrorInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ErrorBoundary extends Component<Props, State> {
|
||||||
|
constructor(props: Props) {
|
||||||
|
super(props);
|
||||||
|
this.state = { hasError: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
static getDerivedStateFromError(error: Error): State {
|
||||||
|
return { hasError: true, error };
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||||
|
console.error("ErrorBoundary caught an error:", error, errorInfo);
|
||||||
|
this.setState({ error, errorInfo });
|
||||||
|
}
|
||||||
|
|
||||||
|
handleReset = () => {
|
||||||
|
this.setState({ hasError: false, error: undefined, errorInfo: undefined });
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if (this.state.hasError) {
|
||||||
|
if (this.props.fallback) {
|
||||||
|
return this.props.fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardContent className="p-6">
|
||||||
|
<div className="flex items-center justify-center text-center">
|
||||||
|
<div>
|
||||||
|
<AlertTriangle className="h-12 w-12 text-destructive mx-auto mb-4" />
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
Something went wrong
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground mb-4">
|
||||||
|
An error occurred while rendering this component. Please try
|
||||||
|
refreshing or check the console for more details.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{this.state.error && (
|
||||||
|
<Alert variant="destructive" className="mb-4 text-left">
|
||||||
|
<AlertTriangle className="h-4 w-4" />
|
||||||
|
<AlertTitle>Error Details</AlertTitle>
|
||||||
|
<AlertDescription className="space-y-2">
|
||||||
|
<p className="text-sm font-mono">
|
||||||
|
<strong>Error:</strong> {this.state.error.message}
|
||||||
|
</p>
|
||||||
|
{this.state.error.stack && (
|
||||||
|
<details className="mt-2">
|
||||||
|
<summary className="text-sm cursor-pointer">
|
||||||
|
Stack trace
|
||||||
|
</summary>
|
||||||
|
<pre className="text-xs mt-1 whitespace-pre-wrap">
|
||||||
|
{this.state.error.stack}
|
||||||
|
</pre>
|
||||||
|
</details>
|
||||||
|
)}
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Button onClick={this.handleReset}>
|
||||||
|
<RefreshCw className="h-4 w-4 mr-2" />
|
||||||
|
Try Again
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.props.children;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ErrorBoundary;
|
||||||
73
frontend/src/components/FiltersSkeleton.tsx
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import { Skeleton } from "./ui/skeleton";
|
||||||
|
import { Card, CardContent } from "./ui/card";
|
||||||
|
|
||||||
|
export default function FiltersSkeleton() {
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<div className="px-6 py-4 border-b border-border">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<Skeleton className="h-6 w-32" />
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Skeleton className="h-8 w-24" />
|
||||||
|
<Skeleton className="h-8 w-20" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<CardContent className="px-6 py-4 border-b border-border bg-muted/30">
|
||||||
|
{/* Quick Date Filters Skeleton */}
|
||||||
|
<div className="mb-6">
|
||||||
|
<Skeleton className="h-4 w-32 mb-3" />
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
<Skeleton className="h-10 w-24 rounded-lg" />
|
||||||
|
<Skeleton className="h-10 w-20 rounded-lg" />
|
||||||
|
<Skeleton className="h-10 w-28 rounded-lg" />
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
<Skeleton className="h-10 w-24 rounded-lg" />
|
||||||
|
<Skeleton className="h-10 w-20 rounded-lg" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Filter Fields Skeleton */}
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
|
||||||
|
<div className="sm:col-span-2 lg:col-span-1">
|
||||||
|
<Skeleton className="h-4 w-16 mb-1" />
|
||||||
|
<Skeleton className="h-10 w-full" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Skeleton className="h-4 w-16 mb-1" />
|
||||||
|
<Skeleton className="h-10 w-full" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Skeleton className="h-4 w-20 mb-1" />
|
||||||
|
<Skeleton className="h-10 w-full" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Skeleton className="h-4 w-16 mb-1" />
|
||||||
|
<Skeleton className="h-10 w-full" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Amount Range Filters Skeleton */}
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mt-4">
|
||||||
|
<div>
|
||||||
|
<Skeleton className="h-4 w-20 mb-1" />
|
||||||
|
<Skeleton className="h-10 w-full" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Skeleton className="h-4 w-20 mb-1" />
|
||||||
|
<Skeleton className="h-10 w-full" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
|
||||||
|
{/* Results Summary Skeleton */}
|
||||||
|
<CardContent className="px-6 py-3 bg-muted/30 border-b border-border">
|
||||||
|
<Skeleton className="h-4 w-48" />
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
259
frontend/src/components/NotificationFiltersDrawer.tsx
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { Plus, X } from "lucide-react";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { Input } from "./ui/input";
|
||||||
|
import { Label } from "./ui/label";
|
||||||
|
import { EditButton } from "./ui/edit-button";
|
||||||
|
import {
|
||||||
|
Drawer,
|
||||||
|
DrawerClose,
|
||||||
|
DrawerContent,
|
||||||
|
DrawerDescription,
|
||||||
|
DrawerFooter,
|
||||||
|
DrawerHeader,
|
||||||
|
DrawerTitle,
|
||||||
|
DrawerTrigger,
|
||||||
|
} from "./ui/drawer";
|
||||||
|
import type { NotificationSettings, NotificationFilters } from "../types/api";
|
||||||
|
|
||||||
|
interface NotificationFiltersDrawerProps {
|
||||||
|
settings: NotificationSettings | undefined;
|
||||||
|
trigger?: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function NotificationFiltersDrawer({
|
||||||
|
settings,
|
||||||
|
trigger,
|
||||||
|
}: NotificationFiltersDrawerProps) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const [filters, setFilters] = useState<NotificationFilters>({
|
||||||
|
case_insensitive: [],
|
||||||
|
case_sensitive: [],
|
||||||
|
});
|
||||||
|
const [newCaseInsensitive, setNewCaseInsensitive] = useState("");
|
||||||
|
const [newCaseSensitive, setNewCaseSensitive] = useState("");
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (settings?.filters) {
|
||||||
|
setFilters({
|
||||||
|
case_insensitive: [...(settings.filters.case_insensitive || [])],
|
||||||
|
case_sensitive: [...(settings.filters.case_sensitive || [])],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [settings]);
|
||||||
|
|
||||||
|
const updateMutation = useMutation({
|
||||||
|
mutationFn: (updatedFilters: NotificationFilters) =>
|
||||||
|
apiClient.updateNotificationSettings({
|
||||||
|
...settings,
|
||||||
|
filters: updatedFilters,
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["notificationSettings"] });
|
||||||
|
setOpen(false);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error("Failed to update notification filters:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
updateMutation.mutate(filters);
|
||||||
|
};
|
||||||
|
|
||||||
|
const addCaseInsensitiveFilter = () => {
|
||||||
|
if (
|
||||||
|
newCaseInsensitive.trim() &&
|
||||||
|
!filters.case_insensitive.includes(newCaseInsensitive.trim())
|
||||||
|
) {
|
||||||
|
setFilters({
|
||||||
|
...filters,
|
||||||
|
case_insensitive: [
|
||||||
|
...filters.case_insensitive,
|
||||||
|
newCaseInsensitive.trim(),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
setNewCaseInsensitive("");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const addCaseSensitiveFilter = () => {
|
||||||
|
if (
|
||||||
|
newCaseSensitive.trim() &&
|
||||||
|
!filters.case_sensitive?.includes(newCaseSensitive.trim())
|
||||||
|
) {
|
||||||
|
setFilters({
|
||||||
|
...filters,
|
||||||
|
case_sensitive: [
|
||||||
|
...(filters.case_sensitive || []),
|
||||||
|
newCaseSensitive.trim(),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
setNewCaseSensitive("");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeCaseInsensitiveFilter = (index: number) => {
|
||||||
|
setFilters({
|
||||||
|
...filters,
|
||||||
|
case_insensitive: filters.case_insensitive.filter((_, i) => i !== index),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeCaseSensitiveFilter = (index: number) => {
|
||||||
|
setFilters({
|
||||||
|
...filters,
|
||||||
|
case_sensitive:
|
||||||
|
filters.case_sensitive?.filter((_, i) => i !== index) || [],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Drawer open={open} onOpenChange={setOpen}>
|
||||||
|
<DrawerTrigger asChild>{trigger || <EditButton />}</DrawerTrigger>
|
||||||
|
<DrawerContent>
|
||||||
|
<div className="mx-auto w-full max-w-2xl">
|
||||||
|
<DrawerHeader>
|
||||||
|
<DrawerTitle>Notification Filters</DrawerTitle>
|
||||||
|
<DrawerDescription>
|
||||||
|
Configure which transaction descriptions should trigger
|
||||||
|
notifications
|
||||||
|
</DrawerDescription>
|
||||||
|
</DrawerHeader>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="p-4 space-y-6">
|
||||||
|
{/* Case Insensitive Filters */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<Label className="text-base font-medium">
|
||||||
|
Case Insensitive Filters
|
||||||
|
</Label>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Filters that match regardless of capitalization (e.g., "AMAZON"
|
||||||
|
matches "amazon")
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="flex space-x-2">
|
||||||
|
<Input
|
||||||
|
placeholder="Add filter term..."
|
||||||
|
value={newCaseInsensitive}
|
||||||
|
onChange={(e) => setNewCaseInsensitive(e.target.value)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
addCaseInsensitiveFilter();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={addCaseInsensitiveFilter}
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
<Plus className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-wrap gap-2 min-h-[2rem] p-3 bg-muted rounded-md">
|
||||||
|
{filters.case_insensitive.length > 0 ? (
|
||||||
|
filters.case_insensitive.map((filter, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="flex items-center space-x-1 bg-secondary text-secondary-foreground px-2 py-1 rounded-md text-sm"
|
||||||
|
>
|
||||||
|
<span>{filter}</span>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={() => removeCaseInsensitiveFilter(index)}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-5 w-5 hover:bg-secondary-foreground/10"
|
||||||
|
>
|
||||||
|
<X className="h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<span className="text-muted-foreground text-sm">
|
||||||
|
No filters added
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Case Sensitive Filters */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<Label className="text-base font-medium">
|
||||||
|
Case Sensitive Filters
|
||||||
|
</Label>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Filters that match exactly as typed (e.g., "AMAZON" only matches
|
||||||
|
"AMAZON")
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="flex space-x-2">
|
||||||
|
<Input
|
||||||
|
placeholder="Add filter term..."
|
||||||
|
value={newCaseSensitive}
|
||||||
|
onChange={(e) => setNewCaseSensitive(e.target.value)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
addCaseSensitiveFilter();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={addCaseSensitiveFilter}
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
<Plus className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-wrap gap-2 min-h-[2rem] p-3 bg-muted rounded-md">
|
||||||
|
{filters.case_sensitive && filters.case_sensitive.length > 0 ? (
|
||||||
|
filters.case_sensitive.map((filter, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="flex items-center space-x-1 bg-secondary text-secondary-foreground px-2 py-1 rounded-md text-sm"
|
||||||
|
>
|
||||||
|
<span>{filter}</span>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={() => removeCaseSensitiveFilter(index)}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-5 w-5 hover:bg-secondary-foreground/10"
|
||||||
|
>
|
||||||
|
<X className="h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<span className="text-muted-foreground text-sm">
|
||||||
|
No filters added
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DrawerFooter className="px-0">
|
||||||
|
<Button type="submit" disabled={updateMutation.isPending}>
|
||||||
|
{updateMutation.isPending ? "Saving..." : "Save Filters"}
|
||||||
|
</Button>
|
||||||
|
<DrawerClose asChild>
|
||||||
|
<Button variant="outline">Cancel</Button>
|
||||||
|
</DrawerClose>
|
||||||
|
</DrawerFooter>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</DrawerContent>
|
||||||
|
</Drawer>
|
||||||
|
);
|
||||||
|
}
|
||||||
452
frontend/src/components/Notifications.tsx
Normal file
@@ -0,0 +1,452 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
Bell,
|
||||||
|
MessageSquare,
|
||||||
|
Send,
|
||||||
|
Trash2,
|
||||||
|
RefreshCw,
|
||||||
|
AlertCircle,
|
||||||
|
CheckCircle,
|
||||||
|
Settings,
|
||||||
|
TestTube,
|
||||||
|
Activity,
|
||||||
|
Clock,
|
||||||
|
TrendingUp,
|
||||||
|
User,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import NotificationsSkeleton from "./NotificationsSkeleton";
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from "./ui/card";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "./ui/alert";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { Input } from "./ui/input";
|
||||||
|
import { Label } from "./ui/label";
|
||||||
|
import { Badge } from "./ui/badge";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "./ui/select";
|
||||||
|
import type {
|
||||||
|
NotificationSettings,
|
||||||
|
NotificationService,
|
||||||
|
SyncOperationsResponse,
|
||||||
|
} from "../types/api";
|
||||||
|
|
||||||
|
export default function Notifications() {
|
||||||
|
const [testService, setTestService] = useState("");
|
||||||
|
const [testMessage, setTestMessage] = useState(
|
||||||
|
"Test notification from Leggen",
|
||||||
|
);
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: settings,
|
||||||
|
isLoading: settingsLoading,
|
||||||
|
error: settingsError,
|
||||||
|
refetch: refetchSettings,
|
||||||
|
} = useQuery<NotificationSettings>({
|
||||||
|
queryKey: ["notificationSettings"],
|
||||||
|
queryFn: apiClient.getNotificationSettings,
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: services,
|
||||||
|
isLoading: servicesLoading,
|
||||||
|
error: servicesError,
|
||||||
|
refetch: refetchServices,
|
||||||
|
} = useQuery<NotificationService[]>({
|
||||||
|
queryKey: ["notificationServices"],
|
||||||
|
queryFn: apiClient.getNotificationServices,
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: syncOperations,
|
||||||
|
isLoading: syncOperationsLoading,
|
||||||
|
error: syncOperationsError,
|
||||||
|
refetch: refetchSyncOperations,
|
||||||
|
} = useQuery<SyncOperationsResponse>({
|
||||||
|
queryKey: ["syncOperations"],
|
||||||
|
queryFn: () => apiClient.getSyncOperations(10, 0), // Get latest 10 operations
|
||||||
|
});
|
||||||
|
|
||||||
|
const testMutation = useMutation({
|
||||||
|
mutationFn: apiClient.testNotification,
|
||||||
|
onSuccess: () => {
|
||||||
|
// Could show a success toast here
|
||||||
|
console.log("Test notification sent successfully");
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error("Failed to send test notification:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const deleteServiceMutation = useMutation({
|
||||||
|
mutationFn: apiClient.deleteNotificationService,
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["notificationSettings"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["notificationServices"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (settingsLoading || servicesLoading || syncOperationsLoading) {
|
||||||
|
return <NotificationsSkeleton />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settingsError || servicesError || syncOperationsError) {
|
||||||
|
return (
|
||||||
|
<Alert variant="destructive">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<AlertTitle>Failed to load system data</AlertTitle>
|
||||||
|
<AlertDescription className="space-y-3">
|
||||||
|
<p>
|
||||||
|
Unable to connect to the Leggen API. Please check your configuration
|
||||||
|
and ensure the API server is running.
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
refetchSettings();
|
||||||
|
refetchServices();
|
||||||
|
refetchSyncOperations();
|
||||||
|
}}
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
<RefreshCw className="h-4 w-4 mr-2" />
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleTestNotification = () => {
|
||||||
|
if (!testService) return;
|
||||||
|
|
||||||
|
testMutation.mutate({
|
||||||
|
service: testService.toLowerCase(),
|
||||||
|
message: testMessage,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteService = (serviceName: string) => {
|
||||||
|
if (
|
||||||
|
confirm(
|
||||||
|
`Are you sure you want to delete the ${serviceName} notification service?`,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
deleteServiceMutation.mutate(serviceName.toLowerCase());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
{/* Sync Operations Section */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center space-x-2">
|
||||||
|
<Activity className="h-5 w-5 text-primary" />
|
||||||
|
<span>Sync Operations</span>
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>Recent synchronization activities</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
{!syncOperations || syncOperations.operations.length === 0 ? (
|
||||||
|
<div className="text-center py-6">
|
||||||
|
<Activity className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
No sync operations yet
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Sync operations will appear here once you start syncing your
|
||||||
|
accounts.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-4">
|
||||||
|
{syncOperations.operations.slice(0, 5).map((operation) => {
|
||||||
|
const startedAt = new Date(operation.started_at);
|
||||||
|
const isRunning = !operation.completed_at;
|
||||||
|
const duration = operation.duration_seconds
|
||||||
|
? `${Math.round(operation.duration_seconds)}s`
|
||||||
|
: "";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={operation.id}
|
||||||
|
className="flex items-center justify-between p-4 border rounded-lg hover:bg-accent transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex items-center space-x-4">
|
||||||
|
<div
|
||||||
|
className={`p-2 rounded-full ${
|
||||||
|
isRunning
|
||||||
|
? "bg-blue-100 text-blue-600"
|
||||||
|
: operation.success
|
||||||
|
? "bg-green-100 text-green-600"
|
||||||
|
: "bg-red-100 text-red-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isRunning ? (
|
||||||
|
<RefreshCw className="h-4 w-4 animate-spin" />
|
||||||
|
) : operation.success ? (
|
||||||
|
<CheckCircle className="h-4 w-4" />
|
||||||
|
) : (
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<h4 className="text-sm font-medium text-foreground">
|
||||||
|
{isRunning
|
||||||
|
? "Sync Running"
|
||||||
|
: operation.success
|
||||||
|
? "Sync Completed"
|
||||||
|
: "Sync Failed"}
|
||||||
|
</h4>
|
||||||
|
<Badge variant="outline" className="text-xs">
|
||||||
|
{operation.trigger_type}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-4 mt-1 text-xs text-muted-foreground">
|
||||||
|
<span className="flex items-center space-x-1">
|
||||||
|
<Clock className="h-3 w-3" />
|
||||||
|
<span>
|
||||||
|
{startedAt.toLocaleDateString()}{" "}
|
||||||
|
{startedAt.toLocaleTimeString()}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
{duration && <span>Duration: {duration}</span>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-right text-sm text-muted-foreground">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<User className="h-3 w-3" />
|
||||||
|
<span>{operation.accounts_processed} accounts</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2 mt-1">
|
||||||
|
<TrendingUp className="h-3 w-3" />
|
||||||
|
<span>
|
||||||
|
{operation.transactions_added} new transactions
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{operation.errors.length > 0 && (
|
||||||
|
<div className="flex items-center space-x-2 mt-1 text-red-600">
|
||||||
|
<AlertCircle className="h-3 w-3" />
|
||||||
|
<span>{operation.errors.length} errors</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Test Notification Section */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center space-x-2">
|
||||||
|
<TestTube className="h-5 w-5 text-primary" />
|
||||||
|
<span>Test Notifications</span>
|
||||||
|
</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<div>
|
||||||
|
<Label htmlFor="service" className="text-foreground">
|
||||||
|
Service
|
||||||
|
</Label>
|
||||||
|
<Select value={testService} onValueChange={setTestService}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Select a service..." />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{services?.map((service) => (
|
||||||
|
<SelectItem key={service.name} value={service.name}>
|
||||||
|
{service.name}{" "}
|
||||||
|
{service.enabled ? "(Enabled)" : "(Disabled)"}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<Label htmlFor="message" className="text-foreground">
|
||||||
|
Message
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="message"
|
||||||
|
type="text"
|
||||||
|
value={testMessage}
|
||||||
|
onChange={(e) => setTestMessage(e.target.value)}
|
||||||
|
placeholder="Test message..."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-4">
|
||||||
|
<Button
|
||||||
|
onClick={handleTestNotification}
|
||||||
|
disabled={!testService || testMutation.isPending}
|
||||||
|
>
|
||||||
|
<Send className="h-4 w-4 mr-2" />
|
||||||
|
{testMutation.isPending ? "Sending..." : "Send Test Notification"}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Notification Services */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center space-x-2">
|
||||||
|
<Bell className="h-5 w-5 text-primary" />
|
||||||
|
<span>Notification Services</span>
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>Manage your notification services</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
{!services || services.length === 0 ? (
|
||||||
|
<CardContent className="text-center">
|
||||||
|
<Bell className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
No notification services configured
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Configure notification services in your backend to receive alerts.
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
) : (
|
||||||
|
<CardContent className="p-0">
|
||||||
|
<div className="divide-y divide-border">
|
||||||
|
{services.map((service) => (
|
||||||
|
<div
|
||||||
|
key={service.name}
|
||||||
|
className="p-6 hover:bg-accent transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="flex items-center space-x-4">
|
||||||
|
<div className="p-3 bg-muted rounded-full">
|
||||||
|
{service.name.toLowerCase().includes("discord") ? (
|
||||||
|
<MessageSquare className="h-6 w-6 text-muted-foreground" />
|
||||||
|
) : service.name.toLowerCase().includes("telegram") ? (
|
||||||
|
<Send className="h-6 w-6 text-muted-foreground" />
|
||||||
|
) : (
|
||||||
|
<Bell className="h-6 w-6 text-muted-foreground" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h4 className="text-lg font-medium text-foreground capitalize">
|
||||||
|
{service.name}
|
||||||
|
</h4>
|
||||||
|
<div className="flex items-center space-x-2 mt-1">
|
||||||
|
<Badge
|
||||||
|
variant={
|
||||||
|
service.enabled ? "default" : "destructive"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{service.enabled ? (
|
||||||
|
<CheckCircle className="h-3 w-3 mr-1" />
|
||||||
|
) : (
|
||||||
|
<AlertCircle className="h-3 w-3 mr-1" />
|
||||||
|
)}
|
||||||
|
{service.enabled ? "Enabled" : "Disabled"}
|
||||||
|
</Badge>
|
||||||
|
<Badge
|
||||||
|
variant={
|
||||||
|
service.configured ? "secondary" : "outline"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{service.configured
|
||||||
|
? "Configured"
|
||||||
|
: "Not Configured"}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={() => handleDeleteService(service.name)}
|
||||||
|
disabled={deleteServiceMutation.isPending}
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
className="text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||||
|
>
|
||||||
|
<Trash2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Notification Settings */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center space-x-2">
|
||||||
|
<Settings className="h-5 w-5 text-primary" />
|
||||||
|
<span>Notification Settings</span>
|
||||||
|
</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
{settings && (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div>
|
||||||
|
<h4 className="text-sm font-medium text-foreground mb-2">
|
||||||
|
Filters
|
||||||
|
</h4>
|
||||||
|
<div className="bg-muted rounded-md p-4">
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||||
|
<div>
|
||||||
|
<Label className="text-xs font-medium text-muted-foreground mb-1 block">
|
||||||
|
Case Insensitive Filters
|
||||||
|
</Label>
|
||||||
|
<p className="text-sm text-foreground">
|
||||||
|
{settings.filters.case_insensitive.length > 0
|
||||||
|
? settings.filters.case_insensitive.join(", ")
|
||||||
|
: "None"}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Label className="text-xs font-medium text-muted-foreground mb-1 block">
|
||||||
|
Case Sensitive Filters
|
||||||
|
</Label>
|
||||||
|
<p className="text-sm text-foreground">
|
||||||
|
{settings.filters.case_sensitive &&
|
||||||
|
settings.filters.case_sensitive.length > 0
|
||||||
|
? settings.filters.case_sensitive.join(", ")
|
||||||
|
: "None"}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="text-sm text-muted-foreground">
|
||||||
|
<p>
|
||||||
|
Configure notification settings through your backend API to
|
||||||
|
customize filters and service configurations.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
95
frontend/src/components/NotificationsSkeleton.tsx
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
import { Skeleton } from "./ui/skeleton";
|
||||||
|
import { Card, CardContent, CardHeader } from "./ui/card";
|
||||||
|
|
||||||
|
export default function NotificationsSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
{/* Test Notification Section Skeleton */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Skeleton className="h-5 w-5" />
|
||||||
|
<Skeleton className="h-6 w-36" />
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-4 w-16" />
|
||||||
|
<Skeleton className="h-10 w-full" />
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-4 w-16" />
|
||||||
|
<Skeleton className="h-10 w-full" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-4">
|
||||||
|
<Skeleton className="h-10 w-48" />
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Notification Services Skeleton */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Skeleton className="h-5 w-5" />
|
||||||
|
<Skeleton className="h-6 w-40" />
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-4 w-56" />
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="p-0">
|
||||||
|
<div className="divide-y divide-border">
|
||||||
|
{Array.from({ length: 3 }).map((_, i) => (
|
||||||
|
<div key={i} className="p-6">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="flex items-center space-x-4">
|
||||||
|
<Skeleton className="h-12 w-12 rounded-full" />
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-5 w-24" />
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Skeleton className="h-5 w-16" />
|
||||||
|
<Skeleton className="h-5 w-20" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-8 w-8" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Notification Settings Skeleton */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Skeleton className="h-5 w-5" />
|
||||||
|
<Skeleton className="h-6 w-40" />
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-4 w-16" />
|
||||||
|
<div className="bg-muted rounded-md p-4">
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-3 w-32" />
|
||||||
|
<Skeleton className="h-4 w-24" />
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-3 w-28" />
|
||||||
|
<Skeleton className="h-4 w-20" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-12 w-full" />
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
119
frontend/src/components/RawTransactionModal.tsx
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
import { X, Copy, Check } from "lucide-react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import type { RawTransactionData } from "../types/api";
|
||||||
|
|
||||||
|
interface RawTransactionModalProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
rawTransaction: RawTransactionData | undefined;
|
||||||
|
transactionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function RawTransactionModal({
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
rawTransaction,
|
||||||
|
transactionId,
|
||||||
|
}: RawTransactionModalProps) {
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
|
||||||
|
if (!isOpen) return null;
|
||||||
|
|
||||||
|
const handleCopy = async () => {
|
||||||
|
if (!rawTransaction) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(
|
||||||
|
JSON.stringify(rawTransaction, null, 2),
|
||||||
|
);
|
||||||
|
setCopied(true);
|
||||||
|
setTimeout(() => setCopied(false), 2000);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Failed to copy to clipboard:", err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 z-50 overflow-y-auto">
|
||||||
|
<div className="flex items-center justify-center min-h-screen px-4 pt-4 pb-20 text-center sm:block sm:p-0">
|
||||||
|
{/* Background overlay */}
|
||||||
|
<div
|
||||||
|
className="fixed inset-0 bg-background/80 backdrop-blur-sm transition-opacity"
|
||||||
|
onClick={onClose}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Modal panel */}
|
||||||
|
<div className="inline-block align-bottom bg-card rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-4xl sm:w-full border">
|
||||||
|
<div className="bg-card px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
|
||||||
|
<div className="flex items-center justify-between mb-4">
|
||||||
|
<h3 className="text-lg font-medium text-foreground">
|
||||||
|
Raw Transaction Data
|
||||||
|
</h3>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Button
|
||||||
|
onClick={handleCopy}
|
||||||
|
disabled={!rawTransaction}
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
{copied ? (
|
||||||
|
<>
|
||||||
|
<Check className="h-4 w-4 mr-1 text-green-600 dark:text-green-400" />
|
||||||
|
Copied!
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Copy className="h-4 w-4 mr-1" />
|
||||||
|
Copy JSON
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
<Button onClick={onClose} variant="ghost" size="sm">
|
||||||
|
<X className="h-5 w-5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mb-4">
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Transaction ID:{" "}
|
||||||
|
<code className="bg-muted px-2 py-1 rounded text-xs text-foreground">
|
||||||
|
{transactionId}
|
||||||
|
</code>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{rawTransaction ? (
|
||||||
|
<div className="bg-muted rounded-lg p-4 overflow-auto max-h-96">
|
||||||
|
<pre className="text-sm text-foreground whitespace-pre-wrap">
|
||||||
|
{JSON.stringify(rawTransaction, null, 2)}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="bg-muted rounded-lg p-8 text-center">
|
||||||
|
<p className="text-foreground">
|
||||||
|
Raw transaction data is not available for this transaction.
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-muted-foreground mt-2">
|
||||||
|
Try refreshing the page or check if the transaction was
|
||||||
|
fetched with summary_only=false.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="bg-muted/50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={onClose}
|
||||||
|
className="w-full sm:ml-3 sm:w-auto"
|
||||||
|
>
|
||||||
|
Close
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
273
frontend/src/components/S3BackupConfigDrawer.tsx
Normal file
@@ -0,0 +1,273 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { Cloud, TestTube } from "lucide-react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { Input } from "./ui/input";
|
||||||
|
import { Label } from "./ui/label";
|
||||||
|
import { Switch } from "./ui/switch";
|
||||||
|
import { EditButton } from "./ui/edit-button";
|
||||||
|
import {
|
||||||
|
Drawer,
|
||||||
|
DrawerClose,
|
||||||
|
DrawerContent,
|
||||||
|
DrawerDescription,
|
||||||
|
DrawerFooter,
|
||||||
|
DrawerHeader,
|
||||||
|
DrawerTitle,
|
||||||
|
DrawerTrigger,
|
||||||
|
} from "./ui/drawer";
|
||||||
|
import type { BackupSettings, S3Config } from "../types/api";
|
||||||
|
|
||||||
|
interface S3BackupConfigDrawerProps {
|
||||||
|
settings?: BackupSettings;
|
||||||
|
trigger?: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function S3BackupConfigDrawer({
|
||||||
|
settings,
|
||||||
|
trigger,
|
||||||
|
}: S3BackupConfigDrawerProps) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const [config, setConfig] = useState<S3Config>({
|
||||||
|
access_key_id: "",
|
||||||
|
secret_access_key: "",
|
||||||
|
bucket_name: "",
|
||||||
|
region: "us-east-1",
|
||||||
|
endpoint_url: "",
|
||||||
|
path_style: false,
|
||||||
|
enabled: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (settings?.s3) {
|
||||||
|
setConfig({ ...settings.s3 });
|
||||||
|
}
|
||||||
|
}, [settings]);
|
||||||
|
|
||||||
|
const updateMutation = useMutation({
|
||||||
|
mutationFn: (s3Config: S3Config) =>
|
||||||
|
apiClient.updateBackupSettings({
|
||||||
|
s3: s3Config,
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["backupSettings"] });
|
||||||
|
setOpen(false);
|
||||||
|
toast.success("S3 backup configuration saved successfully");
|
||||||
|
},
|
||||||
|
onError: (error: Error & { response?: { data?: { detail?: string } } }) => {
|
||||||
|
console.error("Failed to update S3 backup configuration:", error);
|
||||||
|
const message =
|
||||||
|
error?.response?.data?.detail ||
|
||||||
|
"Failed to save S3 configuration. Please check your settings and try again.";
|
||||||
|
toast.error(message);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const testMutation = useMutation({
|
||||||
|
mutationFn: () =>
|
||||||
|
apiClient.testBackupConnection({
|
||||||
|
service: "s3",
|
||||||
|
config: config,
|
||||||
|
}),
|
||||||
|
onSuccess: (response) => {
|
||||||
|
if (response.success) {
|
||||||
|
console.log("S3 connection test successful");
|
||||||
|
toast.success(
|
||||||
|
"S3 connection test successful! Your configuration is working correctly.",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.error("S3 connection test failed:", response.message);
|
||||||
|
toast.error(response.message || "S3 connection test failed. Please verify your credentials and settings.");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: (error: Error & { response?: { data?: { detail?: string } } }) => {
|
||||||
|
console.error("Failed to test S3 connection:", error);
|
||||||
|
const message =
|
||||||
|
error?.response?.data?.detail ||
|
||||||
|
"S3 connection test failed. Please verify your credentials and settings.";
|
||||||
|
toast.error(message);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
updateMutation.mutate(config);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTest = () => {
|
||||||
|
testMutation.mutate();
|
||||||
|
};
|
||||||
|
|
||||||
|
const isConfigValid =
|
||||||
|
config.access_key_id.trim().length > 0 &&
|
||||||
|
config.secret_access_key.trim().length > 0 &&
|
||||||
|
config.bucket_name.trim().length > 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Drawer open={open} onOpenChange={setOpen}>
|
||||||
|
<DrawerTrigger asChild>{trigger || <EditButton />}</DrawerTrigger>
|
||||||
|
<DrawerContent>
|
||||||
|
<div className="mx-auto w-full max-w-sm">
|
||||||
|
<DrawerHeader>
|
||||||
|
<DrawerTitle className="flex items-center space-x-2">
|
||||||
|
<Cloud className="h-5 w-5 text-primary" />
|
||||||
|
<span>S3 Backup Configuration</span>
|
||||||
|
</DrawerTitle>
|
||||||
|
<DrawerDescription>
|
||||||
|
Configure S3 settings for automatic database backups
|
||||||
|
</DrawerDescription>
|
||||||
|
</DrawerHeader>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="px-4 space-y-4">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Switch
|
||||||
|
id="enabled"
|
||||||
|
checked={config.enabled}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
setConfig({ ...config, enabled: checked })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="enabled">Enable S3 backups</Label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{config.enabled && (
|
||||||
|
<>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="access_key_id">Access Key ID</Label>
|
||||||
|
<Input
|
||||||
|
id="access_key_id"
|
||||||
|
type="text"
|
||||||
|
value={config.access_key_id}
|
||||||
|
onChange={(e) =>
|
||||||
|
setConfig({ ...config, access_key_id: e.target.value })
|
||||||
|
}
|
||||||
|
placeholder="Your AWS Access Key ID"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="secret_access_key">Secret Access Key</Label>
|
||||||
|
<Input
|
||||||
|
id="secret_access_key"
|
||||||
|
type="password"
|
||||||
|
value={config.secret_access_key}
|
||||||
|
onChange={(e) =>
|
||||||
|
setConfig({
|
||||||
|
...config,
|
||||||
|
secret_access_key: e.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
placeholder="Your AWS Secret Access Key"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="bucket_name">Bucket Name</Label>
|
||||||
|
<Input
|
||||||
|
id="bucket_name"
|
||||||
|
type="text"
|
||||||
|
value={config.bucket_name}
|
||||||
|
onChange={(e) =>
|
||||||
|
setConfig({ ...config, bucket_name: e.target.value })
|
||||||
|
}
|
||||||
|
placeholder="my-backup-bucket"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="region">Region</Label>
|
||||||
|
<Input
|
||||||
|
id="region"
|
||||||
|
type="text"
|
||||||
|
value={config.region}
|
||||||
|
onChange={(e) =>
|
||||||
|
setConfig({ ...config, region: e.target.value })
|
||||||
|
}
|
||||||
|
placeholder="us-east-1"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="endpoint_url">
|
||||||
|
Custom Endpoint URL (Optional)
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="endpoint_url"
|
||||||
|
type="url"
|
||||||
|
value={config.endpoint_url || ""}
|
||||||
|
onChange={(e) =>
|
||||||
|
setConfig({ ...config, endpoint_url: e.target.value })
|
||||||
|
}
|
||||||
|
placeholder="https://custom-s3-endpoint.com"
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
For S3-compatible services like MinIO or DigitalOcean Spaces
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Switch
|
||||||
|
id="path_style"
|
||||||
|
checked={config.path_style}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
setConfig({ ...config, path_style: checked })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="path_style">Use path-style addressing</Label>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Enable for older S3 implementations or certain S3-compatible
|
||||||
|
services
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<DrawerFooter className="px-0">
|
||||||
|
<div className="flex space-x-2">
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
disabled={updateMutation.isPending || !config.enabled}
|
||||||
|
>
|
||||||
|
{updateMutation.isPending
|
||||||
|
? "Saving..."
|
||||||
|
: "Save Configuration"}
|
||||||
|
</Button>
|
||||||
|
{config.enabled && isConfigValid && (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleTest}
|
||||||
|
disabled={testMutation.isPending}
|
||||||
|
>
|
||||||
|
{testMutation.isPending ? (
|
||||||
|
<>
|
||||||
|
<TestTube className="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
Testing...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<TestTube className="h-4 w-4 mr-2" />
|
||||||
|
Test
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<DrawerClose asChild>
|
||||||
|
<Button variant="ghost">Cancel</Button>
|
||||||
|
</DrawerClose>
|
||||||
|
</DrawerFooter>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</DrawerContent>
|
||||||
|
</Drawer>
|
||||||
|
);
|
||||||
|
}
|
||||||
984
frontend/src/components/Settings.tsx
Normal file
@@ -0,0 +1,984 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
CreditCard,
|
||||||
|
TrendingUp,
|
||||||
|
TrendingDown,
|
||||||
|
Building2,
|
||||||
|
RefreshCw,
|
||||||
|
AlertCircle,
|
||||||
|
Edit2,
|
||||||
|
Check,
|
||||||
|
X,
|
||||||
|
Bell,
|
||||||
|
MessageSquare,
|
||||||
|
Send,
|
||||||
|
Trash2,
|
||||||
|
User,
|
||||||
|
Filter,
|
||||||
|
Cloud,
|
||||||
|
Archive,
|
||||||
|
Eye,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import { formatCurrency, formatDate } from "../lib/utils";
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from "./ui/card";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "./ui/alert";
|
||||||
|
import { Label } from "./ui/label";
|
||||||
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "./ui/tabs";
|
||||||
|
import AccountsSkeleton from "./AccountsSkeleton";
|
||||||
|
import NotificationFiltersDrawer from "./NotificationFiltersDrawer";
|
||||||
|
import DiscordConfigDrawer from "./DiscordConfigDrawer";
|
||||||
|
import TelegramConfigDrawer from "./TelegramConfigDrawer";
|
||||||
|
import AddBankAccountDrawer from "./AddBankAccountDrawer";
|
||||||
|
import S3BackupConfigDrawer from "./S3BackupConfigDrawer";
|
||||||
|
import type {
|
||||||
|
Account,
|
||||||
|
Balance,
|
||||||
|
NotificationSettings,
|
||||||
|
NotificationService,
|
||||||
|
BackupSettings,
|
||||||
|
BackupInfo,
|
||||||
|
} from "../types/api";
|
||||||
|
|
||||||
|
// Helper function to get status indicator color and styles
|
||||||
|
const getStatusIndicator = (status: string) => {
|
||||||
|
const statusLower = status.toLowerCase();
|
||||||
|
|
||||||
|
switch (statusLower) {
|
||||||
|
case "ready":
|
||||||
|
return {
|
||||||
|
color: "bg-green-500",
|
||||||
|
tooltip: "Ready",
|
||||||
|
};
|
||||||
|
case "pending":
|
||||||
|
return {
|
||||||
|
color: "bg-amber-500",
|
||||||
|
tooltip: "Pending",
|
||||||
|
};
|
||||||
|
case "error":
|
||||||
|
case "failed":
|
||||||
|
return {
|
||||||
|
color: "bg-destructive",
|
||||||
|
tooltip: "Error",
|
||||||
|
};
|
||||||
|
case "inactive":
|
||||||
|
return {
|
||||||
|
color: "bg-muted-foreground",
|
||||||
|
tooltip: "Inactive",
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
color: "bg-primary",
|
||||||
|
tooltip: status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function Settings() {
|
||||||
|
const [editingAccountId, setEditingAccountId] = useState<string | null>(null);
|
||||||
|
const [editingName, setEditingName] = useState("");
|
||||||
|
const [failedImages, setFailedImages] = useState<Set<string>>(new Set());
|
||||||
|
const [showBackups, setShowBackups] = useState(false);
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
// Account queries
|
||||||
|
const {
|
||||||
|
data: accounts,
|
||||||
|
isLoading: accountsLoading,
|
||||||
|
error: accountsError,
|
||||||
|
refetch: refetchAccounts,
|
||||||
|
} = useQuery<Account[]>({
|
||||||
|
queryKey: ["accounts"],
|
||||||
|
queryFn: apiClient.getAccounts,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: balances } = useQuery<Balance[]>({
|
||||||
|
queryKey: ["balances"],
|
||||||
|
queryFn: () => apiClient.getBalances(),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Notification queries
|
||||||
|
const {
|
||||||
|
data: notificationSettings,
|
||||||
|
isLoading: settingsLoading,
|
||||||
|
error: settingsError,
|
||||||
|
refetch: refetchSettings,
|
||||||
|
} = useQuery<NotificationSettings>({
|
||||||
|
queryKey: ["notificationSettings"],
|
||||||
|
queryFn: apiClient.getNotificationSettings,
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: services,
|
||||||
|
isLoading: servicesLoading,
|
||||||
|
error: servicesError,
|
||||||
|
refetch: refetchServices,
|
||||||
|
} = useQuery<NotificationService[]>({
|
||||||
|
queryKey: ["notificationServices"],
|
||||||
|
queryFn: apiClient.getNotificationServices,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: bankConnections } = useQuery({
|
||||||
|
queryKey: ["bankConnections"],
|
||||||
|
queryFn: apiClient.getBankConnectionsStatus,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Backup queries
|
||||||
|
const {
|
||||||
|
data: backupSettings,
|
||||||
|
isLoading: backupLoading,
|
||||||
|
error: backupError,
|
||||||
|
refetch: refetchBackup,
|
||||||
|
} = useQuery<BackupSettings>({
|
||||||
|
queryKey: ["backupSettings"],
|
||||||
|
queryFn: apiClient.getBackupSettings,
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: backups,
|
||||||
|
isLoading: backupsLoading,
|
||||||
|
error: backupsError,
|
||||||
|
refetch: refetchBackups,
|
||||||
|
} = useQuery<BackupInfo[]>({
|
||||||
|
queryKey: ["backups"],
|
||||||
|
queryFn: apiClient.listBackups,
|
||||||
|
enabled: showBackups,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Account mutations
|
||||||
|
const updateAccountMutation = useMutation({
|
||||||
|
mutationFn: ({ id, display_name }: { id: string; display_name: string }) =>
|
||||||
|
apiClient.updateAccount(id, { display_name }),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||||
|
setEditingAccountId(null);
|
||||||
|
setEditingName("");
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error("Failed to update account:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Notification mutations
|
||||||
|
const deleteServiceMutation = useMutation({
|
||||||
|
mutationFn: apiClient.deleteNotificationService,
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["notificationSettings"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["notificationServices"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Bank connection mutations
|
||||||
|
const deleteBankConnectionMutation = useMutation({
|
||||||
|
mutationFn: apiClient.deleteBankConnection,
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["bankConnections"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["balances"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Backup mutations
|
||||||
|
const createBackupMutation = useMutation({
|
||||||
|
mutationFn: () => apiClient.performBackupOperation({ operation: "backup" }),
|
||||||
|
onSuccess: (response) => {
|
||||||
|
if (response.success) {
|
||||||
|
toast.success(response.message || "Backup created successfully!");
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["backups"] });
|
||||||
|
} else {
|
||||||
|
toast.error(response.message || "Failed to create backup.");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: (error: Error & { response?: { data?: { detail?: string } } }) => {
|
||||||
|
console.error("Failed to create backup:", error);
|
||||||
|
const message =
|
||||||
|
error?.response?.data?.detail ||
|
||||||
|
"Failed to create backup. Please check your S3 configuration.";
|
||||||
|
toast.error(message);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Account handlers
|
||||||
|
const handleEditStart = (account: Account) => {
|
||||||
|
setEditingAccountId(account.id);
|
||||||
|
setEditingName(account.display_name || account.name || "");
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditSave = () => {
|
||||||
|
if (editingAccountId && editingName.trim()) {
|
||||||
|
updateAccountMutation.mutate({
|
||||||
|
id: editingAccountId,
|
||||||
|
display_name: editingName.trim(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditCancel = () => {
|
||||||
|
setEditingAccountId(null);
|
||||||
|
setEditingName("");
|
||||||
|
};
|
||||||
|
|
||||||
|
// Notification handlers
|
||||||
|
const handleDeleteService = (serviceName: string) => {
|
||||||
|
if (
|
||||||
|
confirm(
|
||||||
|
`Are you sure you want to delete the ${serviceName} notification service?`,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
deleteServiceMutation.mutate(serviceName.toLowerCase());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Backup handlers
|
||||||
|
const handleCreateBackup = () => {
|
||||||
|
if (!backupSettings?.s3?.enabled) {
|
||||||
|
toast.error("S3 backup is not enabled. Please configure and enable S3 backup first.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
createBackupMutation.mutate();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleViewBackups = () => {
|
||||||
|
if (!backupSettings?.s3?.enabled) {
|
||||||
|
toast.error("S3 backup is not enabled. Please configure and enable S3 backup first.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setShowBackups(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isLoading =
|
||||||
|
accountsLoading || settingsLoading || servicesLoading || backupLoading;
|
||||||
|
const hasError =
|
||||||
|
accountsError || settingsError || servicesError || backupError;
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <AccountsSkeleton />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasError) {
|
||||||
|
return (
|
||||||
|
<Alert variant="destructive">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<AlertTitle>Failed to load settings</AlertTitle>
|
||||||
|
<AlertDescription className="space-y-3">
|
||||||
|
<p>
|
||||||
|
Unable to connect to the Leggen API. Please check your configuration
|
||||||
|
and ensure the API server is running.
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
refetchAccounts();
|
||||||
|
refetchSettings();
|
||||||
|
refetchServices();
|
||||||
|
refetchBackup();
|
||||||
|
}}
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
<RefreshCw className="h-4 w-4 mr-2" />
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<Tabs defaultValue="accounts" className="space-y-6">
|
||||||
|
<TabsList className="grid w-full grid-cols-3">
|
||||||
|
<TabsTrigger value="accounts" className="flex items-center space-x-2">
|
||||||
|
<User className="h-4 w-4" />
|
||||||
|
<span>Accounts</span>
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger
|
||||||
|
value="notifications"
|
||||||
|
className="flex items-center space-x-2"
|
||||||
|
>
|
||||||
|
<Bell className="h-4 w-4" />
|
||||||
|
<span>Notifications</span>
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="backup" className="flex items-center space-x-2">
|
||||||
|
<Cloud className="h-4 w-4" />
|
||||||
|
<span>Backup</span>
|
||||||
|
</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
|
||||||
|
<TabsContent value="accounts" className="space-y-6">
|
||||||
|
{/* Account Management Section */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Account Management</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Manage your connected bank accounts and customize their display
|
||||||
|
names
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
{!accounts || accounts.length === 0 ? (
|
||||||
|
<CardContent className="p-6 text-center">
|
||||||
|
<CreditCard className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
No accounts found
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground mb-4">
|
||||||
|
Connect your first bank account to get started with Leggen.
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
) : (
|
||||||
|
<CardContent className="p-0">
|
||||||
|
<div className="divide-y divide-border">
|
||||||
|
{accounts.map((account) => {
|
||||||
|
// Get balance from account's balances array or fallback to balances query
|
||||||
|
const accountBalance = account.balances?.[0];
|
||||||
|
const fallbackBalance = balances?.find(
|
||||||
|
(b) => b.account_id === account.id,
|
||||||
|
);
|
||||||
|
const balance =
|
||||||
|
accountBalance?.amount ||
|
||||||
|
fallbackBalance?.balance_amount ||
|
||||||
|
0;
|
||||||
|
const currency =
|
||||||
|
accountBalance?.currency ||
|
||||||
|
fallbackBalance?.currency ||
|
||||||
|
account.currency ||
|
||||||
|
"EUR";
|
||||||
|
const isPositive = balance >= 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={account.id}
|
||||||
|
className="p-4 sm:p-6 hover:bg-accent transition-colors"
|
||||||
|
>
|
||||||
|
{/* Mobile layout - stack vertically */}
|
||||||
|
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 sm:gap-4">
|
||||||
|
<div className="flex items-start sm:items-center space-x-3 sm:space-x-4 min-w-0 flex-1">
|
||||||
|
<div className="flex-shrink-0 w-10 h-10 sm:w-12 sm:h-12 rounded-full overflow-hidden bg-muted flex items-center justify-center">
|
||||||
|
{account.logo && !failedImages.has(account.id) ? (
|
||||||
|
<img
|
||||||
|
src={account.logo}
|
||||||
|
alt={`${account.institution_id} logo`}
|
||||||
|
className="w-6 h-6 sm:w-8 sm:h-8 object-contain"
|
||||||
|
onError={() => {
|
||||||
|
console.warn(
|
||||||
|
`Failed to load bank logo for ${account.institution_id}: ${account.logo}`,
|
||||||
|
);
|
||||||
|
setFailedImages(
|
||||||
|
(prev) => new Set([...prev, account.id]),
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Building2 className="h-5 w-5 sm:h-6 sm:w-6 text-muted-foreground" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
{editingAccountId === account.id ? (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={editingName}
|
||||||
|
onChange={(e) =>
|
||||||
|
setEditingName(e.target.value)
|
||||||
|
}
|
||||||
|
className="flex-1 px-3 py-1 text-base sm:text-lg font-medium border border-input rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-ring focus:border-ring"
|
||||||
|
placeholder="Custom account name"
|
||||||
|
name="search"
|
||||||
|
autoComplete="off"
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") handleEditSave();
|
||||||
|
if (e.key === "Escape")
|
||||||
|
handleEditCancel();
|
||||||
|
}}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
onClick={handleEditSave}
|
||||||
|
disabled={
|
||||||
|
!editingName.trim() ||
|
||||||
|
updateAccountMutation.isPending
|
||||||
|
}
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-8 w-8 text-green-600 hover:text-green-700 hover:bg-green-100"
|
||||||
|
title="Save changes"
|
||||||
|
>
|
||||||
|
<Check className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={handleEditCancel}
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-8 w-8"
|
||||||
|
title="Cancel editing"
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-muted-foreground truncate">
|
||||||
|
{account.institution_id}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center space-x-2 min-w-0">
|
||||||
|
<h4 className="text-base sm:text-lg font-medium text-foreground truncate">
|
||||||
|
{account.display_name ||
|
||||||
|
account.name ||
|
||||||
|
"Unnamed Account"}
|
||||||
|
</h4>
|
||||||
|
<Button
|
||||||
|
onClick={() => handleEditStart(account)}
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-7 w-7 flex-shrink-0"
|
||||||
|
title="Edit account name"
|
||||||
|
>
|
||||||
|
<Edit2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-muted-foreground truncate">
|
||||||
|
{account.institution_id}
|
||||||
|
</p>
|
||||||
|
{account.iban && (
|
||||||
|
<p className="text-xs text-muted-foreground mt-1 font-mono break-all sm:break-normal">
|
||||||
|
IBAN: {account.iban}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Balance and date section */}
|
||||||
|
<div className="flex items-center justify-between sm:flex-col sm:items-end sm:text-right flex-shrink-0">
|
||||||
|
{/* Date and status indicator - left on mobile, bottom on desktop */}
|
||||||
|
<div className="flex items-center space-x-2 order-1 sm:order-2">
|
||||||
|
<div
|
||||||
|
className={`w-3 h-3 rounded-full ${getStatusIndicator(account.status).color} relative group cursor-help`}
|
||||||
|
role="img"
|
||||||
|
aria-label={`Account status: ${getStatusIndicator(account.status).tooltip}`}
|
||||||
|
>
|
||||||
|
{/* Tooltip */}
|
||||||
|
<div className="absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 hidden group-hover:block bg-gray-900 text-white text-xs rounded py-1 px-2 whitespace-nowrap z-10">
|
||||||
|
{getStatusIndicator(account.status).tooltip}
|
||||||
|
<div className="absolute top-full left-1/2 transform -translate-x-1/2 border-2 border-transparent border-t-gray-900"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs sm:text-sm text-muted-foreground whitespace-nowrap">
|
||||||
|
Updated{" "}
|
||||||
|
{formatDate(
|
||||||
|
account.last_accessed || account.created,
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Balance - right on mobile, top on desktop */}
|
||||||
|
<div className="flex items-center space-x-2 order-2 sm:order-1">
|
||||||
|
{isPositive ? (
|
||||||
|
<TrendingUp className="h-4 w-4 text-green-500" />
|
||||||
|
) : (
|
||||||
|
<TrendingDown className="h-4 w-4 text-red-500" />
|
||||||
|
)}
|
||||||
|
<p
|
||||||
|
className={`text-base sm:text-lg font-semibold ${
|
||||||
|
isPositive ? "text-green-600" : "text-red-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{formatCurrency(balance, currency)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Bank Connections Status */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<CardTitle>Bank Connections</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Status of all bank connection requests and their
|
||||||
|
authorization state
|
||||||
|
</CardDescription>
|
||||||
|
</div>
|
||||||
|
<AddBankAccountDrawer />
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
{!bankConnections || bankConnections.length === 0 ? (
|
||||||
|
<CardContent className="p-6 text-center">
|
||||||
|
<Building2 className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
No bank connections found
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Bank connection requests will appear here after you connect
|
||||||
|
accounts.
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
) : (
|
||||||
|
<CardContent className="p-0">
|
||||||
|
<div className="divide-y divide-border">
|
||||||
|
{bankConnections.map((connection) => {
|
||||||
|
const statusColor =
|
||||||
|
connection.status.toLowerCase() === "ln"
|
||||||
|
? "bg-green-500"
|
||||||
|
: connection.status.toLowerCase() === "cr"
|
||||||
|
? "bg-amber-500"
|
||||||
|
: connection.status.toLowerCase() === "ex"
|
||||||
|
? "bg-red-500"
|
||||||
|
: "bg-muted-foreground";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={connection.requisition_id}
|
||||||
|
className="p-4 sm:p-6 hover:bg-accent transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="flex items-center space-x-4 min-w-0 flex-1">
|
||||||
|
<div className="flex-shrink-0 w-10 h-10 rounded-full bg-muted flex items-center justify-center">
|
||||||
|
<Building2 className="h-5 w-5 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<h4 className="text-base font-medium text-foreground truncate">
|
||||||
|
{connection.bank_name}
|
||||||
|
</h4>
|
||||||
|
<div
|
||||||
|
className={`w-3 h-3 rounded-full ${statusColor}`}
|
||||||
|
title={connection.status_display}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
{connection.status_display} •{" "}
|
||||||
|
{connection.accounts_count} account
|
||||||
|
{connection.accounts_count !== 1 ? "s" : ""}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs text-muted-foreground font-mono">
|
||||||
|
ID: {connection.requisition_id}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center space-x-2 flex-shrink-0">
|
||||||
|
<div className="text-right">
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Created {formatDate(connection.created_at)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
const isWorking =
|
||||||
|
connection.status.toLowerCase() === "ln";
|
||||||
|
const message = isWorking
|
||||||
|
? `Are you sure you want to disconnect "${connection.bank_name}"? This will stop syncing new transactions but keep your existing transaction history.`
|
||||||
|
: `Delete connection to ${connection.bank_name}?`;
|
||||||
|
|
||||||
|
if (confirm(message)) {
|
||||||
|
deleteBankConnectionMutation.mutate(
|
||||||
|
connection.requisition_id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={deleteBankConnectionMutation.isPending}
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
||||||
|
title="Delete connection"
|
||||||
|
>
|
||||||
|
<Trash2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
<TabsContent value="notifications" className="space-y-6">
|
||||||
|
{/* Notification Services */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center space-x-2">
|
||||||
|
<Bell className="h-5 w-5 text-primary" />
|
||||||
|
<span>Notification Services</span>
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Manage your notification services
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
{!services || services.length === 0 ? (
|
||||||
|
<CardContent className="text-center">
|
||||||
|
<Bell className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
No notification services configured
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Configure notification services in your backend to receive
|
||||||
|
alerts.
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
) : (
|
||||||
|
<CardContent className="p-0">
|
||||||
|
<div className="divide-y divide-border">
|
||||||
|
{services.map((service) => (
|
||||||
|
<div
|
||||||
|
key={service.name}
|
||||||
|
className="p-6 hover:bg-accent transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="flex items-center space-x-4">
|
||||||
|
<div className="p-3 bg-muted rounded-full">
|
||||||
|
{service.name.toLowerCase().includes("discord") ? (
|
||||||
|
<MessageSquare className="h-6 w-6 text-muted-foreground" />
|
||||||
|
) : service.name
|
||||||
|
.toLowerCase()
|
||||||
|
.includes("telegram") ? (
|
||||||
|
<Send className="h-6 w-6 text-muted-foreground" />
|
||||||
|
) : (
|
||||||
|
<Bell className="h-6 w-6 text-muted-foreground" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex-1">
|
||||||
|
<div className="flex items-center space-x-3">
|
||||||
|
<h4 className="text-lg font-medium text-foreground capitalize">
|
||||||
|
{service.name}
|
||||||
|
</h4>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<div
|
||||||
|
className={`w-2 h-2 rounded-full ${
|
||||||
|
service.enabled && service.configured
|
||||||
|
? "bg-green-500"
|
||||||
|
: service.enabled
|
||||||
|
? "bg-amber-500"
|
||||||
|
: "bg-muted-foreground"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
<span className="text-sm text-muted-foreground">
|
||||||
|
{service.enabled && service.configured
|
||||||
|
? "Active"
|
||||||
|
: service.enabled
|
||||||
|
? "Needs Configuration"
|
||||||
|
: "Disabled"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
{service.name.toLowerCase().includes("discord") ? (
|
||||||
|
<DiscordConfigDrawer
|
||||||
|
settings={notificationSettings}
|
||||||
|
/>
|
||||||
|
) : service.name
|
||||||
|
.toLowerCase()
|
||||||
|
.includes("telegram") ? (
|
||||||
|
<TelegramConfigDrawer
|
||||||
|
settings={notificationSettings}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={() => handleDeleteService(service.name)}
|
||||||
|
disabled={deleteServiceMutation.isPending}
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
className="text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||||
|
>
|
||||||
|
<Trash2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Notification Filters */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<CardTitle className="flex items-center space-x-2">
|
||||||
|
<Filter className="h-5 w-5 text-primary" />
|
||||||
|
<span>Notification Filters</span>
|
||||||
|
</CardTitle>
|
||||||
|
<NotificationFiltersDrawer settings={notificationSettings} />
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
{notificationSettings?.filters ? (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="bg-muted rounded-md p-4">
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||||
|
<div>
|
||||||
|
<Label className="text-xs font-medium text-muted-foreground mb-2 block">
|
||||||
|
Case Insensitive Filters
|
||||||
|
</Label>
|
||||||
|
<div className="min-h-[2rem] flex flex-wrap gap-1">
|
||||||
|
{notificationSettings.filters.case_insensitive
|
||||||
|
.length > 0 ? (
|
||||||
|
notificationSettings.filters.case_insensitive.map(
|
||||||
|
(filter, index) => (
|
||||||
|
<span
|
||||||
|
key={index}
|
||||||
|
className="inline-flex items-center px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs"
|
||||||
|
>
|
||||||
|
{filter}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
None
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Label className="text-xs font-medium text-muted-foreground mb-2 block">
|
||||||
|
Case Sensitive Filters
|
||||||
|
</Label>
|
||||||
|
<div className="min-h-[2rem] flex flex-wrap gap-1">
|
||||||
|
{notificationSettings.filters.case_sensitive &&
|
||||||
|
notificationSettings.filters.case_sensitive.length >
|
||||||
|
0 ? (
|
||||||
|
notificationSettings.filters.case_sensitive.map(
|
||||||
|
(filter, index) => (
|
||||||
|
<span
|
||||||
|
key={index}
|
||||||
|
className="inline-flex items-center px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs"
|
||||||
|
>
|
||||||
|
{filter}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
None
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Filters determine which transaction descriptions will
|
||||||
|
trigger notifications. Add terms to exclude transactions
|
||||||
|
containing those words.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="text-center py-8">
|
||||||
|
<Filter className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
No notification filters configured
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground mb-4">
|
||||||
|
Set up filters to control which transactions trigger
|
||||||
|
notifications.
|
||||||
|
</p>
|
||||||
|
<NotificationFiltersDrawer settings={notificationSettings} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
<TabsContent value="backup" className="space-y-6">
|
||||||
|
{/* S3 Backup Configuration */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center space-x-2">
|
||||||
|
<Cloud className="h-5 w-5 text-primary" />
|
||||||
|
<span>S3 Backup Configuration</span>
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Configure automatic database backups to Amazon S3 or
|
||||||
|
S3-compatible storage
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
<CardContent>
|
||||||
|
{!backupSettings?.s3 ? (
|
||||||
|
<div className="text-center py-8">
|
||||||
|
<Cloud className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
No S3 backup configured
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground mb-4">
|
||||||
|
Set up S3 backup to automatically backup your database to
|
||||||
|
the cloud.
|
||||||
|
</p>
|
||||||
|
<S3BackupConfigDrawer settings={backupSettings} />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex items-center justify-between p-4 border rounded-lg">
|
||||||
|
<div className="flex items-center space-x-4">
|
||||||
|
<div className="p-3 bg-muted rounded-full">
|
||||||
|
<Cloud className="h-6 w-6 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center space-x-3">
|
||||||
|
<h4 className="text-lg font-medium text-foreground">
|
||||||
|
S3 Backup
|
||||||
|
</h4>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<div
|
||||||
|
className={`w-2 h-2 rounded-full ${
|
||||||
|
backupSettings.s3.enabled
|
||||||
|
? "bg-green-500"
|
||||||
|
: "bg-muted-foreground"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
<span className="text-sm text-muted-foreground">
|
||||||
|
{backupSettings.s3.enabled
|
||||||
|
? "Enabled"
|
||||||
|
: "Disabled"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 space-y-1">
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
<span className="font-medium">Bucket:</span>{" "}
|
||||||
|
{backupSettings.s3.bucket_name}
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
<span className="font-medium">Region:</span>{" "}
|
||||||
|
{backupSettings.s3.region}
|
||||||
|
</p>
|
||||||
|
{backupSettings.s3.endpoint_url && (
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
<span className="font-medium">Endpoint:</span>{" "}
|
||||||
|
{backupSettings.s3.endpoint_url}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<S3BackupConfigDrawer settings={backupSettings} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="p-4 bg-muted rounded-lg">
|
||||||
|
<h5 className="font-medium mb-2">Backup Information</h5>
|
||||||
|
<p className="text-sm text-muted-foreground mb-3">
|
||||||
|
Database backups are stored in the "leggen_backups/"
|
||||||
|
folder in your S3 bucket. Backups include the complete
|
||||||
|
SQLite database file.
|
||||||
|
</p>
|
||||||
|
<div className="flex space-x-2">
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleCreateBackup}
|
||||||
|
disabled={createBackupMutation.isPending}
|
||||||
|
>
|
||||||
|
{createBackupMutation.isPending ? (
|
||||||
|
<>
|
||||||
|
<Archive className="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
Creating...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Archive className="h-4 w-4 mr-2" />
|
||||||
|
Create Backup Now
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleViewBackups}
|
||||||
|
>
|
||||||
|
<Eye className="h-4 w-4 mr-2" />
|
||||||
|
View Backups
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Backup List Modal/View */}
|
||||||
|
{showBackups && (
|
||||||
|
<div className="mt-6 p-4 border rounded-lg bg-background">
|
||||||
|
<div className="flex items-center justify-between mb-4">
|
||||||
|
<h5 className="font-medium">Available Backups</h5>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => setShowBackups(false)}
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{backupsLoading ? (
|
||||||
|
<p className="text-sm text-muted-foreground">Loading backups...</p>
|
||||||
|
) : backupsError ? (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-sm text-destructive">Failed to load backups</p>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => refetchBackups()}
|
||||||
|
>
|
||||||
|
<RefreshCw className="h-4 w-4 mr-2" />
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : !backups || backups.length === 0 ? (
|
||||||
|
<p className="text-sm text-muted-foreground">No backups found</p>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{backups.map((backup, index) => (
|
||||||
|
<div
|
||||||
|
key={backup.key || index}
|
||||||
|
className="flex items-center justify-between p-3 border rounded bg-muted/50"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium">{backup.key}</p>
|
||||||
|
<div className="flex items-center space-x-4 text-xs text-muted-foreground mt-1">
|
||||||
|
<span>Modified: {formatDate(backup.last_modified)}</span>
|
||||||
|
<span>Size: {(backup.size / 1024 / 1024).toFixed(2)} MB</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
85
frontend/src/components/SiteHeader.tsx
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import { useLocation } from "@tanstack/react-router";
|
||||||
|
import { Activity, Wifi, WifiOff } from "lucide-react";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import { ThemeToggle } from "./ui/theme-toggle";
|
||||||
|
import { Separator } from "./ui/separator";
|
||||||
|
import { SidebarTrigger } from "./ui/sidebar";
|
||||||
|
|
||||||
|
const navigation = [
|
||||||
|
{ name: "Overview", to: "/" },
|
||||||
|
{ name: "Transactions", to: "/transactions" },
|
||||||
|
{ name: "Analytics", to: "/analytics" },
|
||||||
|
{ name: "System", to: "/system" },
|
||||||
|
{ name: "Settings", to: "/settings" },
|
||||||
|
];
|
||||||
|
|
||||||
|
export function SiteHeader() {
|
||||||
|
const location = useLocation();
|
||||||
|
const currentPage =
|
||||||
|
navigation.find((item) => item.to === location.pathname)?.name ||
|
||||||
|
"Dashboard";
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: healthStatus,
|
||||||
|
isLoading: healthLoading,
|
||||||
|
isError: healthError,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["health"],
|
||||||
|
queryFn: apiClient.getHealth,
|
||||||
|
refetchInterval: 30000,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<header className="flex h-16 shrink-0 items-center gap-2 border-b transition-[width,height] ease-linear">
|
||||||
|
<div className="flex w-full items-center gap-1 px-4 lg:gap-2 lg:px-6">
|
||||||
|
<SidebarTrigger className="-ml-1" />
|
||||||
|
<Separator
|
||||||
|
orientation="vertical"
|
||||||
|
className="mx-2 data-[orientation=vertical]:h-4"
|
||||||
|
/>
|
||||||
|
<h1 className="text-lg font-semibold text-card-foreground">
|
||||||
|
{currentPage}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<div className="ml-auto flex items-center space-x-3">
|
||||||
|
{/* Version display */}
|
||||||
|
<div className="flex items-center space-x-1">
|
||||||
|
{healthLoading ? (
|
||||||
|
<span className="text-xs text-muted-foreground">v...</span>
|
||||||
|
) : healthError || !healthStatus ? (
|
||||||
|
<span className="text-xs text-muted-foreground">v?</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-xs text-muted-foreground">
|
||||||
|
v{healthStatus.version || "?"}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Connection status */}
|
||||||
|
<div className="flex items-center space-x-1">
|
||||||
|
{healthLoading ? (
|
||||||
|
<>
|
||||||
|
<Activity className="h-4 w-4 text-muted-foreground animate-pulse" />
|
||||||
|
<span className="text-sm text-muted-foreground">
|
||||||
|
Checking...
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
) : healthError || healthStatus?.status !== "healthy" ? (
|
||||||
|
<>
|
||||||
|
<WifiOff className="h-4 w-4 text-destructive" />
|
||||||
|
<span className="text-sm text-destructive">Disconnected</span>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Wifi className="h-4 w-4 text-green-500" />
|
||||||
|
<span className="text-sm text-muted-foreground">Connected</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<ThemeToggle />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
358
frontend/src/components/System.tsx
Normal file
@@ -0,0 +1,358 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
RefreshCw,
|
||||||
|
AlertCircle,
|
||||||
|
CheckCircle,
|
||||||
|
Activity,
|
||||||
|
Clock,
|
||||||
|
TrendingUp,
|
||||||
|
User,
|
||||||
|
FileText,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from "./ui/card";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "./ui/alert";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { Badge } from "./ui/badge";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "./ui/dialog";
|
||||||
|
import { ScrollArea } from "./ui/scroll-area";
|
||||||
|
import type { SyncOperationsResponse, SyncOperation } from "../types/api";
|
||||||
|
|
||||||
|
// Component for viewing sync operation logs
|
||||||
|
function LogsDialog({ operation }: { operation: SyncOperation }) {
|
||||||
|
return (
|
||||||
|
<Dialog>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button variant="outline" size="sm" className="shrink-0">
|
||||||
|
<FileText className="h-3 w-3 mr-1" />
|
||||||
|
<span className="hidden sm:inline">View Logs</span>
|
||||||
|
<span className="sm:hidden">Logs</span>
|
||||||
|
</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent className="max-w-4xl max-h-[80vh]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Sync Operation Logs</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Operation #{operation.id} - Started at{" "}
|
||||||
|
{new Date(operation.started_at).toLocaleString()}
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<ScrollArea className="h-[60vh] w-full rounded border p-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
{operation.logs.length === 0 ? (
|
||||||
|
<p className="text-muted-foreground text-sm">No logs available</p>
|
||||||
|
) : (
|
||||||
|
operation.logs.map((log, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="text-sm font-mono bg-muted/50 p-2 rounded text-wrap break-all"
|
||||||
|
>
|
||||||
|
{log}
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{operation.errors.length > 0 && (
|
||||||
|
<>
|
||||||
|
<div className="mt-4 mb-2 text-sm font-semibold text-destructive">
|
||||||
|
Errors:
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
{operation.errors.map((error, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="text-sm font-mono bg-destructive/10 border border-destructive/20 p-2 rounded text-wrap break-all text-destructive"
|
||||||
|
>
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</ScrollArea>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function System() {
|
||||||
|
const {
|
||||||
|
data: syncOperations,
|
||||||
|
isLoading: syncOperationsLoading,
|
||||||
|
error: syncOperationsError,
|
||||||
|
refetch: refetchSyncOperations,
|
||||||
|
} = useQuery<SyncOperationsResponse>({
|
||||||
|
queryKey: ["syncOperations"],
|
||||||
|
queryFn: () => apiClient.getSyncOperations(10, 0), // Get latest 10 operations
|
||||||
|
});
|
||||||
|
|
||||||
|
if (syncOperationsLoading) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<Card>
|
||||||
|
<CardContent className="p-6">
|
||||||
|
<div className="flex items-center justify-center">
|
||||||
|
<RefreshCw className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||||
|
<span className="ml-2 text-muted-foreground">
|
||||||
|
Loading system status...
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (syncOperationsError) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<Alert variant="destructive">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<AlertTitle>Failed to load system data</AlertTitle>
|
||||||
|
<AlertDescription className="space-y-3">
|
||||||
|
<p>
|
||||||
|
Unable to connect to the Leggen API. Please check your
|
||||||
|
configuration and ensure the API server is running.
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
onClick={() => refetchSyncOperations()}
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
<RefreshCw className="h-4 w-4 mr-2" />
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
{/* Sync Operations Section */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center space-x-2">
|
||||||
|
<Activity className="h-5 w-5 text-primary" />
|
||||||
|
<span>Recent Sync Operations</span>
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Latest synchronization activities and their status
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
{!syncOperations || syncOperations.operations.length === 0 ? (
|
||||||
|
<div className="text-center py-6">
|
||||||
|
<Activity className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
No sync operations yet
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Sync operations will appear here once you start syncing your
|
||||||
|
accounts.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-4">
|
||||||
|
{syncOperations.operations.slice(0, 10).map((operation) => {
|
||||||
|
const startedAt = new Date(operation.started_at);
|
||||||
|
const isRunning = !operation.completed_at;
|
||||||
|
const duration = operation.duration_seconds
|
||||||
|
? `${Math.round(operation.duration_seconds)}s`
|
||||||
|
: "";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={operation.id}
|
||||||
|
className="border rounded-lg hover:bg-accent transition-colors"
|
||||||
|
>
|
||||||
|
{/* Desktop Layout */}
|
||||||
|
<div className="hidden md:flex items-center justify-between p-4">
|
||||||
|
<div className="flex items-center space-x-4">
|
||||||
|
<div
|
||||||
|
className={`p-2 rounded-full ${
|
||||||
|
isRunning
|
||||||
|
? "bg-blue-100 text-blue-600"
|
||||||
|
: operation.success
|
||||||
|
? "bg-green-100 text-green-600"
|
||||||
|
: "bg-red-100 text-red-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isRunning ? (
|
||||||
|
<RefreshCw className="h-4 w-4 animate-spin" />
|
||||||
|
) : operation.success ? (
|
||||||
|
<CheckCircle className="h-4 w-4" />
|
||||||
|
) : (
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<h4 className="text-sm font-medium text-foreground">
|
||||||
|
{isRunning
|
||||||
|
? "Sync Running"
|
||||||
|
: operation.success
|
||||||
|
? "Sync Completed"
|
||||||
|
: "Sync Failed"}
|
||||||
|
</h4>
|
||||||
|
<Badge variant="outline" className="text-xs">
|
||||||
|
{operation.trigger_type.charAt(0).toUpperCase() +
|
||||||
|
operation.trigger_type.slice(1)}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-4 mt-1 text-xs text-muted-foreground">
|
||||||
|
<span className="flex items-center space-x-1">
|
||||||
|
<Clock className="h-3 w-3" />
|
||||||
|
<span>
|
||||||
|
{startedAt.toLocaleDateString()}{" "}
|
||||||
|
{startedAt.toLocaleTimeString()}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
{duration && <span>Duration: {duration}</span>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-4">
|
||||||
|
<div className="text-right text-sm text-muted-foreground">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<User className="h-3 w-3" />
|
||||||
|
<span>{operation.accounts_processed} accounts</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2 mt-1">
|
||||||
|
<TrendingUp className="h-3 w-3" />
|
||||||
|
<span>
|
||||||
|
{operation.transactions_added} new transactions
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<LogsDialog operation={operation} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Mobile Layout */}
|
||||||
|
<div className="md:hidden p-4 space-y-3">
|
||||||
|
<div className="flex items-start justify-between">
|
||||||
|
<div className="flex items-center space-x-3">
|
||||||
|
<div
|
||||||
|
className={`p-2 rounded-full ${
|
||||||
|
isRunning
|
||||||
|
? "bg-blue-100 text-blue-600"
|
||||||
|
: operation.success
|
||||||
|
? "bg-green-100 text-green-600"
|
||||||
|
: "bg-red-100 text-red-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isRunning ? (
|
||||||
|
<RefreshCw className="h-4 w-4 animate-spin" />
|
||||||
|
) : operation.success ? (
|
||||||
|
<CheckCircle className="h-4 w-4" />
|
||||||
|
) : (
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h4 className="text-sm font-medium text-foreground">
|
||||||
|
{isRunning
|
||||||
|
? "Sync Running"
|
||||||
|
: operation.success
|
||||||
|
? "Sync Completed"
|
||||||
|
: "Sync Failed"}
|
||||||
|
</h4>
|
||||||
|
<Badge variant="outline" className="text-xs mt-1">
|
||||||
|
{operation.trigger_type.charAt(0).toUpperCase() +
|
||||||
|
operation.trigger_type.slice(1)}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<LogsDialog operation={operation} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="text-xs text-muted-foreground space-y-2">
|
||||||
|
<div className="flex items-center space-x-1">
|
||||||
|
<Clock className="h-3 w-3" />
|
||||||
|
<span>
|
||||||
|
{startedAt.toLocaleDateString()}{" "}
|
||||||
|
{startedAt.toLocaleTimeString()}
|
||||||
|
</span>
|
||||||
|
{duration && (
|
||||||
|
<span className="ml-2">• {duration}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-2 text-xs">
|
||||||
|
<div className="flex items-center space-x-1">
|
||||||
|
<User className="h-3 w-3" />
|
||||||
|
<span>{operation.accounts_processed} accounts</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-1">
|
||||||
|
<TrendingUp className="h-3 w-3" />
|
||||||
|
<span>
|
||||||
|
{operation.transactions_added} new transactions
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* System Health Summary Card */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center space-x-2">
|
||||||
|
<CheckCircle className="h-5 w-5 text-green-500" />
|
||||||
|
<span>System Health</span>
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Overall system status and performance
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||||
|
<div className="text-center p-4 bg-green-50 rounded-lg border border-green-200">
|
||||||
|
<div className="text-2xl font-bold text-green-700">
|
||||||
|
{syncOperations?.operations.filter((op) => op.success).length ||
|
||||||
|
0}
|
||||||
|
</div>
|
||||||
|
<div className="text-sm text-green-600">Successful Syncs</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-center p-4 bg-red-50 rounded-lg border border-red-200">
|
||||||
|
<div className="text-2xl font-bold text-red-700">
|
||||||
|
{syncOperations?.operations.filter(
|
||||||
|
(op) => !op.success && op.completed_at,
|
||||||
|
).length || 0}
|
||||||
|
</div>
|
||||||
|
<div className="text-sm text-red-600">Failed Syncs</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-center p-4 bg-blue-50 rounded-lg border border-blue-200">
|
||||||
|
<div className="text-2xl font-bold text-blue-700">
|
||||||
|
{syncOperations?.operations.filter((op) => !op.completed_at)
|
||||||
|
.length || 0}
|
||||||
|
</div>
|
||||||
|
<div className="text-sm text-blue-600">Running Operations</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
222
frontend/src/components/TelegramConfigDrawer.tsx
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { Send, TestTube } from "lucide-react";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { Input } from "./ui/input";
|
||||||
|
import { Label } from "./ui/label";
|
||||||
|
import { Switch } from "./ui/switch";
|
||||||
|
import { EditButton } from "./ui/edit-button";
|
||||||
|
import {
|
||||||
|
Drawer,
|
||||||
|
DrawerClose,
|
||||||
|
DrawerContent,
|
||||||
|
DrawerDescription,
|
||||||
|
DrawerFooter,
|
||||||
|
DrawerHeader,
|
||||||
|
DrawerTitle,
|
||||||
|
DrawerTrigger,
|
||||||
|
} from "./ui/drawer";
|
||||||
|
import type { NotificationSettings, TelegramConfig } from "../types/api";
|
||||||
|
|
||||||
|
interface TelegramConfigDrawerProps {
|
||||||
|
settings: NotificationSettings | undefined;
|
||||||
|
trigger?: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TelegramConfigDrawer({
|
||||||
|
settings,
|
||||||
|
trigger,
|
||||||
|
}: TelegramConfigDrawerProps) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const [config, setConfig] = useState<TelegramConfig>({
|
||||||
|
token: "",
|
||||||
|
chat_id: 0,
|
||||||
|
enabled: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (settings?.telegram) {
|
||||||
|
setConfig({ ...settings.telegram });
|
||||||
|
}
|
||||||
|
}, [settings]);
|
||||||
|
|
||||||
|
const updateMutation = useMutation({
|
||||||
|
mutationFn: (telegramConfig: TelegramConfig) =>
|
||||||
|
apiClient.updateNotificationSettings({
|
||||||
|
...settings,
|
||||||
|
telegram: telegramConfig,
|
||||||
|
filters: settings?.filters || {
|
||||||
|
case_insensitive: [],
|
||||||
|
case_sensitive: [],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["notificationSettings"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["notificationServices"] });
|
||||||
|
setOpen(false);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error("Failed to update Telegram configuration:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const testMutation = useMutation({
|
||||||
|
mutationFn: () =>
|
||||||
|
apiClient.testNotification({
|
||||||
|
service: "telegram",
|
||||||
|
message:
|
||||||
|
"Test notification from Leggen - Telegram configuration is working!",
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
console.log("Test Telegram notification sent successfully");
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error("Failed to send test Telegram notification:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
updateMutation.mutate(config);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTest = () => {
|
||||||
|
testMutation.mutate();
|
||||||
|
};
|
||||||
|
|
||||||
|
const isConfigValid = config.token.trim().length > 0 && config.chat_id !== 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Drawer open={open} onOpenChange={setOpen}>
|
||||||
|
<DrawerTrigger asChild>{trigger || <EditButton />}</DrawerTrigger>
|
||||||
|
<DrawerContent>
|
||||||
|
<div className="mx-auto w-full max-w-md">
|
||||||
|
<DrawerHeader>
|
||||||
|
<DrawerTitle className="flex items-center space-x-2">
|
||||||
|
<Send className="h-5 w-5 text-primary" />
|
||||||
|
<span>Telegram Configuration</span>
|
||||||
|
</DrawerTitle>
|
||||||
|
<DrawerDescription>
|
||||||
|
Configure Telegram bot notifications for transaction alerts
|
||||||
|
</DrawerDescription>
|
||||||
|
</DrawerHeader>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="p-4 space-y-6">
|
||||||
|
{/* Enable/Disable Toggle */}
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<Label className="text-base font-medium">
|
||||||
|
Enable Telegram Notifications
|
||||||
|
</Label>
|
||||||
|
<Switch
|
||||||
|
checked={config.enabled}
|
||||||
|
onCheckedChange={(enabled) => setConfig({ ...config, enabled })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Bot Token */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="telegram-token">Bot Token</Label>
|
||||||
|
<Input
|
||||||
|
id="telegram-token"
|
||||||
|
type="password"
|
||||||
|
placeholder="123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
|
||||||
|
value={config.token}
|
||||||
|
onChange={(e) =>
|
||||||
|
setConfig({ ...config, token: e.target.value })
|
||||||
|
}
|
||||||
|
disabled={!config.enabled}
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Create a bot using @BotFather on Telegram to get your token
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Chat ID */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="telegram-chat-id">Chat ID</Label>
|
||||||
|
<Input
|
||||||
|
id="telegram-chat-id"
|
||||||
|
type="number"
|
||||||
|
placeholder="123456789"
|
||||||
|
value={config.chat_id || ""}
|
||||||
|
onChange={(e) =>
|
||||||
|
setConfig({
|
||||||
|
...config,
|
||||||
|
chat_id: parseInt(e.target.value) || 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
disabled={!config.enabled}
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Send a message to your bot and visit
|
||||||
|
https://api.telegram.org/bot<token>/getUpdates to find
|
||||||
|
your chat ID
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Configuration Status */}
|
||||||
|
{config.enabled && (
|
||||||
|
<div className="p-3 bg-muted rounded-md">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<div
|
||||||
|
className={`w-2 h-2 rounded-full ${isConfigValid ? "bg-green-500" : "bg-red-500"}`}
|
||||||
|
/>
|
||||||
|
<span className="text-sm font-medium">
|
||||||
|
{isConfigValid
|
||||||
|
? "Configuration Valid"
|
||||||
|
: "Missing Token or Chat ID"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{!isConfigValid &&
|
||||||
|
(config.token.trim().length > 0 || config.chat_id !== 0) && (
|
||||||
|
<p className="text-xs text-muted-foreground mt-1">
|
||||||
|
Both bot token and chat ID are required
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<DrawerFooter className="px-0">
|
||||||
|
<div className="flex space-x-2">
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
disabled={updateMutation.isPending || !config.enabled}
|
||||||
|
>
|
||||||
|
{updateMutation.isPending
|
||||||
|
? "Saving..."
|
||||||
|
: "Save Configuration"}
|
||||||
|
</Button>
|
||||||
|
{config.enabled && isConfigValid && (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleTest}
|
||||||
|
disabled={testMutation.isPending}
|
||||||
|
>
|
||||||
|
{testMutation.isPending ? (
|
||||||
|
<>
|
||||||
|
<TestTube className="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
Testing...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<TestTube className="h-4 w-4 mr-2" />
|
||||||
|
Test
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<DrawerClose asChild>
|
||||||
|
<Button variant="ghost">Cancel</Button>
|
||||||
|
</DrawerClose>
|
||||||
|
</DrawerFooter>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</DrawerContent>
|
||||||
|
</Drawer>
|
||||||
|
);
|
||||||
|
}
|
||||||
102
frontend/src/components/TransactionSkeleton.tsx
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
import { Skeleton } from "./ui/skeleton";
|
||||||
|
import { Card } from "./ui/card";
|
||||||
|
|
||||||
|
interface TransactionSkeletonProps {
|
||||||
|
rows?: number;
|
||||||
|
view?: "table" | "mobile";
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TransactionSkeleton({
|
||||||
|
rows = 5,
|
||||||
|
view = "table",
|
||||||
|
}: TransactionSkeletonProps) {
|
||||||
|
const skeletonRows = Array.from({ length: rows }, (_, index) => index);
|
||||||
|
|
||||||
|
if (view === "mobile") {
|
||||||
|
return (
|
||||||
|
<Card className="divide-y divide-border">
|
||||||
|
{skeletonRows.map((_, index) => (
|
||||||
|
<div key={index} className="p-4">
|
||||||
|
<div className="flex items-start justify-between">
|
||||||
|
<div className="flex-1">
|
||||||
|
<div className="flex items-start space-x-3">
|
||||||
|
<Skeleton className="h-10 w-10 rounded-full flex-shrink-0" />
|
||||||
|
<div className="flex-1 min-w-0 space-y-2">
|
||||||
|
<Skeleton className="h-4 w-3/4" />
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Skeleton className="h-3 w-1/2" />
|
||||||
|
<Skeleton className="h-3 w-2/3" />
|
||||||
|
<Skeleton className="h-3 w-1/3" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-right ml-3 flex-shrink-0 space-y-2">
|
||||||
|
<Skeleton className="h-6 w-20" />
|
||||||
|
<Skeleton className="h-4 w-16 ml-auto" />
|
||||||
|
<Skeleton className="h-6 w-12 ml-auto" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="overflow-hidden">
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="min-w-full divide-y divide-border">
|
||||||
|
<thead className="bg-muted/50">
|
||||||
|
<tr>
|
||||||
|
<th className="px-6 py-3 text-left">
|
||||||
|
<Skeleton className="h-4 w-20" />
|
||||||
|
</th>
|
||||||
|
<th className="px-6 py-3 text-left">
|
||||||
|
<Skeleton className="h-4 w-16" />
|
||||||
|
</th>
|
||||||
|
<th className="px-6 py-3 text-left">
|
||||||
|
<Skeleton className="h-4 w-12" />
|
||||||
|
</th>
|
||||||
|
<th className="px-6 py-3 text-left">
|
||||||
|
<Skeleton className="h-4 w-8" />
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="bg-card divide-y divide-border">
|
||||||
|
{skeletonRows.map((_, index) => (
|
||||||
|
<tr key={index}>
|
||||||
|
<td className="px-6 py-4">
|
||||||
|
<div className="flex items-start space-x-3">
|
||||||
|
<Skeleton className="h-10 w-10 rounded-full flex-shrink-0" />
|
||||||
|
<div className="flex-1 space-y-2">
|
||||||
|
<Skeleton className="h-4 w-3/4" />
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Skeleton className="h-3 w-1/2" />
|
||||||
|
<Skeleton className="h-3 w-2/3" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4">
|
||||||
|
<div className="text-right">
|
||||||
|
<Skeleton className="h-6 w-24 ml-auto mb-1" />
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Skeleton className="h-4 w-20" />
|
||||||
|
<Skeleton className="h-3 w-16" />
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4">
|
||||||
|
<Skeleton className="h-6 w-12" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
576
frontend/src/components/TransactionsTable.tsx
Normal file
@@ -0,0 +1,576 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
useReactTable,
|
||||||
|
getCoreRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
getFilteredRowModel,
|
||||||
|
flexRender,
|
||||||
|
} from "@tanstack/react-table";
|
||||||
|
import type {
|
||||||
|
ColumnDef,
|
||||||
|
SortingState,
|
||||||
|
ColumnFiltersState,
|
||||||
|
} from "@tanstack/react-table";
|
||||||
|
import {
|
||||||
|
TrendingUp,
|
||||||
|
TrendingDown,
|
||||||
|
RefreshCw,
|
||||||
|
AlertCircle,
|
||||||
|
Eye,
|
||||||
|
ChevronUp,
|
||||||
|
ChevronDown,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { apiClient } from "../lib/api";
|
||||||
|
import { formatCurrency, formatDate } from "../lib/utils";
|
||||||
|
import TransactionSkeleton from "./TransactionSkeleton";
|
||||||
|
import FiltersSkeleton from "./FiltersSkeleton";
|
||||||
|
import RawTransactionModal from "./RawTransactionModal";
|
||||||
|
import { FilterBar, type FilterState } from "./filters";
|
||||||
|
import { DataTablePagination } from "./ui/data-table-pagination";
|
||||||
|
import { Card } from "./ui/card";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "./ui/alert";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import type { Account, Transaction, ApiResponse } from "../types/api";
|
||||||
|
|
||||||
|
export default function TransactionsTable() {
|
||||||
|
// Filter state consolidated into a single object
|
||||||
|
const [filterState, setFilterState] = useState<FilterState>({
|
||||||
|
searchTerm: "",
|
||||||
|
selectedAccount: "",
|
||||||
|
startDate: "",
|
||||||
|
endDate: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
const [showRawModal, setShowRawModal] = useState(false);
|
||||||
|
const [selectedTransaction, setSelectedTransaction] =
|
||||||
|
useState<Transaction | null>(null);
|
||||||
|
|
||||||
|
// Pagination state
|
||||||
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
|
const [perPage, setPerPage] = useState(50);
|
||||||
|
|
||||||
|
// Debounced search state
|
||||||
|
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(
|
||||||
|
filterState.searchTerm,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Table state (remove pagination from table)
|
||||||
|
const [sorting, setSorting] = useState<SortingState>([]);
|
||||||
|
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
||||||
|
|
||||||
|
// Helper function to update filter state
|
||||||
|
const handleFilterChange = (key: keyof FilterState, value: string) => {
|
||||||
|
setFilterState((prev) => ({ ...prev, [key]: value }));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper function to clear all filters
|
||||||
|
const handleClearFilters = () => {
|
||||||
|
setFilterState({
|
||||||
|
searchTerm: "",
|
||||||
|
selectedAccount: "",
|
||||||
|
startDate: "",
|
||||||
|
endDate: "",
|
||||||
|
});
|
||||||
|
setColumnFilters([]);
|
||||||
|
setCurrentPage(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Debounce search term to prevent excessive API calls
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
setDebouncedSearchTerm(filterState.searchTerm);
|
||||||
|
}, 300); // 300ms delay
|
||||||
|
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
}, [filterState.searchTerm]);
|
||||||
|
|
||||||
|
// Reset pagination when search term changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (debouncedSearchTerm !== filterState.searchTerm) {
|
||||||
|
setCurrentPage(1);
|
||||||
|
}
|
||||||
|
}, [debouncedSearchTerm, filterState.searchTerm]);
|
||||||
|
|
||||||
|
const { data: accounts } = useQuery<Account[]>({
|
||||||
|
queryKey: ["accounts"],
|
||||||
|
queryFn: apiClient.getAccounts,
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: transactionsResponse,
|
||||||
|
isLoading: transactionsLoading,
|
||||||
|
error: transactionsError,
|
||||||
|
refetch: refetchTransactions,
|
||||||
|
} = useQuery<ApiResponse<Transaction[]>>({
|
||||||
|
queryKey: [
|
||||||
|
"transactions",
|
||||||
|
filterState.selectedAccount,
|
||||||
|
filterState.startDate,
|
||||||
|
filterState.endDate,
|
||||||
|
currentPage,
|
||||||
|
perPage,
|
||||||
|
debouncedSearchTerm,
|
||||||
|
],
|
||||||
|
queryFn: () =>
|
||||||
|
apiClient.getTransactions({
|
||||||
|
accountId: filterState.selectedAccount || undefined,
|
||||||
|
startDate: filterState.startDate || undefined,
|
||||||
|
endDate: filterState.endDate || undefined,
|
||||||
|
page: currentPage,
|
||||||
|
perPage: perPage,
|
||||||
|
search: debouncedSearchTerm || undefined,
|
||||||
|
summaryOnly: false,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const transactions = transactionsResponse?.data || [];
|
||||||
|
const pagination = transactionsResponse?.pagination;
|
||||||
|
|
||||||
|
// Check if search is currently debouncing
|
||||||
|
const isSearchLoading = filterState.searchTerm !== debouncedSearchTerm;
|
||||||
|
|
||||||
|
// Reset pagination when total becomes 0 (no results)
|
||||||
|
useEffect(() => {
|
||||||
|
if (pagination && pagination.total === 0 && currentPage > 1) {
|
||||||
|
setCurrentPage(1);
|
||||||
|
}
|
||||||
|
}, [pagination, currentPage]);
|
||||||
|
|
||||||
|
// Reset pagination when filters change
|
||||||
|
useEffect(() => {
|
||||||
|
setCurrentPage(1);
|
||||||
|
}, [filterState.selectedAccount, filterState.startDate, filterState.endDate]);
|
||||||
|
|
||||||
|
const handleViewRaw = (transaction: Transaction) => {
|
||||||
|
setSelectedTransaction(transaction);
|
||||||
|
setShowRawModal(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCloseModal = () => {
|
||||||
|
setShowRawModal(false);
|
||||||
|
setSelectedTransaction(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const hasActiveFilters =
|
||||||
|
filterState.searchTerm ||
|
||||||
|
filterState.selectedAccount ||
|
||||||
|
filterState.startDate ||
|
||||||
|
filterState.endDate;
|
||||||
|
|
||||||
|
// Define columns
|
||||||
|
const columns: ColumnDef<Transaction>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: "description",
|
||||||
|
header: "Description",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const transaction = row.original;
|
||||||
|
const account = accounts?.find(
|
||||||
|
(acc) => acc.id === transaction.account_id,
|
||||||
|
);
|
||||||
|
const isPositive = transaction.transaction_value > 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-start space-x-3">
|
||||||
|
<div
|
||||||
|
className={`p-2 rounded-full ${
|
||||||
|
isPositive ? "bg-green-100" : "bg-red-100"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isPositive ? (
|
||||||
|
<TrendingUp className="h-4 w-4 text-green-600" />
|
||||||
|
) : (
|
||||||
|
<TrendingDown className="h-4 w-4 text-red-600" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<h4 className="text-sm font-medium text-foreground truncate">
|
||||||
|
{transaction.description}
|
||||||
|
</h4>
|
||||||
|
<div className="text-xs text-muted-foreground space-y-1">
|
||||||
|
{account && (
|
||||||
|
<p className="truncate">
|
||||||
|
{account.display_name || "Unnamed Account"}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{(transaction.creditor_name || transaction.debtor_name) && (
|
||||||
|
<p className="truncate">
|
||||||
|
{isPositive ? "From: " : "To: "}
|
||||||
|
{transaction.creditor_name || transaction.debtor_name}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{transaction.reference && (
|
||||||
|
<p className="truncate">Ref: {transaction.reference}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "transaction_value",
|
||||||
|
header: "Amount",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const transaction = row.original;
|
||||||
|
const isPositive = transaction.transaction_value > 0;
|
||||||
|
return (
|
||||||
|
<div className="text-right">
|
||||||
|
<p
|
||||||
|
className={`text-lg font-semibold ${
|
||||||
|
isPositive ? "text-green-600" : "text-red-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isPositive ? "+" : ""}
|
||||||
|
{formatCurrency(
|
||||||
|
transaction.transaction_value,
|
||||||
|
transaction.transaction_currency,
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
sortingFn: "basic",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "transaction_date",
|
||||||
|
header: "Date",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const transaction = row.original;
|
||||||
|
return (
|
||||||
|
<div className="text-sm text-foreground">
|
||||||
|
{transaction.transaction_date
|
||||||
|
? formatDate(transaction.transaction_date)
|
||||||
|
: "No date"}
|
||||||
|
{transaction.booking_date &&
|
||||||
|
transaction.booking_date !== transaction.transaction_date && (
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Booked: {formatDate(transaction.booking_date)}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
sortingFn: "datetime",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
header: "",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const transaction = row.original;
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
onClick={() => handleViewRaw(transaction)}
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
title="View raw transaction data"
|
||||||
|
>
|
||||||
|
<Eye className="h-3 w-3 mr-1" />
|
||||||
|
Raw
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data: transactions,
|
||||||
|
columns,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
state: {
|
||||||
|
sorting,
|
||||||
|
columnFilters,
|
||||||
|
globalFilter: filterState.searchTerm,
|
||||||
|
},
|
||||||
|
onGlobalFilterChange: (value: string) =>
|
||||||
|
handleFilterChange("searchTerm", value),
|
||||||
|
globalFilterFn: (row, _columnId, filterValue) => {
|
||||||
|
// Custom global filter that searches multiple fields
|
||||||
|
const transaction = row.original;
|
||||||
|
const searchLower = filterValue.toLowerCase();
|
||||||
|
|
||||||
|
const description = transaction.description || "";
|
||||||
|
const creditorName = transaction.creditor_name || "";
|
||||||
|
const debtorName = transaction.debtor_name || "";
|
||||||
|
const reference = transaction.reference || "";
|
||||||
|
|
||||||
|
return (
|
||||||
|
description.toLowerCase().includes(searchLower) ||
|
||||||
|
creditorName.toLowerCase().includes(searchLower) ||
|
||||||
|
debtorName.toLowerCase().includes(searchLower) ||
|
||||||
|
reference.toLowerCase().includes(searchLower)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (transactionsLoading) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<FiltersSkeleton />
|
||||||
|
<TransactionSkeleton rows={10} view="table" />
|
||||||
|
<div className="md:hidden">
|
||||||
|
<TransactionSkeleton rows={10} view="mobile" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transactionsError) {
|
||||||
|
return (
|
||||||
|
<Alert variant="destructive">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<AlertTitle>Failed to load transactions</AlertTitle>
|
||||||
|
<AlertDescription className="space-y-3">
|
||||||
|
<p>Unable to fetch transactions from the Leggen API.</p>
|
||||||
|
<Button
|
||||||
|
onClick={() => refetchTransactions()}
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
<RefreshCw className="h-4 w-4 mr-2" />
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6 max-w-full">
|
||||||
|
{/* New FilterBar */}
|
||||||
|
<FilterBar
|
||||||
|
filterState={filterState}
|
||||||
|
onFilterChange={handleFilterChange}
|
||||||
|
onClearFilters={handleClearFilters}
|
||||||
|
accounts={accounts}
|
||||||
|
isSearchLoading={isSearchLoading}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Responsive Table/Cards */}
|
||||||
|
<Card>
|
||||||
|
{/* Desktop Table View (hidden on mobile) */}
|
||||||
|
<div className="hidden md:block">
|
||||||
|
<table className="min-w-full divide-y divide-border">
|
||||||
|
<thead className="bg-muted/50">
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<tr key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => (
|
||||||
|
<th
|
||||||
|
key={header.id}
|
||||||
|
className="px-6 py-3 text-left text-xs font-medium text-muted-foreground uppercase tracking-wider cursor-pointer hover:bg-muted"
|
||||||
|
onClick={header.column.getToggleSortingHandler()}
|
||||||
|
>
|
||||||
|
<div className="flex items-center space-x-1">
|
||||||
|
<span>
|
||||||
|
{header.isPlaceholder
|
||||||
|
? null
|
||||||
|
: flexRender(
|
||||||
|
header.column.columnDef.header,
|
||||||
|
header.getContext(),
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
{header.column.getCanSort() && (
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<ChevronUp
|
||||||
|
className={`h-3 w-3 ${
|
||||||
|
header.column.getIsSorted() === "asc"
|
||||||
|
? "text-primary"
|
||||||
|
: "text-muted-foreground"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
<ChevronDown
|
||||||
|
className={`h-3 w-3 -mt-1 ${
|
||||||
|
header.column.getIsSorted() === "desc"
|
||||||
|
? "text-primary"
|
||||||
|
: "text-muted-foreground"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</thead>
|
||||||
|
<tbody className="bg-card divide-y divide-border">
|
||||||
|
{table.getRowModel().rows.length === 0 ? (
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
colSpan={columns.length}
|
||||||
|
className="px-6 py-12 text-center"
|
||||||
|
>
|
||||||
|
<div className="text-muted-foreground mb-4">
|
||||||
|
<TrendingUp className="h-12 w-12 mx-auto" />
|
||||||
|
</div>
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
No transactions found
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
{hasActiveFilters
|
||||||
|
? "Try adjusting your filters to see more results."
|
||||||
|
: "No transactions are available for the selected criteria."}
|
||||||
|
</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : (
|
||||||
|
table.getRowModel().rows.map((row) => (
|
||||||
|
<tr key={row.id} className="hover:bg-muted/50">
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<td key={cell.id} className="px-6 py-4 whitespace-nowrap">
|
||||||
|
{flexRender(
|
||||||
|
cell.column.columnDef.cell,
|
||||||
|
cell.getContext(),
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Mobile Card View (visible only on mobile) */}
|
||||||
|
<div className="md:hidden">
|
||||||
|
{table.getRowModel().rows.length === 0 ? (
|
||||||
|
<div className="px-6 py-12 text-center">
|
||||||
|
<div className="text-muted-foreground mb-4">
|
||||||
|
<TrendingUp className="h-12 w-12 mx-auto" />
|
||||||
|
</div>
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-2">
|
||||||
|
No transactions found
|
||||||
|
</h3>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
{hasActiveFilters
|
||||||
|
? "Try adjusting your filters to see more results."
|
||||||
|
: "No transactions are available for the selected criteria."}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="divide-y divide-border">
|
||||||
|
{table.getRowModel().rows.map((row) => {
|
||||||
|
const transaction = row.original;
|
||||||
|
const account = accounts?.find(
|
||||||
|
(acc) => acc.id === transaction.account_id,
|
||||||
|
);
|
||||||
|
const isPositive = transaction.transaction_value > 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={row.id}
|
||||||
|
className="p-4 hover:bg-muted/50 transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex items-start justify-between">
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<div className="flex items-start space-x-3">
|
||||||
|
<div
|
||||||
|
className={`p-2 rounded-full flex-shrink-0 ${
|
||||||
|
isPositive ? "bg-green-100" : "bg-red-100"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isPositive ? (
|
||||||
|
<TrendingUp className="h-4 w-4 text-green-600" />
|
||||||
|
) : (
|
||||||
|
<TrendingDown className="h-4 w-4 text-red-600" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<h4 className="text-sm font-medium text-foreground break-words">
|
||||||
|
{transaction.description}
|
||||||
|
</h4>
|
||||||
|
<div className="text-xs text-muted-foreground space-y-1 mt-1">
|
||||||
|
{account && (
|
||||||
|
<p className="break-words">
|
||||||
|
{account.display_name || "Unnamed Account"}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{(transaction.creditor_name ||
|
||||||
|
transaction.debtor_name) && (
|
||||||
|
<p className="break-words">
|
||||||
|
{isPositive ? "From: " : "To: "}
|
||||||
|
{transaction.creditor_name ||
|
||||||
|
transaction.debtor_name}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{transaction.reference && (
|
||||||
|
<p className="break-words">
|
||||||
|
Ref: {transaction.reference}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
{transaction.transaction_date
|
||||||
|
? formatDate(transaction.transaction_date)
|
||||||
|
: "No date"}
|
||||||
|
{transaction.booking_date &&
|
||||||
|
transaction.booking_date !==
|
||||||
|
transaction.transaction_date && (
|
||||||
|
<span className="ml-2">
|
||||||
|
(Booked:{" "}
|
||||||
|
{formatDate(transaction.booking_date)})
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-right ml-3 flex-shrink-0">
|
||||||
|
<p
|
||||||
|
className={`text-lg font-semibold mb-1 ${
|
||||||
|
isPositive ? "text-green-600" : "text-red-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isPositive ? "+" : ""}
|
||||||
|
{formatCurrency(
|
||||||
|
transaction.transaction_value,
|
||||||
|
transaction.transaction_currency,
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
onClick={() => handleViewRaw(transaction)}
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
title="View raw transaction data"
|
||||||
|
>
|
||||||
|
<Eye className="h-3 w-3 mr-1" />
|
||||||
|
Raw
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Pagination */}
|
||||||
|
{pagination && (
|
||||||
|
<DataTablePagination
|
||||||
|
currentPage={pagination.page}
|
||||||
|
totalPages={pagination.total_pages}
|
||||||
|
pageSize={pagination.per_page}
|
||||||
|
total={pagination.total}
|
||||||
|
hasNext={pagination.has_next}
|
||||||
|
hasPrev={pagination.has_prev}
|
||||||
|
onPageChange={setCurrentPage}
|
||||||
|
onPageSizeChange={setPerPage}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Raw Transaction Modal */}
|
||||||
|
<RawTransactionModal
|
||||||
|
isOpen={showRawModal}
|
||||||
|
onClose={handleCloseModal}
|
||||||
|
rawTransaction={selectedTransaction?.raw_transaction}
|
||||||
|
transactionId={selectedTransaction?.transaction_id || "unknown"}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
191
frontend/src/components/analytics/BalanceChart.tsx
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
import {
|
||||||
|
AreaChart,
|
||||||
|
Area,
|
||||||
|
XAxis,
|
||||||
|
YAxis,
|
||||||
|
CartesianGrid,
|
||||||
|
Tooltip,
|
||||||
|
ResponsiveContainer,
|
||||||
|
Legend,
|
||||||
|
} from "recharts";
|
||||||
|
import type { Balance, Account } from "../../types/api";
|
||||||
|
|
||||||
|
interface BalanceChartProps {
|
||||||
|
data: Balance[];
|
||||||
|
accounts: Account[];
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ChartDataPoint {
|
||||||
|
date: string;
|
||||||
|
balance: number;
|
||||||
|
account_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AggregatedDataPoint {
|
||||||
|
date: string;
|
||||||
|
[key: string]: string | number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TooltipProps {
|
||||||
|
active?: boolean;
|
||||||
|
payload?: Array<{
|
||||||
|
name: string;
|
||||||
|
value: number;
|
||||||
|
color: string;
|
||||||
|
}>;
|
||||||
|
label?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function BalanceChart({
|
||||||
|
data,
|
||||||
|
accounts,
|
||||||
|
className,
|
||||||
|
}: BalanceChartProps) {
|
||||||
|
// Create a lookup map for account info
|
||||||
|
const accountMap = accounts.reduce(
|
||||||
|
(map, account) => {
|
||||||
|
map[account.id] = account;
|
||||||
|
return map;
|
||||||
|
},
|
||||||
|
{} as Record<string, Account>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Helper function to get bank name from institution_id
|
||||||
|
const getBankName = (institutionId: string): string => {
|
||||||
|
const bankMapping: Record<string, string> = {
|
||||||
|
REVOLUT_REVOLT21: "Revolut",
|
||||||
|
NUBANK_NUPBBR25: "Nu Pagamentos",
|
||||||
|
BANCOBPI_BBPIPTPL: "Banco BPI",
|
||||||
|
// Add more mappings as needed
|
||||||
|
};
|
||||||
|
return bankMapping[institutionId] || institutionId.split("_")[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper function to create display name for account
|
||||||
|
const getAccountDisplayName = (accountId: string): string => {
|
||||||
|
const account = accountMap[accountId];
|
||||||
|
if (account) {
|
||||||
|
const bankName = getBankName(account.institution_id);
|
||||||
|
const accountName = account.name || `Account ${accountId.split("-")[1]}`;
|
||||||
|
return `${bankName} - ${accountName}`;
|
||||||
|
}
|
||||||
|
return `Account ${accountId.split("-")[1]}`;
|
||||||
|
};
|
||||||
|
// Process balance data for the chart
|
||||||
|
const chartData = data
|
||||||
|
.filter((balance) => balance.balance_type === "closingBooked")
|
||||||
|
.map((balance) => ({
|
||||||
|
date: new Date(balance.reference_date).toLocaleDateString("en-GB"), // DD/MM/YYYY format
|
||||||
|
balance: balance.balance_amount,
|
||||||
|
account_id: balance.account_id,
|
||||||
|
}))
|
||||||
|
.sort(
|
||||||
|
(a, b) =>
|
||||||
|
new Date(a.date.split("/").reverse().join("/")).getTime() -
|
||||||
|
new Date(b.date.split("/").reverse().join("/")).getTime(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Group by account and aggregate
|
||||||
|
const accountBalances: { [key: string]: ChartDataPoint[] } = {};
|
||||||
|
chartData.forEach((item) => {
|
||||||
|
if (!accountBalances[item.account_id]) {
|
||||||
|
accountBalances[item.account_id] = [];
|
||||||
|
}
|
||||||
|
accountBalances[item.account_id].push(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create aggregated data points
|
||||||
|
const aggregatedData: { [key: string]: AggregatedDataPoint } = {};
|
||||||
|
Object.entries(accountBalances).forEach(([accountId, balances]) => {
|
||||||
|
balances.forEach((balance) => {
|
||||||
|
if (!aggregatedData[balance.date]) {
|
||||||
|
aggregatedData[balance.date] = { date: balance.date };
|
||||||
|
}
|
||||||
|
aggregatedData[balance.date][accountId] = balance.balance;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const finalData = Object.values(aggregatedData).sort(
|
||||||
|
(a, b) =>
|
||||||
|
new Date(a.date.split("/").reverse().join("/")).getTime() -
|
||||||
|
new Date(b.date.split("/").reverse().join("/")).getTime(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const colors = ["#3B82F6", "#10B981", "#F59E0B", "#EF4444", "#8B5CF6"];
|
||||||
|
|
||||||
|
const CustomTooltip = ({ active, payload, label }: TooltipProps) => {
|
||||||
|
if (active && payload && payload.length) {
|
||||||
|
return (
|
||||||
|
<div className="bg-card p-3 border rounded shadow-lg">
|
||||||
|
<p className="font-medium text-foreground">Date: {label}</p>
|
||||||
|
{payload.map((entry, index) => (
|
||||||
|
<p key={index} style={{ color: entry.color }}>
|
||||||
|
{getAccountDisplayName(entry.name)}: €
|
||||||
|
{entry.value.toLocaleString()}
|
||||||
|
</p>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (finalData.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className={className}>
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-4">
|
||||||
|
Balance Progress
|
||||||
|
</h3>
|
||||||
|
<div className="h-80 flex items-center justify-center text-muted-foreground">
|
||||||
|
No balance data available
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={className}>
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-4">
|
||||||
|
Balance Progress Over Time
|
||||||
|
</h3>
|
||||||
|
<div className="h-80">
|
||||||
|
<ResponsiveContainer width="100%" height="100%">
|
||||||
|
<AreaChart data={finalData}>
|
||||||
|
<CartesianGrid strokeDasharray="3 3" />
|
||||||
|
<XAxis
|
||||||
|
dataKey="date"
|
||||||
|
tick={{ fontSize: 12 }}
|
||||||
|
tickFormatter={(value) => {
|
||||||
|
// Convert DD/MM/YYYY back to a proper date for formatting
|
||||||
|
const [day, month, year] = value.split("/");
|
||||||
|
const date = new Date(year, month - 1, day);
|
||||||
|
return date.toLocaleDateString("en-GB", {
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<YAxis
|
||||||
|
tick={{ fontSize: 12 }}
|
||||||
|
tickFormatter={(value) => `€${value.toLocaleString()}`}
|
||||||
|
/>
|
||||||
|
<Tooltip content={<CustomTooltip />} />
|
||||||
|
<Legend />
|
||||||
|
{Object.keys(accountBalances).map((accountId, index) => (
|
||||||
|
<Area
|
||||||
|
key={accountId}
|
||||||
|
type="monotone"
|
||||||
|
dataKey={accountId}
|
||||||
|
stackId="1"
|
||||||
|
fill={colors[index % colors.length]}
|
||||||
|
stroke={colors[index % colors.length]}
|
||||||
|
name={getAccountDisplayName(accountId)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</AreaChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
142
frontend/src/components/analytics/MonthlyTrends.tsx
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
import {
|
||||||
|
BarChart,
|
||||||
|
Bar,
|
||||||
|
XAxis,
|
||||||
|
YAxis,
|
||||||
|
CartesianGrid,
|
||||||
|
Tooltip,
|
||||||
|
ResponsiveContainer,
|
||||||
|
} from "recharts";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import apiClient from "../../lib/api";
|
||||||
|
|
||||||
|
interface MonthlyTrendsProps {
|
||||||
|
className?: string;
|
||||||
|
days?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TooltipProps {
|
||||||
|
active?: boolean;
|
||||||
|
payload?: Array<{
|
||||||
|
name: string;
|
||||||
|
value: number;
|
||||||
|
color: string;
|
||||||
|
}>;
|
||||||
|
label?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function MonthlyTrends({
|
||||||
|
className,
|
||||||
|
days = 365,
|
||||||
|
}: MonthlyTrendsProps) {
|
||||||
|
// Get pre-calculated monthly stats from the new endpoint
|
||||||
|
const { data: monthlyData, isLoading } = useQuery({
|
||||||
|
queryKey: ["monthly-stats", days],
|
||||||
|
queryFn: async () => {
|
||||||
|
return await apiClient.getMonthlyTransactionStats(days);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Calculate number of months to display based on days filter
|
||||||
|
const getMonthsToDisplay = (days: number): number => {
|
||||||
|
if (days <= 30) return 1;
|
||||||
|
if (days <= 180) return 6;
|
||||||
|
if (days <= 365) return 12;
|
||||||
|
return Math.ceil(days / 30);
|
||||||
|
};
|
||||||
|
|
||||||
|
const monthsToDisplay = getMonthsToDisplay(days);
|
||||||
|
const displayData = monthlyData ? monthlyData.slice(-monthsToDisplay) : [];
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className={className}>
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-4">
|
||||||
|
Monthly Spending Trends
|
||||||
|
</h3>
|
||||||
|
<div className="h-80 flex items-center justify-center">
|
||||||
|
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (displayData.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className={className}>
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-4">
|
||||||
|
Monthly Spending Trends
|
||||||
|
</h3>
|
||||||
|
<div className="h-80 flex items-center justify-center text-muted-foreground">
|
||||||
|
No transaction data available
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const CustomTooltip = ({ active, payload, label }: TooltipProps) => {
|
||||||
|
if (active && payload && payload.length) {
|
||||||
|
return (
|
||||||
|
<div className="bg-card p-3 border rounded shadow-lg">
|
||||||
|
<p className="font-medium text-foreground">{label}</p>
|
||||||
|
{payload.map((entry, index) => (
|
||||||
|
<p key={index} style={{ color: entry.color }}>
|
||||||
|
{entry.name}: €{Math.abs(entry.value).toLocaleString()}
|
||||||
|
</p>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Generate dynamic title based on time period
|
||||||
|
const getTitle = (days: number): string => {
|
||||||
|
if (days <= 30) return "Monthly Spending Trends (Last 30 Days)";
|
||||||
|
if (days <= 180) return "Monthly Spending Trends (Last 6 Months)";
|
||||||
|
if (days <= 365) return "Monthly Spending Trends (Last 12 Months)";
|
||||||
|
return `Monthly Spending Trends (Last ${Math.ceil(days / 30)} Months)`;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={className}>
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-4">
|
||||||
|
{getTitle(days)}
|
||||||
|
</h3>
|
||||||
|
<div className="h-80">
|
||||||
|
<ResponsiveContainer width="100%" height="100%">
|
||||||
|
<BarChart
|
||||||
|
data={displayData}
|
||||||
|
margin={{ top: 20, right: 30, left: 20, bottom: 5 }}
|
||||||
|
>
|
||||||
|
<CartesianGrid strokeDasharray="3 3" />
|
||||||
|
<XAxis
|
||||||
|
dataKey="month"
|
||||||
|
tick={{ fontSize: 12 }}
|
||||||
|
angle={-45}
|
||||||
|
textAnchor="end"
|
||||||
|
height={60}
|
||||||
|
/>
|
||||||
|
<YAxis
|
||||||
|
tick={{ fontSize: 12 }}
|
||||||
|
tickFormatter={(value) => `€${value.toLocaleString()}`}
|
||||||
|
/>
|
||||||
|
<Tooltip content={<CustomTooltip />} />
|
||||||
|
<Bar dataKey="income" fill="#10B981" name="Income" />
|
||||||
|
<Bar dataKey="expenses" fill="#EF4444" name="Expenses" />
|
||||||
|
</BarChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
</div>
|
||||||
|
<div className="mt-4 flex justify-center space-x-6 text-sm text-foreground">
|
||||||
|
<div className="flex items-center">
|
||||||
|
<div className="w-3 h-3 bg-green-500 rounded mr-2" />
|
||||||
|
<span>Income</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<div className="w-3 h-3 bg-red-500 rounded mr-2" />
|
||||||
|
<span>Expenses</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
80
frontend/src/components/analytics/StatCard.tsx
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import type { LucideIcon } from "lucide-react";
|
||||||
|
import { Card, CardContent } from "../ui/card";
|
||||||
|
import { cn } from "../../lib/utils";
|
||||||
|
|
||||||
|
interface StatCardProps {
|
||||||
|
title: string;
|
||||||
|
value: string | number;
|
||||||
|
subtitle?: string;
|
||||||
|
icon: LucideIcon;
|
||||||
|
trend?: {
|
||||||
|
value: number;
|
||||||
|
isPositive: boolean;
|
||||||
|
};
|
||||||
|
className?: string;
|
||||||
|
iconColor?: "green" | "blue" | "red" | "purple" | "orange" | "default";
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function StatCard({
|
||||||
|
title,
|
||||||
|
value,
|
||||||
|
subtitle,
|
||||||
|
icon: Icon,
|
||||||
|
trend,
|
||||||
|
className,
|
||||||
|
iconColor = "default",
|
||||||
|
}: StatCardProps) {
|
||||||
|
return (
|
||||||
|
<Card className={cn(className)}>
|
||||||
|
<CardContent className="p-6">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium text-muted-foreground">{title}</p>
|
||||||
|
<div className="flex items-baseline">
|
||||||
|
<p className="text-2xl font-bold text-foreground">{value}</p>
|
||||||
|
{trend && (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"ml-2 flex items-baseline text-sm font-semibold",
|
||||||
|
trend.isPositive
|
||||||
|
? "text-green-600 dark:text-green-400"
|
||||||
|
: "text-red-600 dark:text-red-400",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{trend.isPositive ? "+" : ""}
|
||||||
|
{trend.value}%
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{subtitle && (
|
||||||
|
<p className="text-sm text-muted-foreground mt-1">{subtitle}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"p-3 rounded-full",
|
||||||
|
iconColor === "green" && "bg-green-100 dark:bg-green-900/20",
|
||||||
|
iconColor === "blue" && "bg-blue-100 dark:bg-blue-900/20",
|
||||||
|
iconColor === "red" && "bg-red-100 dark:bg-red-900/20",
|
||||||
|
iconColor === "purple" && "bg-purple-100 dark:bg-purple-900/20",
|
||||||
|
iconColor === "orange" && "bg-orange-100 dark:bg-orange-900/20",
|
||||||
|
iconColor === "default" && "bg-muted",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
className={cn(
|
||||||
|
"h-6 w-6",
|
||||||
|
iconColor === "green" && "text-green-600",
|
||||||
|
iconColor === "blue" && "text-blue-600",
|
||||||
|
iconColor === "red" && "text-red-600",
|
||||||
|
iconColor === "purple" && "text-purple-600",
|
||||||
|
iconColor === "orange" && "text-orange-600",
|
||||||
|
iconColor === "default" && "text-muted-foreground",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
41
frontend/src/components/analytics/TimePeriodFilter.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { Calendar } from "lucide-react";
|
||||||
|
import { Button } from "../ui/button";
|
||||||
|
import type { TimePeriod } from "../../lib/timePeriods";
|
||||||
|
import { TIME_PERIODS } from "../../lib/timePeriods";
|
||||||
|
|
||||||
|
interface TimePeriodFilterProps {
|
||||||
|
selectedPeriod: TimePeriod;
|
||||||
|
onPeriodChange: (period: TimePeriod) => void;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TimePeriodFilter({
|
||||||
|
selectedPeriod,
|
||||||
|
onPeriodChange,
|
||||||
|
className = "",
|
||||||
|
}: TimePeriodFilterProps) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`flex flex-col sm:flex-row sm:items-center gap-4 ${className}`}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-2 text-foreground">
|
||||||
|
<Calendar size={20} />
|
||||||
|
<span className="font-medium">Time Period:</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
{TIME_PERIODS.map((period) => (
|
||||||
|
<Button
|
||||||
|
key={period.value}
|
||||||
|
onClick={() => onPeriodChange(period)}
|
||||||
|
variant={
|
||||||
|
selectedPeriod.value === period.value ? "default" : "outline"
|
||||||
|
}
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
{period.label}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
148
frontend/src/components/analytics/TransactionDistribution.tsx
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
import {
|
||||||
|
PieChart,
|
||||||
|
Pie,
|
||||||
|
Cell,
|
||||||
|
ResponsiveContainer,
|
||||||
|
Tooltip,
|
||||||
|
Legend,
|
||||||
|
} from "recharts";
|
||||||
|
import type { Account } from "../../types/api";
|
||||||
|
|
||||||
|
interface TransactionDistributionProps {
|
||||||
|
accounts: Account[];
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PieDataPoint {
|
||||||
|
name: string;
|
||||||
|
value: number;
|
||||||
|
color: string;
|
||||||
|
[key: string]: string | number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TooltipProps {
|
||||||
|
active?: boolean;
|
||||||
|
payload?: Array<{
|
||||||
|
payload: PieDataPoint;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TransactionDistribution({
|
||||||
|
accounts,
|
||||||
|
className,
|
||||||
|
}: TransactionDistributionProps) {
|
||||||
|
// Helper function to get bank name from institution_id
|
||||||
|
const getBankName = (institutionId: string): string => {
|
||||||
|
const bankMapping: Record<string, string> = {
|
||||||
|
REVOLUT_REVOLT21: "Revolut",
|
||||||
|
NUBANK_NUPBBR25: "Nu Pagamentos",
|
||||||
|
BANCOBPI_BBPIPTPL: "Banco BPI",
|
||||||
|
// TODO: Add more bank mappings as needed
|
||||||
|
};
|
||||||
|
return bankMapping[institutionId] || institutionId.split("_")[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper function to create display name for account
|
||||||
|
const getAccountDisplayName = (account: Account): string => {
|
||||||
|
const bankName = getBankName(account.institution_id);
|
||||||
|
const accountName = account.name || `Account ${account.id.split("-")[1]}`;
|
||||||
|
return `${bankName} - ${accountName}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create pie chart data from account balances
|
||||||
|
const pieData: PieDataPoint[] = accounts.map((account, index) => {
|
||||||
|
const primaryBalance = account.balances?.[0]?.amount || 0;
|
||||||
|
|
||||||
|
const colors = ["#3B82F6", "#10B981", "#F59E0B", "#EF4444", "#8B5CF6"];
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: getAccountDisplayName(account),
|
||||||
|
value: primaryBalance,
|
||||||
|
color: colors[index % colors.length],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const totalBalance = pieData.reduce((sum, item) => sum + item.value, 0);
|
||||||
|
|
||||||
|
if (pieData.length === 0 || totalBalance === 0) {
|
||||||
|
return (
|
||||||
|
<div className={className}>
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-4">
|
||||||
|
Account Distribution
|
||||||
|
</h3>
|
||||||
|
<div className="h-80 flex items-center justify-center text-muted-foreground">
|
||||||
|
No account data available
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const CustomTooltip = ({ active, payload }: TooltipProps) => {
|
||||||
|
if (active && payload && payload.length) {
|
||||||
|
const data = payload[0].payload;
|
||||||
|
const percentage = ((data.value / totalBalance) * 100).toFixed(1);
|
||||||
|
return (
|
||||||
|
<div className="bg-card p-3 border rounded shadow-lg">
|
||||||
|
<p className="font-medium text-foreground">{data.name}</p>
|
||||||
|
<p className="text-primary">
|
||||||
|
Balance: €{data.value.toLocaleString()}
|
||||||
|
</p>
|
||||||
|
<p className="text-muted-foreground">{percentage}% of total</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={className}>
|
||||||
|
<h3 className="text-lg font-medium text-foreground mb-4">
|
||||||
|
Account Balance Distribution
|
||||||
|
</h3>
|
||||||
|
<div className="h-80">
|
||||||
|
<ResponsiveContainer width="100%" height="100%">
|
||||||
|
<PieChart>
|
||||||
|
<Pie
|
||||||
|
data={pieData}
|
||||||
|
cx="50%"
|
||||||
|
cy="50%"
|
||||||
|
outerRadius={100}
|
||||||
|
innerRadius={40}
|
||||||
|
paddingAngle={2}
|
||||||
|
dataKey="value"
|
||||||
|
>
|
||||||
|
{pieData.map((entry, index) => (
|
||||||
|
<Cell key={`cell-${index}`} fill={entry.color} />
|
||||||
|
))}
|
||||||
|
</Pie>
|
||||||
|
<Tooltip content={<CustomTooltip />} />
|
||||||
|
<Legend
|
||||||
|
formatter={(value, entry: { color?: string }) => (
|
||||||
|
<span style={{ color: entry.color }}>{value}</span>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</PieChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
</div>
|
||||||
|
<div className="mt-4 grid grid-cols-1 gap-2">
|
||||||
|
{pieData.map((item, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="flex items-center justify-between text-sm"
|
||||||
|
>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<div
|
||||||
|
className="w-3 h-3 rounded-full mr-2"
|
||||||
|
style={{ backgroundColor: item.color }}
|
||||||
|
/>
|
||||||
|
<span className="text-foreground">{item.name}</span>
|
||||||
|
</div>
|
||||||
|
<span className="font-medium text-foreground">
|
||||||
|
€{item.value.toLocaleString()}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
127
frontend/src/components/filters/AccountCombobox.tsx
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { Check, ChevronDown, Building2 } from "lucide-react";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
CommandEmpty,
|
||||||
|
CommandGroup,
|
||||||
|
CommandInput,
|
||||||
|
CommandItem,
|
||||||
|
CommandList,
|
||||||
|
} from "@/components/ui/command";
|
||||||
|
import {
|
||||||
|
Popover,
|
||||||
|
PopoverContent,
|
||||||
|
PopoverTrigger,
|
||||||
|
} from "@/components/ui/popover";
|
||||||
|
import type { Account } from "../../types/api";
|
||||||
|
|
||||||
|
export interface AccountComboboxProps {
|
||||||
|
accounts?: Account[];
|
||||||
|
selectedAccount: string;
|
||||||
|
onAccountChange: (accountId: string) => void;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AccountCombobox({
|
||||||
|
accounts = [],
|
||||||
|
selectedAccount,
|
||||||
|
onAccountChange,
|
||||||
|
className,
|
||||||
|
}: AccountComboboxProps) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
const selectedAccountData = accounts.find(
|
||||||
|
(account) => account.id === selectedAccount,
|
||||||
|
);
|
||||||
|
|
||||||
|
const formatAccountName = (account: Account) => {
|
||||||
|
const displayName =
|
||||||
|
account.display_name || account.name || "Unnamed Account";
|
||||||
|
return `${displayName} (${account.institution_id})`;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={className}>
|
||||||
|
<Popover open={open} onOpenChange={setOpen}>
|
||||||
|
<PopoverTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
role="combobox"
|
||||||
|
aria-expanded={open}
|
||||||
|
className="w-full justify-between"
|
||||||
|
>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<Building2 className="mr-2 h-4 w-4" />
|
||||||
|
{selectedAccountData
|
||||||
|
? formatAccountName(selectedAccountData)
|
||||||
|
: "All accounts"}
|
||||||
|
</div>
|
||||||
|
<ChevronDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent className="w-[300px] p-0">
|
||||||
|
<Command>
|
||||||
|
<CommandInput placeholder="Search accounts..." className="h-9" />
|
||||||
|
<CommandList>
|
||||||
|
<CommandEmpty>No accounts found.</CommandEmpty>
|
||||||
|
<CommandGroup>
|
||||||
|
{/* All accounts option */}
|
||||||
|
<CommandItem
|
||||||
|
value="all-accounts"
|
||||||
|
onSelect={() => {
|
||||||
|
onAccountChange("");
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Check
|
||||||
|
className={cn(
|
||||||
|
"mr-2 h-4 w-4",
|
||||||
|
selectedAccount === "" ? "opacity-100" : "opacity-0",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Building2 className="mr-2 h-4 w-4 text-gray-400" />
|
||||||
|
All accounts
|
||||||
|
</CommandItem>
|
||||||
|
|
||||||
|
{/* Individual accounts */}
|
||||||
|
{accounts.map((account) => (
|
||||||
|
<CommandItem
|
||||||
|
key={account.id}
|
||||||
|
value={`${account.display_name || account.name} ${account.institution_id}`}
|
||||||
|
onSelect={() => {
|
||||||
|
onAccountChange(account.id);
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Check
|
||||||
|
className={cn(
|
||||||
|
"mr-2 h-4 w-4",
|
||||||
|
selectedAccount === account.id
|
||||||
|
? "opacity-100"
|
||||||
|
: "opacity-0",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<span className="font-medium">
|
||||||
|
{account.display_name ||
|
||||||
|
account.name ||
|
||||||
|
"Unnamed Account"}
|
||||||
|
</span>
|
||||||
|
<span className="text-xs text-gray-500">
|
||||||
|
{account.institution_id}
|
||||||
|
{account.iban && ` • ${account.iban.slice(-4)}`}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</CommandItem>
|
||||||
|
))}
|
||||||
|
</CommandGroup>
|
||||||
|
</CommandList>
|
||||||
|
</Command>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
121
frontend/src/components/filters/ActiveFilterChips.tsx
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
import { X } from "lucide-react";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { formatDate } from "@/lib/utils";
|
||||||
|
import type { FilterState } from "./FilterBar";
|
||||||
|
import type { Account } from "../../types/api";
|
||||||
|
|
||||||
|
export interface ActiveFilterChipsProps {
|
||||||
|
filterState: FilterState;
|
||||||
|
onFilterChange: (key: keyof FilterState, value: string) => void;
|
||||||
|
onClearFilters: () => void;
|
||||||
|
accounts?: Account[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ActiveFilterChips({
|
||||||
|
filterState,
|
||||||
|
onFilterChange,
|
||||||
|
onClearFilters,
|
||||||
|
accounts = [],
|
||||||
|
}: ActiveFilterChipsProps) {
|
||||||
|
const chips: Array<{
|
||||||
|
key: keyof FilterState;
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
// Search term chip
|
||||||
|
if (filterState.searchTerm) {
|
||||||
|
chips.push({
|
||||||
|
key: "searchTerm",
|
||||||
|
label: `Search: "${filterState.searchTerm}"`,
|
||||||
|
value: filterState.searchTerm,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Account chip
|
||||||
|
if (filterState.selectedAccount) {
|
||||||
|
const account = accounts.find(
|
||||||
|
(acc) => acc.id === filterState.selectedAccount,
|
||||||
|
);
|
||||||
|
const accountName = account
|
||||||
|
? `${account.name || "Unnamed Account"} (${account.institution_id})`
|
||||||
|
: "Unknown Account";
|
||||||
|
chips.push({
|
||||||
|
key: "selectedAccount",
|
||||||
|
label: accountName,
|
||||||
|
value: filterState.selectedAccount,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Date range chip
|
||||||
|
if (filterState.startDate || filterState.endDate) {
|
||||||
|
let dateLabel = "Date: ";
|
||||||
|
if (filterState.startDate && filterState.endDate) {
|
||||||
|
if (filterState.startDate === filterState.endDate) {
|
||||||
|
dateLabel += formatDate(filterState.startDate);
|
||||||
|
} else {
|
||||||
|
dateLabel += `${formatDate(filterState.startDate)} - ${formatDate(filterState.endDate)}`;
|
||||||
|
}
|
||||||
|
} else if (filterState.startDate) {
|
||||||
|
dateLabel += `From ${formatDate(filterState.startDate)}`;
|
||||||
|
} else if (filterState.endDate) {
|
||||||
|
dateLabel += `Until ${formatDate(filterState.endDate)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
chips.push({
|
||||||
|
key: "startDate", // We'll clear both start and end date when removing this chip
|
||||||
|
label: dateLabel,
|
||||||
|
value: `${filterState.startDate}-${filterState.endDate}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRemoveChip = (key: keyof FilterState) => {
|
||||||
|
switch (key) {
|
||||||
|
case "startDate":
|
||||||
|
// Clear both start and end date
|
||||||
|
onFilterChange("startDate", "");
|
||||||
|
onFilterChange("endDate", "");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
onFilterChange(key, "");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (chips.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
|
<span className="text-sm text-gray-600 font-medium">Active filters:</span>
|
||||||
|
{chips.map((chip) => (
|
||||||
|
<Badge
|
||||||
|
key={`${chip.key}-${chip.value}`}
|
||||||
|
variant="secondary"
|
||||||
|
className="pl-3 pr-1 py-1 bg-blue-50 text-blue-700 border-blue-200 hover:bg-blue-100"
|
||||||
|
>
|
||||||
|
<span className="mr-1 text-xs">{chip.label}</span>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
className="h-4 w-4 p-0 hover:bg-blue-200/50"
|
||||||
|
onClick={() => handleRemoveChip(chip.key)}
|
||||||
|
>
|
||||||
|
<X className="h-3 w-3" />
|
||||||
|
<span className="sr-only">Remove {chip.label} filter</span>
|
||||||
|
</Button>
|
||||||
|
</Badge>
|
||||||
|
))}
|
||||||
|
<Button
|
||||||
|
onClick={onClearFilters}
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="text-muted-foreground ml-2"
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4 mr-1" />
|
||||||
|
Clear All
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
199
frontend/src/components/filters/DateRangePicker.tsx
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { format } from "date-fns";
|
||||||
|
import { Calendar as CalendarIcon, ChevronDown } from "lucide-react";
|
||||||
|
import type { DateRange } from "react-day-picker";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Calendar } from "@/components/ui/calendar";
|
||||||
|
import { Card, CardContent, CardFooter } from "@/components/ui/card";
|
||||||
|
import {
|
||||||
|
Popover,
|
||||||
|
PopoverContent,
|
||||||
|
PopoverTrigger,
|
||||||
|
} from "@/components/ui/popover";
|
||||||
|
|
||||||
|
export interface DateRangePickerProps {
|
||||||
|
startDate: string;
|
||||||
|
endDate: string;
|
||||||
|
onDateRangeChange: (startDate: string, endDate: string) => void;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DatePreset {
|
||||||
|
label: string;
|
||||||
|
getValue: () => { startDate: string; endDate: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
const datePresets: DatePreset[] = [
|
||||||
|
{
|
||||||
|
label: "Today",
|
||||||
|
getValue: () => {
|
||||||
|
const today = new Date();
|
||||||
|
return {
|
||||||
|
startDate: today.toISOString().split("T")[0],
|
||||||
|
endDate: today.toISOString().split("T")[0],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Yesterday",
|
||||||
|
getValue: () => {
|
||||||
|
const yesterday = new Date();
|
||||||
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
|
return {
|
||||||
|
startDate: yesterday.toISOString().split("T")[0],
|
||||||
|
endDate: yesterday.toISOString().split("T")[0],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Last 7 days",
|
||||||
|
getValue: () => {
|
||||||
|
const endDate = new Date();
|
||||||
|
const startDate = new Date();
|
||||||
|
startDate.setDate(endDate.getDate() - 6);
|
||||||
|
return {
|
||||||
|
startDate: startDate.toISOString().split("T")[0],
|
||||||
|
endDate: endDate.toISOString().split("T")[0],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Last 30 days",
|
||||||
|
getValue: () => {
|
||||||
|
const endDate = new Date();
|
||||||
|
const startDate = new Date();
|
||||||
|
startDate.setDate(endDate.getDate() - 29);
|
||||||
|
return {
|
||||||
|
startDate: startDate.toISOString().split("T")[0],
|
||||||
|
endDate: endDate.toISOString().split("T")[0],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "This month",
|
||||||
|
getValue: () => {
|
||||||
|
const now = new Date();
|
||||||
|
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||||
|
const endOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0);
|
||||||
|
|
||||||
|
return {
|
||||||
|
startDate: startOfMonth.toISOString().split("T")[0],
|
||||||
|
endDate: endOfMonth.toISOString().split("T")[0],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export function DateRangePicker({
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
onDateRangeChange,
|
||||||
|
className,
|
||||||
|
}: DateRangePickerProps) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
// Convert string dates to Date objects for the calendar
|
||||||
|
const dateRange: DateRange | undefined =
|
||||||
|
startDate && endDate
|
||||||
|
? {
|
||||||
|
from: new Date(startDate),
|
||||||
|
to: new Date(endDate),
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const handleDateRangeSelect = (range: DateRange | undefined) => {
|
||||||
|
if (range?.from && range?.to) {
|
||||||
|
onDateRangeChange(
|
||||||
|
range.from.toISOString().split("T")[0],
|
||||||
|
range.to.toISOString().split("T")[0],
|
||||||
|
);
|
||||||
|
} else if (range?.from && !range?.to) {
|
||||||
|
onDateRangeChange(
|
||||||
|
range.from.toISOString().split("T")[0],
|
||||||
|
range.from.toISOString().split("T")[0],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePresetClick = (preset: DatePreset) => {
|
||||||
|
const { startDate: presetStart, endDate: presetEnd } = preset.getValue();
|
||||||
|
onDateRangeChange(presetStart, presetEnd);
|
||||||
|
setOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDateRange = () => {
|
||||||
|
if (!startDate || !endDate) {
|
||||||
|
return "Select date range";
|
||||||
|
}
|
||||||
|
|
||||||
|
const start = new Date(startDate);
|
||||||
|
const end = new Date(endDate);
|
||||||
|
|
||||||
|
// Check if it matches a preset
|
||||||
|
const matchingPreset = datePresets.find((preset) => {
|
||||||
|
const { startDate: presetStart, endDate: presetEnd } = preset.getValue();
|
||||||
|
return presetStart === startDate && presetEnd === endDate;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (matchingPreset) {
|
||||||
|
return matchingPreset.label;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format custom range
|
||||||
|
if (startDate === endDate) {
|
||||||
|
return format(start, "MMM d, yyyy");
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${format(start, "MMM d")} - ${format(end, "MMM d, yyyy")}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cn("grid gap-2", className)}>
|
||||||
|
<Popover open={open} onOpenChange={setOpen}>
|
||||||
|
<PopoverTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className={cn(
|
||||||
|
"justify-between text-left font-normal",
|
||||||
|
!dateRange && "text-muted-foreground",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<CalendarIcon className="mr-2 h-4 w-4" />
|
||||||
|
{formatDateRange()}
|
||||||
|
</div>
|
||||||
|
<ChevronDown className="h-4 w-4 opacity-50" />
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent className="w-auto p-0" align="start">
|
||||||
|
<Card className="w-auto py-4">
|
||||||
|
<CardContent className="px-4">
|
||||||
|
<Calendar
|
||||||
|
mode="range"
|
||||||
|
defaultMonth={dateRange?.from}
|
||||||
|
selected={dateRange}
|
||||||
|
onSelect={handleDateRangeSelect}
|
||||||
|
className="bg-transparent p-0"
|
||||||
|
/>
|
||||||
|
</CardContent>
|
||||||
|
<CardFooter className="grid grid-cols-2 gap-1 border-t px-4 !pt-4">
|
||||||
|
{datePresets.map((preset) => (
|
||||||
|
<Button
|
||||||
|
key={preset.label}
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="text-xs px-2 h-7"
|
||||||
|
onClick={() => handlePresetClick(preset)}
|
||||||
|
>
|
||||||
|
{preset.label}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
146
frontend/src/components/filters/FilterBar.tsx
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
import { Search } from "lucide-react";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { DateRangePicker } from "./DateRangePicker";
|
||||||
|
import { AccountCombobox } from "./AccountCombobox";
|
||||||
|
import { ActiveFilterChips } from "./ActiveFilterChips";
|
||||||
|
import type { Account } from "../../types/api";
|
||||||
|
|
||||||
|
export interface FilterState {
|
||||||
|
searchTerm: string;
|
||||||
|
selectedAccount: string;
|
||||||
|
startDate: string;
|
||||||
|
endDate: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FilterBarProps {
|
||||||
|
filterState: FilterState;
|
||||||
|
onFilterChange: (key: keyof FilterState, value: string) => void;
|
||||||
|
onClearFilters: () => void;
|
||||||
|
accounts?: Account[];
|
||||||
|
isSearchLoading?: boolean;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FilterBar({
|
||||||
|
filterState,
|
||||||
|
onFilterChange,
|
||||||
|
onClearFilters,
|
||||||
|
accounts,
|
||||||
|
isSearchLoading = false,
|
||||||
|
className,
|
||||||
|
}: FilterBarProps) {
|
||||||
|
const hasActiveFilters =
|
||||||
|
filterState.searchTerm ||
|
||||||
|
filterState.selectedAccount ||
|
||||||
|
filterState.startDate ||
|
||||||
|
filterState.endDate;
|
||||||
|
|
||||||
|
const handleDateRangeChange = (startDate: string, endDate: string) => {
|
||||||
|
onFilterChange("startDate", startDate);
|
||||||
|
onFilterChange("endDate", endDate);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cn("bg-card rounded-lg shadow border", className)}>
|
||||||
|
{/* Main Filter Bar */}
|
||||||
|
<div className="px-6 py-4">
|
||||||
|
<div className="flex items-center justify-between mb-4">
|
||||||
|
<h3 className="text-lg font-semibold text-card-foreground">
|
||||||
|
Transactions
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Primary Filters Row */}
|
||||||
|
<div className="space-y-4 mb-4">
|
||||||
|
{/* Desktop Layout */}
|
||||||
|
<div className="hidden lg:flex items-center justify-between gap-6">
|
||||||
|
{/* Left Side: Main Filters */}
|
||||||
|
<div className="flex items-center gap-3 flex-1">
|
||||||
|
{/* Search Input */}
|
||||||
|
<div className="relative w-[200px]">
|
||||||
|
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||||
|
<Input
|
||||||
|
placeholder="Search transactions..."
|
||||||
|
value={filterState.searchTerm}
|
||||||
|
onChange={(e) => onFilterChange("searchTerm", e.target.value)}
|
||||||
|
className="pl-9 pr-8 bg-background"
|
||||||
|
/>
|
||||||
|
{isSearchLoading && (
|
||||||
|
<div className="absolute right-3 top-1/2 transform -translate-y-1/2">
|
||||||
|
<div className="animate-spin h-4 w-4 border-2 border-border border-t-primary rounded-full"></div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Account Selection */}
|
||||||
|
<AccountCombobox
|
||||||
|
accounts={accounts}
|
||||||
|
selectedAccount={filterState.selectedAccount}
|
||||||
|
onAccountChange={(accountId) =>
|
||||||
|
onFilterChange("selectedAccount", accountId)
|
||||||
|
}
|
||||||
|
className="w-[180px]"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Date Range Picker */}
|
||||||
|
<DateRangePicker
|
||||||
|
startDate={filterState.startDate}
|
||||||
|
endDate={filterState.endDate}
|
||||||
|
onDateRangeChange={handleDateRangeChange}
|
||||||
|
className="w-[220px]"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Mobile Layout */}
|
||||||
|
<div className="lg:hidden space-y-3">
|
||||||
|
{/* First Row: Search Input (Full Width) */}
|
||||||
|
<div className="relative">
|
||||||
|
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||||
|
<Input
|
||||||
|
placeholder="Search..."
|
||||||
|
value={filterState.searchTerm}
|
||||||
|
onChange={(e) => onFilterChange("searchTerm", e.target.value)}
|
||||||
|
className="pl-9 pr-8 bg-background w-full"
|
||||||
|
/>
|
||||||
|
{isSearchLoading && (
|
||||||
|
<div className="absolute right-3 top-1/2 transform -translate-y-1/2">
|
||||||
|
<div className="animate-spin h-4 w-4 border-2 border-border border-t-primary rounded-full"></div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Second Row: Account Selection (Full Width) */}
|
||||||
|
<AccountCombobox
|
||||||
|
accounts={accounts}
|
||||||
|
selectedAccount={filterState.selectedAccount}
|
||||||
|
onAccountChange={(accountId) =>
|
||||||
|
onFilterChange("selectedAccount", accountId)
|
||||||
|
}
|
||||||
|
className="w-full"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Third Row: Date Range */}
|
||||||
|
<DateRangePicker
|
||||||
|
startDate={filterState.startDate}
|
||||||
|
endDate={filterState.endDate}
|
||||||
|
onDateRangeChange={handleDateRangeChange}
|
||||||
|
className="w-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Active Filter Chips */}
|
||||||
|
{hasActiveFilters && (
|
||||||
|
<ActiveFilterChips
|
||||||
|
filterState={filterState}
|
||||||
|
onFilterChange={onFilterChange}
|
||||||
|
onClearFilters={onClearFilters}
|
||||||
|
accounts={accounts}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
5
frontend/src/components/filters/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export { FilterBar } from "./FilterBar";
|
||||||
|
export { DateRangePicker } from "./DateRangePicker";
|
||||||
|
export { AccountCombobox } from "./AccountCombobox";
|
||||||
|
export { ActiveFilterChips } from "./ActiveFilterChips";
|
||||||
|
export type { FilterState, FilterBarProps } from "./FilterBar";
|
||||||
59
frontend/src/components/ui/alert.tsx
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const alertVariants = cva(
|
||||||
|
"relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "bg-background text-foreground",
|
||||||
|
destructive:
|
||||||
|
"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const Alert = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
|
||||||
|
>(({ className, variant, ...props }, ref) => (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
role="alert"
|
||||||
|
className={cn(alertVariants({ variant }), className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
Alert.displayName = "Alert";
|
||||||
|
|
||||||
|
const AlertTitle = React.forwardRef<
|
||||||
|
HTMLParagraphElement,
|
||||||
|
React.HTMLAttributes<HTMLHeadingElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<h5
|
||||||
|
ref={ref}
|
||||||
|
className={cn("mb-1 font-medium leading-none tracking-tight", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
AlertTitle.displayName = "AlertTitle";
|
||||||
|
|
||||||
|
const AlertDescription = React.forwardRef<
|
||||||
|
HTMLParagraphElement,
|
||||||
|
React.HTMLAttributes<HTMLParagraphElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
className={cn("text-sm [&_p]:leading-relaxed", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
AlertDescription.displayName = "AlertDescription";
|
||||||
|
|
||||||
|
export { Alert, AlertTitle, AlertDescription };
|
||||||
36
frontend/src/components/ui/badge.tsx
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const badgeVariants = cva(
|
||||||
|
"inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default:
|
||||||
|
"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
|
||||||
|
secondary:
|
||||||
|
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||||
|
destructive:
|
||||||
|
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
|
||||||
|
outline: "text-foreground",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export interface BadgeProps
|
||||||
|
extends React.HTMLAttributes<HTMLDivElement>,
|
||||||
|
VariantProps<typeof badgeVariants> {}
|
||||||
|
|
||||||
|
function Badge({ className, variant, ...props }: BadgeProps) {
|
||||||
|
return (
|
||||||
|
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Badge, badgeVariants };
|
||||||
57
frontend/src/components/ui/button.tsx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const buttonVariants = cva(
|
||||||
|
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default:
|
||||||
|
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
||||||
|
destructive:
|
||||||
|
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
||||||
|
outline:
|
||||||
|
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
||||||
|
secondary:
|
||||||
|
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
||||||
|
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||||
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
default: "h-9 px-4 py-2",
|
||||||
|
sm: "h-8 rounded-md px-3 text-xs",
|
||||||
|
lg: "h-10 rounded-md px-8",
|
||||||
|
icon: "h-9 w-9",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export interface ButtonProps
|
||||||
|
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||||
|
VariantProps<typeof buttonVariants> {
|
||||||
|
asChild?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||||
|
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||||
|
const Comp = asChild ? Slot : "button";
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
|
ref={ref}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
Button.displayName = "Button";
|
||||||
|
|
||||||
|
export { Button, buttonVariants };
|
||||||
211
frontend/src/components/ui/calendar.tsx
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import {
|
||||||
|
ChevronDownIcon,
|
||||||
|
ChevronLeftIcon,
|
||||||
|
ChevronRightIcon,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { DayButton, DayPicker, getDefaultClassNames } from "react-day-picker";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Button, buttonVariants } from "@/components/ui/button";
|
||||||
|
|
||||||
|
function Calendar({
|
||||||
|
className,
|
||||||
|
classNames,
|
||||||
|
showOutsideDays = true,
|
||||||
|
captionLayout = "label",
|
||||||
|
buttonVariant = "ghost",
|
||||||
|
formatters,
|
||||||
|
components,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DayPicker> & {
|
||||||
|
buttonVariant?: React.ComponentProps<typeof Button>["variant"];
|
||||||
|
}) {
|
||||||
|
const defaultClassNames = getDefaultClassNames();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DayPicker
|
||||||
|
showOutsideDays={showOutsideDays}
|
||||||
|
className={cn(
|
||||||
|
"bg-background group/calendar p-3 [--cell-size:2rem] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",
|
||||||
|
String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
|
||||||
|
String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
captionLayout={captionLayout}
|
||||||
|
formatters={{
|
||||||
|
formatMonthDropdown: (date) =>
|
||||||
|
date.toLocaleString("default", { month: "short" }),
|
||||||
|
...formatters,
|
||||||
|
}}
|
||||||
|
classNames={{
|
||||||
|
root: cn("w-fit", defaultClassNames.root),
|
||||||
|
months: cn(
|
||||||
|
"relative flex flex-col gap-4 md:flex-row",
|
||||||
|
defaultClassNames.months,
|
||||||
|
),
|
||||||
|
month: cn("flex w-full flex-col gap-4", defaultClassNames.month),
|
||||||
|
nav: cn(
|
||||||
|
"absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",
|
||||||
|
defaultClassNames.nav,
|
||||||
|
),
|
||||||
|
button_previous: cn(
|
||||||
|
buttonVariants({ variant: buttonVariant }),
|
||||||
|
"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",
|
||||||
|
defaultClassNames.button_previous,
|
||||||
|
),
|
||||||
|
button_next: cn(
|
||||||
|
buttonVariants({ variant: buttonVariant }),
|
||||||
|
"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",
|
||||||
|
defaultClassNames.button_next,
|
||||||
|
),
|
||||||
|
month_caption: cn(
|
||||||
|
"flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",
|
||||||
|
defaultClassNames.month_caption,
|
||||||
|
),
|
||||||
|
dropdowns: cn(
|
||||||
|
"flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",
|
||||||
|
defaultClassNames.dropdowns,
|
||||||
|
),
|
||||||
|
dropdown_root: cn(
|
||||||
|
"has-focus:border-ring border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border",
|
||||||
|
defaultClassNames.dropdown_root,
|
||||||
|
),
|
||||||
|
dropdown: cn(
|
||||||
|
"bg-popover absolute inset-0 opacity-0",
|
||||||
|
defaultClassNames.dropdown,
|
||||||
|
),
|
||||||
|
caption_label: cn(
|
||||||
|
"select-none font-medium",
|
||||||
|
captionLayout === "label"
|
||||||
|
? "text-sm"
|
||||||
|
: "[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md pl-2 pr-1 text-sm [&>svg]:size-3.5",
|
||||||
|
defaultClassNames.caption_label,
|
||||||
|
),
|
||||||
|
table: "w-full border-collapse",
|
||||||
|
weekdays: cn("flex", defaultClassNames.weekdays),
|
||||||
|
weekday: cn(
|
||||||
|
"text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",
|
||||||
|
defaultClassNames.weekday,
|
||||||
|
),
|
||||||
|
week: cn("mt-2 flex w-full", defaultClassNames.week),
|
||||||
|
week_number_header: cn(
|
||||||
|
"w-[--cell-size] select-none",
|
||||||
|
defaultClassNames.week_number_header,
|
||||||
|
),
|
||||||
|
week_number: cn(
|
||||||
|
"text-muted-foreground select-none text-[0.8rem]",
|
||||||
|
defaultClassNames.week_number,
|
||||||
|
),
|
||||||
|
day: cn(
|
||||||
|
"group/day relative aspect-square h-full w-full select-none p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md",
|
||||||
|
defaultClassNames.day,
|
||||||
|
),
|
||||||
|
range_start: cn(
|
||||||
|
"bg-accent rounded-l-md",
|
||||||
|
defaultClassNames.range_start,
|
||||||
|
),
|
||||||
|
range_middle: cn("rounded-none", defaultClassNames.range_middle),
|
||||||
|
range_end: cn("bg-accent rounded-r-md", defaultClassNames.range_end),
|
||||||
|
today: cn(
|
||||||
|
"bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",
|
||||||
|
defaultClassNames.today,
|
||||||
|
),
|
||||||
|
outside: cn(
|
||||||
|
"text-muted-foreground aria-selected:text-muted-foreground",
|
||||||
|
defaultClassNames.outside,
|
||||||
|
),
|
||||||
|
disabled: cn(
|
||||||
|
"text-muted-foreground opacity-50",
|
||||||
|
defaultClassNames.disabled,
|
||||||
|
),
|
||||||
|
hidden: cn("invisible", defaultClassNames.hidden),
|
||||||
|
...classNames,
|
||||||
|
}}
|
||||||
|
components={{
|
||||||
|
Root: ({ className, rootRef, ...props }) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="calendar"
|
||||||
|
ref={rootRef}
|
||||||
|
className={cn(className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
Chevron: ({ className, orientation, ...props }) => {
|
||||||
|
if (orientation === "left") {
|
||||||
|
return (
|
||||||
|
<ChevronLeftIcon className={cn("size-4", className)} {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orientation === "right") {
|
||||||
|
return (
|
||||||
|
<ChevronRightIcon
|
||||||
|
className={cn("size-4", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ChevronDownIcon className={cn("size-4", className)} {...props} />
|
||||||
|
);
|
||||||
|
},
|
||||||
|
DayButton: CalendarDayButton,
|
||||||
|
WeekNumber: ({ children, ...props }) => {
|
||||||
|
return (
|
||||||
|
<td {...props}>
|
||||||
|
<div className="flex size-[--cell-size] items-center justify-center text-center">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
...components,
|
||||||
|
}}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CalendarDayButton({
|
||||||
|
className,
|
||||||
|
day,
|
||||||
|
modifiers,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DayButton>) {
|
||||||
|
const defaultClassNames = getDefaultClassNames();
|
||||||
|
|
||||||
|
const ref = React.useRef<HTMLButtonElement>(null);
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (modifiers.focused) ref.current?.focus();
|
||||||
|
}, [modifiers.focused]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
ref={ref}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
data-day={day.date.toLocaleDateString()}
|
||||||
|
data-selected-single={
|
||||||
|
modifiers.selected &&
|
||||||
|
!modifiers.range_start &&
|
||||||
|
!modifiers.range_end &&
|
||||||
|
!modifiers.range_middle
|
||||||
|
}
|
||||||
|
data-range-start={modifiers.range_start}
|
||||||
|
data-range-end={modifiers.range_end}
|
||||||
|
data-range-middle={modifiers.range_middle}
|
||||||
|
className={cn(
|
||||||
|
"data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 flex aspect-square h-auto w-full min-w-[--cell-size] flex-col gap-1 font-normal leading-none data-[range-end=true]:rounded-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] [&>span]:text-xs [&>span]:opacity-70",
|
||||||
|
defaultClassNames.day,
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Calendar, CalendarDayButton };
|
||||||
86
frontend/src/components/ui/card.tsx
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Card = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.HTMLAttributes<HTMLDivElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"rounded-lg border bg-card text-card-foreground shadow-sm",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
Card.displayName = "Card";
|
||||||
|
|
||||||
|
const CardHeader = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.HTMLAttributes<HTMLDivElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
CardHeader.displayName = "CardHeader";
|
||||||
|
|
||||||
|
const CardTitle = React.forwardRef<
|
||||||
|
HTMLParagraphElement,
|
||||||
|
React.HTMLAttributes<HTMLHeadingElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<h3
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"text-2xl font-semibold leading-none tracking-tight",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
CardTitle.displayName = "CardTitle";
|
||||||
|
|
||||||
|
const CardDescription = React.forwardRef<
|
||||||
|
HTMLParagraphElement,
|
||||||
|
React.HTMLAttributes<HTMLParagraphElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<p
|
||||||
|
ref={ref}
|
||||||
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
CardDescription.displayName = "CardDescription";
|
||||||
|
|
||||||
|
const CardContent = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.HTMLAttributes<HTMLDivElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
||||||
|
));
|
||||||
|
CardContent.displayName = "CardContent";
|
||||||
|
|
||||||
|
const CardFooter = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.HTMLAttributes<HTMLDivElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
className={cn("flex items-center p-6 pt-0", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
CardFooter.displayName = "CardFooter";
|
||||||
|
|
||||||
|
export {
|
||||||
|
Card,
|
||||||
|
CardHeader,
|
||||||
|
CardFooter,
|
||||||
|
CardTitle,
|
||||||
|
CardDescription,
|
||||||
|
CardContent,
|
||||||
|
};
|
||||||
153
frontend/src/components/ui/command.tsx
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import * as React from "react";
|
||||||
|
import { type DialogProps } from "@radix-ui/react-dialog";
|
||||||
|
import { Command as CommandPrimitive } from "cmdk";
|
||||||
|
import { Search } from "lucide-react";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Dialog, DialogContent } from "@/components/ui/dialog";
|
||||||
|
|
||||||
|
const Command = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<CommandPrimitive
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
Command.displayName = CommandPrimitive.displayName;
|
||||||
|
|
||||||
|
const CommandDialog = ({ children, ...props }: DialogProps) => {
|
||||||
|
return (
|
||||||
|
<Dialog {...props}>
|
||||||
|
<DialogContent className="overflow-hidden p-0">
|
||||||
|
<Command className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
|
||||||
|
{children}
|
||||||
|
</Command>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const CommandInput = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive.Input>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<div className="flex items-center border-b px-3" cmdk-input-wrapper="">
|
||||||
|
<Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />
|
||||||
|
<CommandPrimitive.Input
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
|
||||||
|
CommandInput.displayName = CommandPrimitive.Input.displayName;
|
||||||
|
|
||||||
|
const CommandList = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive.List>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<CommandPrimitive.List
|
||||||
|
ref={ref}
|
||||||
|
className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
|
||||||
|
CommandList.displayName = CommandPrimitive.List.displayName;
|
||||||
|
|
||||||
|
const CommandEmpty = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive.Empty>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
|
||||||
|
>((props, ref) => (
|
||||||
|
<CommandPrimitive.Empty
|
||||||
|
ref={ref}
|
||||||
|
className="py-6 text-center text-sm"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
|
||||||
|
CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
|
||||||
|
|
||||||
|
const CommandGroup = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive.Group>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<CommandPrimitive.Group
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
|
||||||
|
CommandGroup.displayName = CommandPrimitive.Group.displayName;
|
||||||
|
|
||||||
|
const CommandSeparator = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive.Separator>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<CommandPrimitive.Separator
|
||||||
|
ref={ref}
|
||||||
|
className={cn("-mx-1 h-px bg-border", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
|
||||||
|
|
||||||
|
const CommandItem = React.forwardRef<
|
||||||
|
React.ElementRef<typeof CommandPrimitive.Item>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<CommandPrimitive.Item
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
|
||||||
|
CommandItem.displayName = CommandPrimitive.Item.displayName;
|
||||||
|
|
||||||
|
const CommandShortcut = ({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"ml-auto text-xs tracking-widest text-muted-foreground",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
CommandShortcut.displayName = "CommandShortcut";
|
||||||
|
|
||||||
|
export {
|
||||||
|
Command,
|
||||||
|
CommandDialog,
|
||||||
|
CommandInput,
|
||||||
|
CommandList,
|
||||||
|
CommandEmpty,
|
||||||
|
CommandGroup,
|
||||||
|
CommandItem,
|
||||||
|
CommandShortcut,
|
||||||
|
CommandSeparator,
|
||||||
|
};
|
||||||
137
frontend/src/components/ui/data-table-pagination.tsx
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
import {
|
||||||
|
ChevronLeft,
|
||||||
|
ChevronRight,
|
||||||
|
ChevronsLeft,
|
||||||
|
ChevronsRight,
|
||||||
|
} from "lucide-react";
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select";
|
||||||
|
|
||||||
|
interface DataTablePaginationProps {
|
||||||
|
currentPage: number;
|
||||||
|
totalPages: number;
|
||||||
|
pageSize: number;
|
||||||
|
total: number;
|
||||||
|
hasNext: boolean;
|
||||||
|
hasPrev: boolean;
|
||||||
|
onPageChange: (page: number) => void;
|
||||||
|
onPageSizeChange: (pageSize: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DataTablePagination({
|
||||||
|
currentPage,
|
||||||
|
totalPages,
|
||||||
|
pageSize,
|
||||||
|
total,
|
||||||
|
hasNext,
|
||||||
|
hasPrev,
|
||||||
|
onPageChange,
|
||||||
|
onPageSizeChange,
|
||||||
|
}: DataTablePaginationProps) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-between px-2 py-4">
|
||||||
|
<div className="hidden sm:flex sm:flex-1 sm:items-center sm:justify-between">
|
||||||
|
<div className="flex items-center space-x-6 lg:space-x-8">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<p className="text-sm font-medium text-foreground">Rows per page</p>
|
||||||
|
<Select
|
||||||
|
value={`${pageSize}`}
|
||||||
|
onValueChange={(value) => {
|
||||||
|
onPageSizeChange(Number(value));
|
||||||
|
onPageChange(1); // Reset to first page when changing page size
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="h-8 w-[70px]">
|
||||||
|
<SelectValue placeholder={pageSize} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent side="top">
|
||||||
|
{[10, 25, 50, 100].map((pageSize) => (
|
||||||
|
<SelectItem key={pageSize} value={`${pageSize}`}>
|
||||||
|
{pageSize}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="flex w-[100px] items-center justify-center text-sm font-medium text-foreground">
|
||||||
|
Page {currentPage} of {totalPages}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="hidden h-8 w-8 p-0 lg:flex"
|
||||||
|
onClick={() => onPageChange(1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<span className="sr-only">Go to first page</span>
|
||||||
|
<ChevronsLeft className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="h-8 w-8 p-0"
|
||||||
|
onClick={() => onPageChange(currentPage - 1)}
|
||||||
|
disabled={!hasPrev}
|
||||||
|
>
|
||||||
|
<span className="sr-only">Go to previous page</span>
|
||||||
|
<ChevronLeft className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="h-8 w-8 p-0"
|
||||||
|
onClick={() => onPageChange(currentPage + 1)}
|
||||||
|
disabled={!hasNext}
|
||||||
|
>
|
||||||
|
<span className="sr-only">Go to next page</span>
|
||||||
|
<ChevronRight className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="hidden h-8 w-8 p-0 lg:flex"
|
||||||
|
onClick={() => onPageChange(totalPages)}
|
||||||
|
disabled={currentPage === totalPages}
|
||||||
|
>
|
||||||
|
<span className="sr-only">Go to last page</span>
|
||||||
|
<ChevronsRight className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-sm text-muted-foreground">
|
||||||
|
Showing {(currentPage - 1) * pageSize + 1} to{" "}
|
||||||
|
{Math.min(currentPage * pageSize, total)} of {total} entries
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Mobile view */}
|
||||||
|
<div className="flex w-full items-center justify-between space-x-4 sm:hidden">
|
||||||
|
<div className="text-sm text-muted-foreground">
|
||||||
|
Page {currentPage} of {totalPages}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => onPageChange(currentPage - 1)}
|
||||||
|
disabled={!hasPrev}
|
||||||
|
>
|
||||||
|
Previous
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => onPageChange(currentPage + 1)}
|
||||||
|
disabled={!hasNext}
|
||||||
|
>
|
||||||
|
Next
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
120
frontend/src/components/ui/dialog.tsx
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||||
|
import { X } from "lucide-react";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Dialog = DialogPrimitive.Root;
|
||||||
|
|
||||||
|
const DialogTrigger = DialogPrimitive.Trigger;
|
||||||
|
|
||||||
|
const DialogPortal = DialogPrimitive.Portal;
|
||||||
|
|
||||||
|
const DialogClose = DialogPrimitive.Close;
|
||||||
|
|
||||||
|
const DialogOverlay = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<DialogPrimitive.Overlay
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
||||||
|
|
||||||
|
const DialogContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
||||||
|
>(({ className, children, ...props }, ref) => (
|
||||||
|
<DialogPortal>
|
||||||
|
<DialogOverlay />
|
||||||
|
<DialogPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
<span className="sr-only">Close</span>
|
||||||
|
</DialogPrimitive.Close>
|
||||||
|
</DialogPrimitive.Content>
|
||||||
|
</DialogPortal>
|
||||||
|
));
|
||||||
|
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
||||||
|
|
||||||
|
const DialogHeader = ({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex flex-col space-y-1.5 text-center sm:text-left",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
DialogHeader.displayName = "DialogHeader";
|
||||||
|
|
||||||
|
const DialogFooter = ({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
DialogFooter.displayName = "DialogFooter";
|
||||||
|
|
||||||
|
const DialogTitle = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DialogPrimitive.Title>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<DialogPrimitive.Title
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"text-lg font-semibold leading-none tracking-tight",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
DialogTitle.displayName = DialogPrimitive.Title.displayName;
|
||||||
|
|
||||||
|
const DialogDescription = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DialogPrimitive.Description>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<DialogPrimitive.Description
|
||||||
|
ref={ref}
|
||||||
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
||||||
|
|
||||||
|
export {
|
||||||
|
Dialog,
|
||||||
|
DialogPortal,
|
||||||
|
DialogOverlay,
|
||||||
|
DialogTrigger,
|
||||||
|
DialogClose,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogFooter,
|
||||||
|
DialogTitle,
|
||||||
|
DialogDescription,
|
||||||
|
};
|
||||||
116
frontend/src/components/ui/drawer.tsx
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { Drawer as DrawerPrimitive } from "vaul";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Drawer = ({
|
||||||
|
shouldScaleBackground = true,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DrawerPrimitive.Root>) => (
|
||||||
|
<DrawerPrimitive.Root
|
||||||
|
shouldScaleBackground={shouldScaleBackground}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
Drawer.displayName = "Drawer";
|
||||||
|
|
||||||
|
const DrawerTrigger = DrawerPrimitive.Trigger;
|
||||||
|
|
||||||
|
const DrawerPortal = DrawerPrimitive.Portal;
|
||||||
|
|
||||||
|
const DrawerClose = DrawerPrimitive.Close;
|
||||||
|
|
||||||
|
const DrawerOverlay = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DrawerPrimitive.Overlay>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<DrawerPrimitive.Overlay
|
||||||
|
ref={ref}
|
||||||
|
className={cn("fixed inset-0 z-50 bg-black/80", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName;
|
||||||
|
|
||||||
|
const DrawerContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DrawerPrimitive.Content>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
|
||||||
|
>(({ className, children, ...props }, ref) => (
|
||||||
|
<DrawerPortal>
|
||||||
|
<DrawerOverlay />
|
||||||
|
<DrawerPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" />
|
||||||
|
{children}
|
||||||
|
</DrawerPrimitive.Content>
|
||||||
|
</DrawerPortal>
|
||||||
|
));
|
||||||
|
DrawerContent.displayName = "DrawerContent";
|
||||||
|
|
||||||
|
const DrawerHeader = ({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||||
|
<div
|
||||||
|
className={cn("grid gap-1.5 p-4 text-center sm:text-left", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
DrawerHeader.displayName = "DrawerHeader";
|
||||||
|
|
||||||
|
const DrawerFooter = ({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||||
|
<div
|
||||||
|
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
DrawerFooter.displayName = "DrawerFooter";
|
||||||
|
|
||||||
|
const DrawerTitle = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DrawerPrimitive.Title>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<DrawerPrimitive.Title
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"text-lg font-semibold leading-none tracking-tight",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
DrawerTitle.displayName = DrawerPrimitive.Title.displayName;
|
||||||
|
|
||||||
|
const DrawerDescription = React.forwardRef<
|
||||||
|
React.ElementRef<typeof DrawerPrimitive.Description>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<DrawerPrimitive.Description
|
||||||
|
ref={ref}
|
||||||
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
DrawerDescription.displayName = DrawerPrimitive.Description.displayName;
|
||||||
|
|
||||||
|
export {
|
||||||
|
Drawer,
|
||||||
|
DrawerPortal,
|
||||||
|
DrawerOverlay,
|
||||||
|
DrawerTrigger,
|
||||||
|
DrawerClose,
|
||||||
|
DrawerContent,
|
||||||
|
DrawerHeader,
|
||||||
|
DrawerFooter,
|
||||||
|
DrawerTitle,
|
||||||
|
DrawerDescription,
|
||||||
|
};
|
||||||
45
frontend/src/components/ui/edit-button.tsx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { Edit3 } from "lucide-react";
|
||||||
|
import { Button } from "./button";
|
||||||
|
import { cn } from "../../lib/utils";
|
||||||
|
|
||||||
|
interface EditButtonProps {
|
||||||
|
onClick?: () => void;
|
||||||
|
disabled?: boolean;
|
||||||
|
className?: string;
|
||||||
|
size?: "default" | "sm" | "lg" | "icon";
|
||||||
|
variant?:
|
||||||
|
| "default"
|
||||||
|
| "destructive"
|
||||||
|
| "outline"
|
||||||
|
| "secondary"
|
||||||
|
| "ghost"
|
||||||
|
| "link";
|
||||||
|
children?: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function EditButton({
|
||||||
|
onClick,
|
||||||
|
disabled = false,
|
||||||
|
className,
|
||||||
|
size = "sm",
|
||||||
|
variant = "outline",
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: EditButtonProps) {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
onClick={onClick}
|
||||||
|
disabled={disabled}
|
||||||
|
size={size}
|
||||||
|
variant={variant}
|
||||||
|
className={cn(
|
||||||
|
"h-8 px-3 text-muted-foreground hover:text-foreground transition-colors",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<Edit3 className="h-4 w-4" />
|
||||||
|
<span className="ml-2">{children || "Edit"}</span>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
22
frontend/src/components/ui/input.tsx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
|
||||||
|
({ className, type, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
type={type}
|
||||||
|
className={cn(
|
||||||
|
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
ref={ref}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
Input.displayName = "Input";
|
||||||
|
|
||||||
|
export { Input };
|
||||||
19
frontend/src/components/ui/label.tsx
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Label = React.forwardRef<
|
||||||
|
HTMLLabelElement,
|
||||||
|
React.LabelHTMLAttributes<HTMLLabelElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<label
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
Label.displayName = "Label";
|
||||||
|
|
||||||
|
export { Label };
|
||||||
46
frontend/src/components/ui/logo.tsx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
interface LogoProps {
|
||||||
|
className?: string;
|
||||||
|
size?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Logo({ className = "", size = 32 }: LogoProps) {
|
||||||
|
return (
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width={size}
|
||||||
|
height={size}
|
||||||
|
viewBox="0 0 32 32"
|
||||||
|
className={className}
|
||||||
|
role="img"
|
||||||
|
aria-labelledby="logo-title logo-desc"
|
||||||
|
>
|
||||||
|
<title id="logo-title">leggen — stylized italic L</title>
|
||||||
|
<desc id="logo-desc">
|
||||||
|
Square gradient background with italic white L.
|
||||||
|
</desc>
|
||||||
|
|
||||||
|
<defs>
|
||||||
|
<linearGradient id="logo-bg" x1="0" y1="0" x2="1" y2="1">
|
||||||
|
<stop offset="0%" stopColor="#0b74de" />
|
||||||
|
<stop offset="100%" stopColor="#06b6d4" />
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
|
||||||
|
{/* Square background */}
|
||||||
|
<rect width="32" height="32" fill="url(#logo-bg)" rx="4" />
|
||||||
|
|
||||||
|
{/* Italic L */}
|
||||||
|
<text
|
||||||
|
x="11"
|
||||||
|
y="22"
|
||||||
|
fontFamily="Inter, Roboto, Arial, sans-serif"
|
||||||
|
fontWeight="700"
|
||||||
|
fontSize="20"
|
||||||
|
fontStyle="italic"
|
||||||
|
fill="#fff"
|
||||||
|
>
|
||||||
|
L
|
||||||
|
</text>
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
}
|
||||||
118
frontend/src/components/ui/pagination.tsx
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { ChevronLeft, ChevronRight, MoreHorizontal } from "lucide-react";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { buttonVariants } from "@/components/ui/button";
|
||||||
|
import type { ButtonProps } from "@/components/ui/button";
|
||||||
|
|
||||||
|
const Pagination = ({ className, ...props }: React.ComponentProps<"nav">) => (
|
||||||
|
<nav
|
||||||
|
role="navigation"
|
||||||
|
aria-label="pagination"
|
||||||
|
className={cn("mx-auto flex w-full justify-center", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
Pagination.displayName = "Pagination";
|
||||||
|
|
||||||
|
const PaginationContent = React.forwardRef<
|
||||||
|
HTMLUListElement,
|
||||||
|
React.ComponentProps<"ul">
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<ul
|
||||||
|
ref={ref}
|
||||||
|
className={cn("flex flex-row items-center gap-1", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
PaginationContent.displayName = "PaginationContent";
|
||||||
|
|
||||||
|
const PaginationItem = React.forwardRef<
|
||||||
|
HTMLLIElement,
|
||||||
|
React.ComponentProps<"li">
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<li ref={ref} className={cn("", className)} {...props} />
|
||||||
|
));
|
||||||
|
PaginationItem.displayName = "PaginationItem";
|
||||||
|
|
||||||
|
type PaginationLinkProps = {
|
||||||
|
isActive?: boolean;
|
||||||
|
} & Pick<ButtonProps, "size"> &
|
||||||
|
React.ComponentProps<"a">;
|
||||||
|
|
||||||
|
const PaginationLink = ({
|
||||||
|
className,
|
||||||
|
isActive,
|
||||||
|
size = "icon",
|
||||||
|
...props
|
||||||
|
}: PaginationLinkProps) => (
|
||||||
|
<a
|
||||||
|
aria-current={isActive ? "page" : undefined}
|
||||||
|
className={cn(
|
||||||
|
buttonVariants({
|
||||||
|
variant: isActive ? "outline" : "ghost",
|
||||||
|
size,
|
||||||
|
}),
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
PaginationLink.displayName = "PaginationLink";
|
||||||
|
|
||||||
|
const PaginationPrevious = ({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof PaginationLink>) => (
|
||||||
|
<PaginationLink
|
||||||
|
aria-label="Go to previous page"
|
||||||
|
size="default"
|
||||||
|
className={cn("gap-1 pl-2.5", className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronLeft className="h-4 w-4" />
|
||||||
|
<span>Previous</span>
|
||||||
|
</PaginationLink>
|
||||||
|
);
|
||||||
|
PaginationPrevious.displayName = "PaginationPrevious";
|
||||||
|
|
||||||
|
const PaginationNext = ({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof PaginationLink>) => (
|
||||||
|
<PaginationLink
|
||||||
|
aria-label="Go to next page"
|
||||||
|
size="default"
|
||||||
|
className={cn("gap-1 pr-2.5", className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span>Next</span>
|
||||||
|
<ChevronRight className="h-4 w-4" />
|
||||||
|
</PaginationLink>
|
||||||
|
);
|
||||||
|
PaginationNext.displayName = "PaginationNext";
|
||||||
|
|
||||||
|
const PaginationEllipsis = ({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"span">) => (
|
||||||
|
<span
|
||||||
|
aria-hidden
|
||||||
|
className={cn("flex h-9 w-9 items-center justify-center", className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
|
<span className="sr-only">More pages</span>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
PaginationEllipsis.displayName = "PaginationEllipsis";
|
||||||
|
|
||||||
|
export {
|
||||||
|
Pagination,
|
||||||
|
PaginationContent,
|
||||||
|
PaginationEllipsis,
|
||||||
|
PaginationItem,
|
||||||
|
PaginationLink,
|
||||||
|
PaginationNext,
|
||||||
|
PaginationPrevious,
|
||||||
|
};
|
||||||
31
frontend/src/components/ui/popover.tsx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Popover = PopoverPrimitive.Root;
|
||||||
|
|
||||||
|
const PopoverTrigger = PopoverPrimitive.Trigger;
|
||||||
|
|
||||||
|
const PopoverAnchor = PopoverPrimitive.Anchor;
|
||||||
|
|
||||||
|
const PopoverContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof PopoverPrimitive.Content>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
|
||||||
|
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
|
||||||
|
<PopoverPrimitive.Portal>
|
||||||
|
<PopoverPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
align={align}
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
"z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-popover-content-transform-origin]",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</PopoverPrimitive.Portal>
|
||||||
|
));
|
||||||
|
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
|
||||||
|
|
||||||
|
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor };
|
||||||
26
frontend/src/components/ui/progress.tsx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import * as ProgressPrimitive from "@radix-ui/react-progress";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Progress = React.forwardRef<
|
||||||
|
React.ElementRef<typeof ProgressPrimitive.Root>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
|
||||||
|
>(({ className, value, ...props }, ref) => (
|
||||||
|
<ProgressPrimitive.Root
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"relative h-2 w-full overflow-hidden rounded-full bg-secondary",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ProgressPrimitive.Indicator
|
||||||
|
className="h-full w-full flex-1 bg-primary transition-all"
|
||||||
|
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
|
||||||
|
/>
|
||||||
|
</ProgressPrimitive.Root>
|
||||||
|
));
|
||||||
|
Progress.displayName = ProgressPrimitive.Root.displayName;
|
||||||
|
|
||||||
|
export { Progress };
|
||||||
21
frontend/src/components/ui/scroll-area.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { cn } from "../../lib/utils";
|
||||||
|
|
||||||
|
const ScrollArea = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.HTMLAttributes<HTMLDivElement>
|
||||||
|
>(({ className, children, ...props }, ref) => (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"relative overflow-auto scrollbar-thin scrollbar-thumb-gray-300 scrollbar-track-gray-100",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
ScrollArea.displayName = "ScrollArea";
|
||||||
|
|
||||||
|
export { ScrollArea };
|
||||||
157
frontend/src/components/ui/select.tsx
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import * as SelectPrimitive from "@radix-ui/react-select";
|
||||||
|
import { Check, ChevronDown, ChevronUp } from "lucide-react";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Select = SelectPrimitive.Root;
|
||||||
|
|
||||||
|
const SelectGroup = SelectPrimitive.Group;
|
||||||
|
|
||||||
|
const SelectValue = SelectPrimitive.Value;
|
||||||
|
|
||||||
|
const SelectTrigger = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SelectPrimitive.Trigger>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
|
||||||
|
>(({ className, children, ...props }, ref) => (
|
||||||
|
<SelectPrimitive.Trigger
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<SelectPrimitive.Icon asChild>
|
||||||
|
<ChevronDown className="h-4 w-4 opacity-50" />
|
||||||
|
</SelectPrimitive.Icon>
|
||||||
|
</SelectPrimitive.Trigger>
|
||||||
|
));
|
||||||
|
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
|
||||||
|
|
||||||
|
const SelectScrollUpButton = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<SelectPrimitive.ScrollUpButton
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"flex cursor-default items-center justify-center py-1",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronUp className="h-4 w-4" />
|
||||||
|
</SelectPrimitive.ScrollUpButton>
|
||||||
|
));
|
||||||
|
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
|
||||||
|
|
||||||
|
const SelectScrollDownButton = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<SelectPrimitive.ScrollDownButton
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"flex cursor-default items-center justify-center py-1",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronDown className="h-4 w-4" />
|
||||||
|
</SelectPrimitive.ScrollDownButton>
|
||||||
|
));
|
||||||
|
SelectScrollDownButton.displayName =
|
||||||
|
SelectPrimitive.ScrollDownButton.displayName;
|
||||||
|
|
||||||
|
const SelectContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SelectPrimitive.Content>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
|
||||||
|
>(({ className, children, position = "popper", ...props }, ref) => (
|
||||||
|
<SelectPrimitive.Portal>
|
||||||
|
<SelectPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",
|
||||||
|
position === "popper" &&
|
||||||
|
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
position={position}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<SelectScrollUpButton />
|
||||||
|
<SelectPrimitive.Viewport
|
||||||
|
className={cn(
|
||||||
|
"p-1",
|
||||||
|
position === "popper" &&
|
||||||
|
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</SelectPrimitive.Viewport>
|
||||||
|
<SelectScrollDownButton />
|
||||||
|
</SelectPrimitive.Content>
|
||||||
|
</SelectPrimitive.Portal>
|
||||||
|
));
|
||||||
|
SelectContent.displayName = SelectPrimitive.Content.displayName;
|
||||||
|
|
||||||
|
const SelectLabel = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SelectPrimitive.Label>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<SelectPrimitive.Label
|
||||||
|
ref={ref}
|
||||||
|
className={cn("px-2 py-1.5 text-sm font-semibold", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
SelectLabel.displayName = SelectPrimitive.Label.displayName;
|
||||||
|
|
||||||
|
const SelectItem = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SelectPrimitive.Item>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
|
||||||
|
>(({ className, children, ...props }, ref) => (
|
||||||
|
<SelectPrimitive.Item
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||||
|
<SelectPrimitive.ItemIndicator>
|
||||||
|
<Check className="h-4 w-4" />
|
||||||
|
</SelectPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||||
|
</SelectPrimitive.Item>
|
||||||
|
));
|
||||||
|
SelectItem.displayName = SelectPrimitive.Item.displayName;
|
||||||
|
|
||||||
|
const SelectSeparator = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SelectPrimitive.Separator>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<SelectPrimitive.Separator
|
||||||
|
ref={ref}
|
||||||
|
className={cn("-mx-1 my-1 h-px bg-muted", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
|
||||||
|
|
||||||
|
export {
|
||||||
|
Select,
|
||||||
|
SelectGroup,
|
||||||
|
SelectValue,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectContent,
|
||||||
|
SelectLabel,
|
||||||
|
SelectItem,
|
||||||
|
SelectSeparator,
|
||||||
|
SelectScrollUpButton,
|
||||||
|
SelectScrollDownButton,
|
||||||
|
};
|
||||||
29
frontend/src/components/ui/separator.tsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import * as SeparatorPrimitive from "@radix-ui/react-separator";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Separator = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SeparatorPrimitive.Root>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
|
||||||
|
>(
|
||||||
|
(
|
||||||
|
{ className, orientation = "horizontal", decorative = true, ...props },
|
||||||
|
ref,
|
||||||
|
) => (
|
||||||
|
<SeparatorPrimitive.Root
|
||||||
|
ref={ref}
|
||||||
|
decorative={decorative}
|
||||||
|
orientation={orientation}
|
||||||
|
className={cn(
|
||||||
|
"shrink-0 bg-border",
|
||||||
|
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
);
|
||||||
|
Separator.displayName = SeparatorPrimitive.Root.displayName;
|
||||||
|
|
||||||
|
export { Separator };
|
||||||
140
frontend/src/components/ui/sheet.tsx
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import * as React from "react";
|
||||||
|
import * as SheetPrimitive from "@radix-ui/react-dialog";
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
import { X } from "lucide-react";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Sheet = SheetPrimitive.Root;
|
||||||
|
|
||||||
|
const SheetTrigger = SheetPrimitive.Trigger;
|
||||||
|
|
||||||
|
const SheetClose = SheetPrimitive.Close;
|
||||||
|
|
||||||
|
const SheetPortal = SheetPrimitive.Portal;
|
||||||
|
|
||||||
|
const SheetOverlay = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SheetPrimitive.Overlay>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<SheetPrimitive.Overlay
|
||||||
|
className={cn(
|
||||||
|
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
ref={ref}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;
|
||||||
|
|
||||||
|
const sheetVariants = cva(
|
||||||
|
"fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
side: {
|
||||||
|
top: "inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
|
||||||
|
bottom:
|
||||||
|
"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
|
||||||
|
left: "inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",
|
||||||
|
right:
|
||||||
|
"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
side: "right",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
interface SheetContentProps
|
||||||
|
extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
|
||||||
|
VariantProps<typeof sheetVariants> {}
|
||||||
|
|
||||||
|
const SheetContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SheetPrimitive.Content>,
|
||||||
|
SheetContentProps
|
||||||
|
>(({ side = "right", className, children, ...props }, ref) => (
|
||||||
|
<SheetPortal>
|
||||||
|
<SheetOverlay />
|
||||||
|
<SheetPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
className={cn(sheetVariants({ side }), className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
<span className="sr-only">Close</span>
|
||||||
|
</SheetPrimitive.Close>
|
||||||
|
{children}
|
||||||
|
</SheetPrimitive.Content>
|
||||||
|
</SheetPortal>
|
||||||
|
));
|
||||||
|
SheetContent.displayName = SheetPrimitive.Content.displayName;
|
||||||
|
|
||||||
|
const SheetHeader = ({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex flex-col space-y-2 text-center sm:text-left",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
SheetHeader.displayName = "SheetHeader";
|
||||||
|
|
||||||
|
const SheetFooter = ({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
SheetFooter.displayName = "SheetFooter";
|
||||||
|
|
||||||
|
const SheetTitle = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SheetPrimitive.Title>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<SheetPrimitive.Title
|
||||||
|
ref={ref}
|
||||||
|
className={cn("text-lg font-semibold text-foreground", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
SheetTitle.displayName = SheetPrimitive.Title.displayName;
|
||||||
|
|
||||||
|
const SheetDescription = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SheetPrimitive.Description>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<SheetPrimitive.Description
|
||||||
|
ref={ref}
|
||||||
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
SheetDescription.displayName = SheetPrimitive.Description.displayName;
|
||||||
|
|
||||||
|
export {
|
||||||
|
Sheet,
|
||||||
|
SheetPortal,
|
||||||
|
SheetOverlay,
|
||||||
|
SheetTrigger,
|
||||||
|
SheetClose,
|
||||||
|
SheetContent,
|
||||||
|
SheetHeader,
|
||||||
|
SheetFooter,
|
||||||
|
SheetTitle,
|
||||||
|
SheetDescription,
|
||||||
|
};
|
||||||
779
frontend/src/components/ui/sidebar.tsx
Normal file
@@ -0,0 +1,779 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
import { PanelLeft } from "lucide-react";
|
||||||
|
|
||||||
|
import { useIsMobile } from "@/hooks/use-mobile";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Separator } from "@/components/ui/separator";
|
||||||
|
import {
|
||||||
|
Sheet,
|
||||||
|
SheetContent,
|
||||||
|
SheetDescription,
|
||||||
|
SheetHeader,
|
||||||
|
SheetTitle,
|
||||||
|
} from "@/components/ui/sheet";
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip";
|
||||||
|
|
||||||
|
const SIDEBAR_COOKIE_NAME = "sidebar_state";
|
||||||
|
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
||||||
|
const SIDEBAR_WIDTH = "16rem";
|
||||||
|
const SIDEBAR_WIDTH_MOBILE = "18rem";
|
||||||
|
const SIDEBAR_WIDTH_ICON = "3rem";
|
||||||
|
const SIDEBAR_KEYBOARD_SHORTCUT = "b";
|
||||||
|
|
||||||
|
type SidebarContextProps = {
|
||||||
|
state: "expanded" | "collapsed";
|
||||||
|
open: boolean;
|
||||||
|
setOpen: (open: boolean) => void;
|
||||||
|
openMobile: boolean;
|
||||||
|
setOpenMobile: (open: boolean) => void;
|
||||||
|
isMobile: boolean;
|
||||||
|
toggleSidebar: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SidebarContext = React.createContext<SidebarContextProps | null>(null);
|
||||||
|
|
||||||
|
function useSidebar() {
|
||||||
|
const context = React.useContext(SidebarContext);
|
||||||
|
if (!context) {
|
||||||
|
throw new Error("useSidebar must be used within a SidebarProvider.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SidebarProvider = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.ComponentProps<"div"> & {
|
||||||
|
defaultOpen?: boolean;
|
||||||
|
open?: boolean;
|
||||||
|
onOpenChange?: (open: boolean) => void;
|
||||||
|
}
|
||||||
|
>(
|
||||||
|
(
|
||||||
|
{
|
||||||
|
defaultOpen = true,
|
||||||
|
open: openProp,
|
||||||
|
onOpenChange: setOpenProp,
|
||||||
|
className,
|
||||||
|
style,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
},
|
||||||
|
ref,
|
||||||
|
) => {
|
||||||
|
const isMobile = useIsMobile();
|
||||||
|
const [openMobile, setOpenMobile] = React.useState(false);
|
||||||
|
|
||||||
|
// This is the internal state of the sidebar.
|
||||||
|
// We use openProp and setOpenProp for control from outside the component.
|
||||||
|
const [_open, _setOpen] = React.useState(defaultOpen);
|
||||||
|
const open = openProp ?? _open;
|
||||||
|
const setOpen = React.useCallback(
|
||||||
|
(value: boolean | ((value: boolean) => boolean)) => {
|
||||||
|
const openState = typeof value === "function" ? value(open) : value;
|
||||||
|
if (setOpenProp) {
|
||||||
|
setOpenProp(openState);
|
||||||
|
} else {
|
||||||
|
_setOpen(openState);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This sets the cookie to keep the sidebar state.
|
||||||
|
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
|
||||||
|
},
|
||||||
|
[setOpenProp, open],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Helper to toggle the sidebar.
|
||||||
|
const toggleSidebar = React.useCallback(() => {
|
||||||
|
return isMobile
|
||||||
|
? setOpenMobile((open) => !open)
|
||||||
|
: setOpen((open) => !open);
|
||||||
|
}, [isMobile, setOpen, setOpenMobile]);
|
||||||
|
|
||||||
|
// Adds a keyboard shortcut to toggle the sidebar.
|
||||||
|
React.useEffect(() => {
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (
|
||||||
|
event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
|
||||||
|
(event.metaKey || event.ctrlKey)
|
||||||
|
) {
|
||||||
|
event.preventDefault();
|
||||||
|
toggleSidebar();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||||
|
}, [toggleSidebar]);
|
||||||
|
|
||||||
|
// We add a state so that we can do data-state="expanded" or "collapsed".
|
||||||
|
// This makes it easier to style the sidebar with Tailwind classes.
|
||||||
|
const state = open ? "expanded" : "collapsed";
|
||||||
|
|
||||||
|
const contextValue = React.useMemo<SidebarContextProps>(
|
||||||
|
() => ({
|
||||||
|
state,
|
||||||
|
open,
|
||||||
|
setOpen,
|
||||||
|
isMobile,
|
||||||
|
openMobile,
|
||||||
|
setOpenMobile,
|
||||||
|
toggleSidebar,
|
||||||
|
}),
|
||||||
|
[
|
||||||
|
state,
|
||||||
|
open,
|
||||||
|
setOpen,
|
||||||
|
isMobile,
|
||||||
|
openMobile,
|
||||||
|
setOpenMobile,
|
||||||
|
toggleSidebar,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SidebarContext.Provider value={contextValue}>
|
||||||
|
<TooltipProvider delayDuration={0}>
|
||||||
|
<div
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
"--sidebar-width": SIDEBAR_WIDTH,
|
||||||
|
"--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
|
||||||
|
...style,
|
||||||
|
} as React.CSSProperties
|
||||||
|
}
|
||||||
|
className={cn(
|
||||||
|
"group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
ref={ref}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</TooltipProvider>
|
||||||
|
</SidebarContext.Provider>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
SidebarProvider.displayName = "SidebarProvider";
|
||||||
|
|
||||||
|
const Sidebar = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.ComponentProps<"div"> & {
|
||||||
|
side?: "left" | "right";
|
||||||
|
variant?: "sidebar" | "floating" | "inset";
|
||||||
|
collapsible?: "offcanvas" | "icon" | "none";
|
||||||
|
}
|
||||||
|
>(
|
||||||
|
(
|
||||||
|
{
|
||||||
|
side = "left",
|
||||||
|
variant = "sidebar",
|
||||||
|
collapsible = "offcanvas",
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
},
|
||||||
|
ref,
|
||||||
|
) => {
|
||||||
|
const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
|
||||||
|
|
||||||
|
if (collapsible === "none") {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex h-full w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
ref={ref}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMobile) {
|
||||||
|
return (
|
||||||
|
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
|
||||||
|
<SheetContent
|
||||||
|
data-sidebar="sidebar"
|
||||||
|
data-mobile="true"
|
||||||
|
className="w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
"--sidebar-width": SIDEBAR_WIDTH_MOBILE,
|
||||||
|
} as React.CSSProperties
|
||||||
|
}
|
||||||
|
side={side}
|
||||||
|
>
|
||||||
|
<SheetHeader className="sr-only">
|
||||||
|
<SheetTitle>Sidebar</SheetTitle>
|
||||||
|
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
||||||
|
</SheetHeader>
|
||||||
|
<div className="flex h-full w-full flex-col">{children}</div>
|
||||||
|
</SheetContent>
|
||||||
|
</Sheet>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
className="group peer hidden text-sidebar-foreground md:block"
|
||||||
|
data-state={state}
|
||||||
|
data-collapsible={state === "collapsed" ? collapsible : ""}
|
||||||
|
data-variant={variant}
|
||||||
|
data-side={side}
|
||||||
|
>
|
||||||
|
{/* This is what handles the sidebar gap on desktop */}
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"relative w-[--sidebar-width] bg-transparent transition-[width] duration-200 ease-linear",
|
||||||
|
"group-data-[collapsible=offcanvas]:w-0",
|
||||||
|
"group-data-[side=right]:rotate-180",
|
||||||
|
variant === "floating" || variant === "inset"
|
||||||
|
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]"
|
||||||
|
: "group-data-[collapsible=icon]:w-[--sidebar-width-icon]",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] duration-200 ease-linear md:flex",
|
||||||
|
side === "left"
|
||||||
|
? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
|
||||||
|
: "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
|
||||||
|
// Adjust the padding for floating and inset variants.
|
||||||
|
variant === "floating" || variant === "inset"
|
||||||
|
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]"
|
||||||
|
: "group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
data-sidebar="sidebar"
|
||||||
|
className="flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow"
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
Sidebar.displayName = "Sidebar";
|
||||||
|
|
||||||
|
const SidebarTrigger = React.forwardRef<
|
||||||
|
React.ElementRef<typeof Button>,
|
||||||
|
React.ComponentProps<typeof Button>
|
||||||
|
>(({ className, onClick, ...props }, ref) => {
|
||||||
|
const { toggleSidebar } = useSidebar();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="trigger"
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className={cn("h-7 w-7", className)}
|
||||||
|
onClick={(event) => {
|
||||||
|
onClick?.(event);
|
||||||
|
toggleSidebar();
|
||||||
|
}}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<PanelLeft />
|
||||||
|
<span className="sr-only">Toggle Sidebar</span>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarTrigger.displayName = "SidebarTrigger";
|
||||||
|
|
||||||
|
const SidebarRail = React.forwardRef<
|
||||||
|
HTMLButtonElement,
|
||||||
|
React.ComponentProps<"button">
|
||||||
|
>(({ className, ...props }, ref) => {
|
||||||
|
const { toggleSidebar } = useSidebar();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="rail"
|
||||||
|
aria-label="Toggle Sidebar"
|
||||||
|
tabIndex={-1}
|
||||||
|
onClick={toggleSidebar}
|
||||||
|
title="Toggle Sidebar"
|
||||||
|
className={cn(
|
||||||
|
"absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex",
|
||||||
|
"[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize",
|
||||||
|
"[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
|
||||||
|
"group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar",
|
||||||
|
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
|
||||||
|
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarRail.displayName = "SidebarRail";
|
||||||
|
|
||||||
|
const SidebarInset = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.ComponentProps<"main">
|
||||||
|
>(({ className, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
<main
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"relative flex w-full flex-1 flex-col bg-background",
|
||||||
|
"md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarInset.displayName = "SidebarInset";
|
||||||
|
|
||||||
|
const SidebarInput = React.forwardRef<
|
||||||
|
React.ElementRef<typeof Input>,
|
||||||
|
React.ComponentProps<typeof Input>
|
||||||
|
>(({ className, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
<Input
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="input"
|
||||||
|
className={cn(
|
||||||
|
"h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarInput.displayName = "SidebarInput";
|
||||||
|
|
||||||
|
const SidebarHeader = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.ComponentProps<"div">
|
||||||
|
>(({ className, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="header"
|
||||||
|
className={cn("flex flex-col gap-2 p-2", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarHeader.displayName = "SidebarHeader";
|
||||||
|
|
||||||
|
const SidebarFooter = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.ComponentProps<"div">
|
||||||
|
>(({ className, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="footer"
|
||||||
|
className={cn("flex flex-col gap-2 p-2", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarFooter.displayName = "SidebarFooter";
|
||||||
|
|
||||||
|
const SidebarSeparator = React.forwardRef<
|
||||||
|
React.ElementRef<typeof Separator>,
|
||||||
|
React.ComponentProps<typeof Separator>
|
||||||
|
>(({ className, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
<Separator
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="separator"
|
||||||
|
className={cn("mx-2 w-auto bg-sidebar-border", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarSeparator.displayName = "SidebarSeparator";
|
||||||
|
|
||||||
|
const SidebarContent = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.ComponentProps<"div">
|
||||||
|
>(({ className, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="content"
|
||||||
|
className={cn(
|
||||||
|
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarContent.displayName = "SidebarContent";
|
||||||
|
|
||||||
|
const SidebarGroup = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.ComponentProps<"div">
|
||||||
|
>(({ className, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="group"
|
||||||
|
className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarGroup.displayName = "SidebarGroup";
|
||||||
|
|
||||||
|
const SidebarGroupLabel = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.ComponentProps<"div"> & { asChild?: boolean }
|
||||||
|
>(({ className, asChild = false, ...props }, ref) => {
|
||||||
|
const Comp = asChild ? Slot : "div";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="group-label"
|
||||||
|
className={cn(
|
||||||
|
"flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-none ring-sidebar-ring transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||||
|
"group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarGroupLabel.displayName = "SidebarGroupLabel";
|
||||||
|
|
||||||
|
const SidebarGroupAction = React.forwardRef<
|
||||||
|
HTMLButtonElement,
|
||||||
|
React.ComponentProps<"button"> & { asChild?: boolean }
|
||||||
|
>(({ className, asChild = false, ...props }, ref) => {
|
||||||
|
const Comp = asChild ? Slot : "button";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="group-action"
|
||||||
|
className={cn(
|
||||||
|
"absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||||
|
// Increases the hit area of the button on mobile.
|
||||||
|
"after:absolute after:-inset-2 after:md:hidden",
|
||||||
|
"group-data-[collapsible=icon]:hidden",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarGroupAction.displayName = "SidebarGroupAction";
|
||||||
|
|
||||||
|
const SidebarGroupContent = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.ComponentProps<"div">
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="group-content"
|
||||||
|
className={cn("w-full text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
SidebarGroupContent.displayName = "SidebarGroupContent";
|
||||||
|
|
||||||
|
const SidebarMenu = React.forwardRef<
|
||||||
|
HTMLUListElement,
|
||||||
|
React.ComponentProps<"ul">
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<ul
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="menu"
|
||||||
|
className={cn("flex w-full min-w-0 flex-col gap-1", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
SidebarMenu.displayName = "SidebarMenu";
|
||||||
|
|
||||||
|
const SidebarMenuItem = React.forwardRef<
|
||||||
|
HTMLLIElement,
|
||||||
|
React.ComponentProps<"li">
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<li
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="menu-item"
|
||||||
|
className={cn("group/menu-item relative", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
SidebarMenuItem.displayName = "SidebarMenuItem";
|
||||||
|
|
||||||
|
const sidebarMenuButtonVariants = cva(
|
||||||
|
"peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
||||||
|
outline:
|
||||||
|
"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
default: "h-8 text-sm",
|
||||||
|
sm: "h-7 text-xs",
|
||||||
|
lg: "h-12 text-sm group-data-[collapsible=icon]:!p-0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const SidebarMenuButton = React.forwardRef<
|
||||||
|
HTMLButtonElement,
|
||||||
|
React.ComponentProps<"button"> & {
|
||||||
|
asChild?: boolean;
|
||||||
|
isActive?: boolean;
|
||||||
|
tooltip?: string | React.ComponentProps<typeof TooltipContent>;
|
||||||
|
} & VariantProps<typeof sidebarMenuButtonVariants>
|
||||||
|
>(
|
||||||
|
(
|
||||||
|
{
|
||||||
|
asChild = false,
|
||||||
|
isActive = false,
|
||||||
|
variant = "default",
|
||||||
|
size = "default",
|
||||||
|
tooltip,
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
},
|
||||||
|
ref,
|
||||||
|
) => {
|
||||||
|
const Comp = asChild ? Slot : "button";
|
||||||
|
const { isMobile, state } = useSidebar();
|
||||||
|
|
||||||
|
const button = (
|
||||||
|
<Comp
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="menu-button"
|
||||||
|
data-size={size}
|
||||||
|
data-active={isActive}
|
||||||
|
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!tooltip) {
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof tooltip === "string") {
|
||||||
|
tooltip = {
|
||||||
|
children: tooltip,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
||||||
|
<TooltipContent
|
||||||
|
side="right"
|
||||||
|
align="center"
|
||||||
|
hidden={state !== "collapsed" || isMobile}
|
||||||
|
{...tooltip}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
SidebarMenuButton.displayName = "SidebarMenuButton";
|
||||||
|
|
||||||
|
const SidebarMenuAction = React.forwardRef<
|
||||||
|
HTMLButtonElement,
|
||||||
|
React.ComponentProps<"button"> & {
|
||||||
|
asChild?: boolean;
|
||||||
|
showOnHover?: boolean;
|
||||||
|
}
|
||||||
|
>(({ className, asChild = false, showOnHover = false, ...props }, ref) => {
|
||||||
|
const Comp = asChild ? Slot : "button";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="menu-action"
|
||||||
|
className={cn(
|
||||||
|
"absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0",
|
||||||
|
// Increases the hit area of the button on mobile.
|
||||||
|
"after:absolute after:-inset-2 after:md:hidden",
|
||||||
|
"peer-data-[size=sm]/menu-button:top-1",
|
||||||
|
"peer-data-[size=default]/menu-button:top-1.5",
|
||||||
|
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||||
|
"group-data-[collapsible=icon]:hidden",
|
||||||
|
showOnHover &&
|
||||||
|
"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarMenuAction.displayName = "SidebarMenuAction";
|
||||||
|
|
||||||
|
const SidebarMenuBadge = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.ComponentProps<"div">
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="menu-badge"
|
||||||
|
className={cn(
|
||||||
|
"pointer-events-none absolute right-1 flex h-5 min-w-5 select-none items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground",
|
||||||
|
"peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
|
||||||
|
"peer-data-[size=sm]/menu-button:top-1",
|
||||||
|
"peer-data-[size=default]/menu-button:top-1.5",
|
||||||
|
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||||
|
"group-data-[collapsible=icon]:hidden",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
SidebarMenuBadge.displayName = "SidebarMenuBadge";
|
||||||
|
|
||||||
|
const SidebarMenuSkeleton = React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
React.ComponentProps<"div"> & {
|
||||||
|
showIcon?: boolean;
|
||||||
|
}
|
||||||
|
>(({ className, showIcon = false, ...props }, ref) => {
|
||||||
|
// Random width between 50 to 90%.
|
||||||
|
const width = React.useMemo(() => {
|
||||||
|
return `${Math.floor(Math.random() * 40) + 50}%`;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="menu-skeleton"
|
||||||
|
className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{showIcon && (
|
||||||
|
<Skeleton
|
||||||
|
className="size-4 rounded-md"
|
||||||
|
data-sidebar="menu-skeleton-icon"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<Skeleton
|
||||||
|
className="h-4 max-w-[--skeleton-width] flex-1"
|
||||||
|
data-sidebar="menu-skeleton-text"
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
"--skeleton-width": width,
|
||||||
|
} as React.CSSProperties
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarMenuSkeleton.displayName = "SidebarMenuSkeleton";
|
||||||
|
|
||||||
|
const SidebarMenuSub = React.forwardRef<
|
||||||
|
HTMLUListElement,
|
||||||
|
React.ComponentProps<"ul">
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<ul
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="menu-sub"
|
||||||
|
className={cn(
|
||||||
|
"mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5",
|
||||||
|
"group-data-[collapsible=icon]:hidden",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
SidebarMenuSub.displayName = "SidebarMenuSub";
|
||||||
|
|
||||||
|
const SidebarMenuSubItem = React.forwardRef<
|
||||||
|
HTMLLIElement,
|
||||||
|
React.ComponentProps<"li">
|
||||||
|
>(({ ...props }, ref) => <li ref={ref} {...props} />);
|
||||||
|
SidebarMenuSubItem.displayName = "SidebarMenuSubItem";
|
||||||
|
|
||||||
|
const SidebarMenuSubButton = React.forwardRef<
|
||||||
|
HTMLAnchorElement,
|
||||||
|
React.ComponentProps<"a"> & {
|
||||||
|
asChild?: boolean;
|
||||||
|
size?: "sm" | "md";
|
||||||
|
isActive?: boolean;
|
||||||
|
}
|
||||||
|
>(({ asChild = false, size = "md", isActive, className, ...props }, ref) => {
|
||||||
|
const Comp = asChild ? Slot : "a";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
ref={ref}
|
||||||
|
data-sidebar="menu-sub-button"
|
||||||
|
data-size={size}
|
||||||
|
data-active={isActive}
|
||||||
|
className={cn(
|
||||||
|
"flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground",
|
||||||
|
"data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
|
||||||
|
size === "sm" && "text-xs",
|
||||||
|
size === "md" && "text-sm",
|
||||||
|
"group-data-[collapsible=icon]:hidden",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
SidebarMenuSubButton.displayName = "SidebarMenuSubButton";
|
||||||
|
|
||||||
|
export {
|
||||||
|
Sidebar,
|
||||||
|
SidebarContent,
|
||||||
|
SidebarFooter,
|
||||||
|
SidebarGroup,
|
||||||
|
SidebarGroupAction,
|
||||||
|
SidebarGroupContent,
|
||||||
|
SidebarGroupLabel,
|
||||||
|
SidebarHeader,
|
||||||
|
SidebarInput,
|
||||||
|
SidebarInset,
|
||||||
|
SidebarMenu,
|
||||||
|
SidebarMenuAction,
|
||||||
|
SidebarMenuBadge,
|
||||||
|
SidebarMenuButton,
|
||||||
|
SidebarMenuItem,
|
||||||
|
SidebarMenuSkeleton,
|
||||||
|
SidebarMenuSub,
|
||||||
|
SidebarMenuSubButton,
|
||||||
|
SidebarMenuSubItem,
|
||||||
|
SidebarProvider,
|
||||||
|
SidebarRail,
|
||||||
|
SidebarSeparator,
|
||||||
|
SidebarTrigger,
|
||||||
|
useSidebar,
|
||||||
|
};
|
||||||
15
frontend/src/components/ui/skeleton.tsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
function Skeleton({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn("animate-pulse rounded-md bg-primary/10", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Skeleton };
|
||||||
27
frontend/src/components/ui/sonner.tsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Toaster as Sonner } from "sonner";
|
||||||
|
|
||||||
|
type ToasterProps = React.ComponentProps<typeof Sonner>;
|
||||||
|
|
||||||
|
const Toaster = ({ ...props }: ToasterProps) => {
|
||||||
|
return (
|
||||||
|
<Sonner
|
||||||
|
className="toaster group"
|
||||||
|
toastOptions={{
|
||||||
|
classNames: {
|
||||||
|
toast:
|
||||||
|
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
|
||||||
|
description: "group-[.toast]:text-muted-foreground",
|
||||||
|
actionButton:
|
||||||
|
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
|
||||||
|
cancelButton:
|
||||||
|
"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { Toaster };
|
||||||
27
frontend/src/components/ui/switch.tsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import * as SwitchPrimitives from "@radix-ui/react-switch";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Switch = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SwitchPrimitives.Root>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<SwitchPrimitives.Root
|
||||||
|
className={cn(
|
||||||
|
"peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
ref={ref}
|
||||||
|
>
|
||||||
|
<SwitchPrimitives.Thumb
|
||||||
|
className={cn(
|
||||||
|
"pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</SwitchPrimitives.Root>
|
||||||
|
));
|
||||||
|
Switch.displayName = SwitchPrimitives.Root.displayName;
|
||||||
|
|
||||||
|
export { Switch };
|
||||||
117
frontend/src/components/ui/table.tsx
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Table = React.forwardRef<
|
||||||
|
HTMLTableElement,
|
||||||
|
React.HTMLAttributes<HTMLTableElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<div className="relative w-full overflow-auto">
|
||||||
|
<table
|
||||||
|
ref={ref}
|
||||||
|
className={cn("w-full caption-bottom text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
Table.displayName = "Table";
|
||||||
|
|
||||||
|
const TableHeader = React.forwardRef<
|
||||||
|
HTMLTableSectionElement,
|
||||||
|
React.HTMLAttributes<HTMLTableSectionElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
|
||||||
|
));
|
||||||
|
TableHeader.displayName = "TableHeader";
|
||||||
|
|
||||||
|
const TableBody = React.forwardRef<
|
||||||
|
HTMLTableSectionElement,
|
||||||
|
React.HTMLAttributes<HTMLTableSectionElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<tbody
|
||||||
|
ref={ref}
|
||||||
|
className={cn("[&_tr:last-child]:border-0", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TableBody.displayName = "TableBody";
|
||||||
|
|
||||||
|
const TableFooter = React.forwardRef<
|
||||||
|
HTMLTableSectionElement,
|
||||||
|
React.HTMLAttributes<HTMLTableSectionElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<tfoot
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TableFooter.displayName = "TableFooter";
|
||||||
|
|
||||||
|
const TableRow = React.forwardRef<
|
||||||
|
HTMLTableRowElement,
|
||||||
|
React.HTMLAttributes<HTMLTableRowElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<tr
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TableRow.displayName = "TableRow";
|
||||||
|
|
||||||
|
const TableHead = React.forwardRef<
|
||||||
|
HTMLTableCellElement,
|
||||||
|
React.ThHTMLAttributes<HTMLTableCellElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<th
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TableHead.displayName = "TableHead";
|
||||||
|
|
||||||
|
const TableCell = React.forwardRef<
|
||||||
|
HTMLTableCellElement,
|
||||||
|
React.TdHTMLAttributes<HTMLTableCellElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<td
|
||||||
|
ref={ref}
|
||||||
|
className={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TableCell.displayName = "TableCell";
|
||||||
|
|
||||||
|
const TableCaption = React.forwardRef<
|
||||||
|
HTMLTableCaptionElement,
|
||||||
|
React.HTMLAttributes<HTMLTableCaptionElement>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<caption
|
||||||
|
ref={ref}
|
||||||
|
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TableCaption.displayName = "TableCaption";
|
||||||
|
|
||||||
|
export {
|
||||||
|
Table,
|
||||||
|
TableHeader,
|
||||||
|
TableBody,
|
||||||
|
TableFooter,
|
||||||
|
TableHead,
|
||||||
|
TableRow,
|
||||||
|
TableCell,
|
||||||
|
TableCaption,
|
||||||
|
};
|
||||||
53
frontend/src/components/ui/tabs.tsx
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const Tabs = TabsPrimitive.Root;
|
||||||
|
|
||||||
|
const TabsList = React.forwardRef<
|
||||||
|
React.ElementRef<typeof TabsPrimitive.List>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<TabsPrimitive.List
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TabsList.displayName = TabsPrimitive.List.displayName;
|
||||||
|
|
||||||
|
const TabsTrigger = React.forwardRef<
|
||||||
|
React.ElementRef<typeof TabsPrimitive.Trigger>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<TabsPrimitive.Trigger
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName;
|
||||||
|
|
||||||
|
const TabsContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof TabsPrimitive.Content>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<TabsPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TabsContent.displayName = TabsPrimitive.Content.displayName;
|
||||||
|
|
||||||
|
export { Tabs, TabsList, TabsTrigger, TabsContent };
|
||||||
52
frontend/src/components/ui/theme-toggle.tsx
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import { Monitor, Moon, Sun } from "lucide-react";
|
||||||
|
import { Button } from "./button";
|
||||||
|
import { useTheme } from "../../contexts/ThemeContext";
|
||||||
|
|
||||||
|
export function ThemeToggle() {
|
||||||
|
const { theme, setTheme } = useTheme();
|
||||||
|
|
||||||
|
const cycleTheme = () => {
|
||||||
|
if (theme === "light") {
|
||||||
|
setTheme("dark");
|
||||||
|
} else if (theme === "dark") {
|
||||||
|
setTheme("system");
|
||||||
|
} else {
|
||||||
|
setTheme("light");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getIcon = () => {
|
||||||
|
switch (theme) {
|
||||||
|
case "light":
|
||||||
|
return <Sun className="h-4 w-4" />;
|
||||||
|
case "dark":
|
||||||
|
return <Moon className="h-4 w-4" />;
|
||||||
|
case "system":
|
||||||
|
return <Monitor className="h-4 w-4" />;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getLabel = () => {
|
||||||
|
switch (theme) {
|
||||||
|
case "light":
|
||||||
|
return "Switch to dark mode";
|
||||||
|
case "dark":
|
||||||
|
return "Switch to system mode";
|
||||||
|
case "system":
|
||||||
|
return "Switch to light mode";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={cycleTheme}
|
||||||
|
className="h-8 w-8"
|
||||||
|
title={getLabel()}
|
||||||
|
>
|
||||||
|
{getIcon()}
|
||||||
|
<span className="sr-only">{getLabel()}</span>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
30
frontend/src/components/ui/tooltip.tsx
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const TooltipProvider = TooltipPrimitive.Provider;
|
||||||
|
|
||||||
|
const Tooltip = TooltipPrimitive.Root;
|
||||||
|
|
||||||
|
const TooltipTrigger = TooltipPrimitive.Trigger;
|
||||||
|
|
||||||
|
const TooltipContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof TooltipPrimitive.Content>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
||||||
|
>(({ className, sideOffset = 4, ...props }, ref) => (
|
||||||
|
<TooltipPrimitive.Portal>
|
||||||
|
<TooltipPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
"z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</TooltipPrimitive.Portal>
|
||||||
|
));
|
||||||
|
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
||||||
|
|
||||||
|
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
||||||
111
frontend/src/contexts/ThemeContext.tsx
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import React, { createContext, useContext, useEffect, useState } from "react";
|
||||||
|
|
||||||
|
type Theme = "light" | "dark" | "system";
|
||||||
|
|
||||||
|
interface ThemeContextType {
|
||||||
|
theme: Theme;
|
||||||
|
setTheme: (theme: Theme) => void;
|
||||||
|
actualTheme: "light" | "dark";
|
||||||
|
}
|
||||||
|
|
||||||
|
const ThemeContext = createContext<ThemeContextType | undefined>(undefined);
|
||||||
|
|
||||||
|
// Theme colors for different modes
|
||||||
|
const THEME_COLORS = {
|
||||||
|
light: "#0b74de", // Primary brand color
|
||||||
|
dark: "#0f0f23", // Dark background color that matches typical dark themes
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
||||||
|
const [theme, setTheme] = useState<Theme>(() => {
|
||||||
|
const stored = localStorage.getItem("theme") as Theme;
|
||||||
|
return stored || "system";
|
||||||
|
});
|
||||||
|
|
||||||
|
const [actualTheme, setActualTheme] = useState<"light" | "dark">("light");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const root = window.document.documentElement;
|
||||||
|
|
||||||
|
const updateActualTheme = () => {
|
||||||
|
let resolvedTheme: "light" | "dark";
|
||||||
|
|
||||||
|
if (theme === "system") {
|
||||||
|
resolvedTheme = window.matchMedia("(prefers-color-scheme: dark)")
|
||||||
|
.matches
|
||||||
|
? "dark"
|
||||||
|
: "light";
|
||||||
|
} else {
|
||||||
|
resolvedTheme = theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
setActualTheme(resolvedTheme);
|
||||||
|
|
||||||
|
// Remove previous theme classes
|
||||||
|
root.classList.remove("light", "dark");
|
||||||
|
|
||||||
|
// Add resolved theme class
|
||||||
|
root.classList.add(resolvedTheme);
|
||||||
|
|
||||||
|
// Update theme-color meta tags for PWA status bar
|
||||||
|
const themeColor = THEME_COLORS[resolvedTheme];
|
||||||
|
|
||||||
|
// Update theme-color meta tag
|
||||||
|
const themeColorMeta = document.getElementById(
|
||||||
|
"theme-color-meta",
|
||||||
|
) as HTMLMetaElement;
|
||||||
|
if (themeColorMeta) {
|
||||||
|
themeColorMeta.content = themeColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update Microsoft tile color
|
||||||
|
const msThemeColorMeta = document.getElementById(
|
||||||
|
"ms-theme-color-meta",
|
||||||
|
) as HTMLMetaElement;
|
||||||
|
if (msThemeColorMeta) {
|
||||||
|
msThemeColorMeta.content = themeColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update Apple status bar style for better iOS integration
|
||||||
|
const appleStatusBarMeta = document.getElementById(
|
||||||
|
"apple-status-bar-meta",
|
||||||
|
) as HTMLMetaElement;
|
||||||
|
if (appleStatusBarMeta) {
|
||||||
|
// Use 'black-translucent' for dark theme, 'default' for light theme
|
||||||
|
appleStatusBarMeta.content =
|
||||||
|
resolvedTheme === "dark" ? "black-translucent" : "default";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
updateActualTheme();
|
||||||
|
|
||||||
|
// Listen for system theme changes
|
||||||
|
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||||
|
const handleChange = () => {
|
||||||
|
if (theme === "system") {
|
||||||
|
updateActualTheme();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
mediaQuery.addEventListener("change", handleChange);
|
||||||
|
|
||||||
|
// Store theme preference
|
||||||
|
localStorage.setItem("theme", theme);
|
||||||
|
|
||||||
|
return () => mediaQuery.removeEventListener("change", handleChange);
|
||||||
|
}, [theme]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ThemeContext.Provider value={{ theme, setTheme, actualTheme }}>
|
||||||
|
{children}
|
||||||
|
</ThemeContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useTheme() {
|
||||||
|
const context = useContext(ThemeContext);
|
||||||
|
if (context === undefined) {
|
||||||
|
throw new Error("useTheme must be used within a ThemeProvider");
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
21
frontend/src/hooks/use-mobile.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
|
||||||
|
const MOBILE_BREAKPOINT = 768;
|
||||||
|
|
||||||
|
export function useIsMobile() {
|
||||||
|
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
||||||
|
const onChange = () => {
|
||||||
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
||||||
|
};
|
||||||
|
mql.addEventListener("change", onChange);
|
||||||
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
||||||
|
return () => mql.removeEventListener("change", onChange);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return !!isMobile;
|
||||||
|
}
|
||||||
94
frontend/src/index.css
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
@tailwind base;
|
||||||
|
@tailwind components;
|
||||||
|
@tailwind utilities;
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
:root {
|
||||||
|
--background: 0 0% 100%;
|
||||||
|
--foreground: 222.2 84% 4.9%;
|
||||||
|
--card: 0 0% 100%;
|
||||||
|
--card-foreground: 222.2 84% 4.9%;
|
||||||
|
--popover: 0 0% 100%;
|
||||||
|
--popover-foreground: 222.2 84% 4.9%;
|
||||||
|
--primary: 219 91% 46%;
|
||||||
|
--primary-foreground: 210 40% 98%;
|
||||||
|
--secondary: 189 94% 43%;
|
||||||
|
--secondary-foreground: 210 40% 98%;
|
||||||
|
--muted: 210 40% 96.1%;
|
||||||
|
--muted-foreground: 215.4 16.3% 46.9%;
|
||||||
|
--accent: 210 40% 96.1%;
|
||||||
|
--accent-foreground: 222.2 47.4% 11.2%;
|
||||||
|
--destructive: 0 84.2% 60.2%;
|
||||||
|
--destructive-foreground: 210 40% 98%;
|
||||||
|
--border: 214.3 31.8% 91.4%;
|
||||||
|
--input: 214.3 31.8% 91.4%;
|
||||||
|
--ring: 222.2 84% 4.9%;
|
||||||
|
--chart-1: 12 76% 61%;
|
||||||
|
--chart-2: 173 58% 39%;
|
||||||
|
--chart-3: 197 37% 24%;
|
||||||
|
--chart-4: 43 74% 66%;
|
||||||
|
--chart-5: 27 87% 67%;
|
||||||
|
--radius: 0.5rem;
|
||||||
|
|
||||||
|
/* iOS Safe Area Support for PWA */
|
||||||
|
--safe-area-inset-top: env(safe-area-inset-top, 0px);
|
||||||
|
--safe-area-inset-right: env(safe-area-inset-right, 0px);
|
||||||
|
--safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
|
||||||
|
--safe-area-inset-left: env(safe-area-inset-left, 0px);
|
||||||
|
--sidebar-background: 0 0% 98%;
|
||||||
|
--sidebar-foreground: 240 5.3% 26.1%;
|
||||||
|
--sidebar-primary: 240 5.9% 10%;
|
||||||
|
--sidebar-primary-foreground: 0 0% 98%;
|
||||||
|
--sidebar-accent: 240 4.8% 95.9%;
|
||||||
|
--sidebar-accent-foreground: 240 5.9% 10%;
|
||||||
|
--sidebar-border: 220 13% 91%;
|
||||||
|
--sidebar-ring: 217.2 91.2% 59.8%;
|
||||||
|
}
|
||||||
|
.dark {
|
||||||
|
--background: 222.2 84% 4.9%;
|
||||||
|
--foreground: 210 40% 98%;
|
||||||
|
--card: 222.2 84% 4.9%;
|
||||||
|
--card-foreground: 210 40% 98%;
|
||||||
|
--popover: 222.2 84% 4.9%;
|
||||||
|
--popover-foreground: 210 40% 98%;
|
||||||
|
--primary: 219 91% 46%;
|
||||||
|
--primary-foreground: 210 40% 98%;
|
||||||
|
--secondary: 189 94% 43%;
|
||||||
|
--secondary-foreground: 210 40% 98%;
|
||||||
|
--muted: 217.2 32.6% 17.5%;
|
||||||
|
--muted-foreground: 215 20.2% 65.1%;
|
||||||
|
--accent: 217.2 32.6% 17.5%;
|
||||||
|
--accent-foreground: 210 40% 98%;
|
||||||
|
--destructive: 0 62.8% 30.6%;
|
||||||
|
--destructive-foreground: 210 40% 98%;
|
||||||
|
--border: 217.2 32.6% 17.5%;
|
||||||
|
--input: 217.2 32.6% 17.5%;
|
||||||
|
--ring: 212.7 26.8% 83.9%;
|
||||||
|
--chart-1: 220 70% 50%;
|
||||||
|
--chart-2: 160 60% 45%;
|
||||||
|
--chart-3: 30 80% 55%;
|
||||||
|
--chart-4: 280 65% 60%;
|
||||||
|
--chart-5: 340 75% 55%;
|
||||||
|
--sidebar-background: 240 5.9% 10%;
|
||||||
|
--sidebar-foreground: 240 4.8% 95.9%;
|
||||||
|
--sidebar-primary: 224.3 76.3% 48%;
|
||||||
|
--sidebar-primary-foreground: 0 0% 100%;
|
||||||
|
--sidebar-accent: 240 3.7% 15.9%;
|
||||||
|
--sidebar-accent-foreground: 240 4.8% 95.9%;
|
||||||
|
--sidebar-border: 240 3.7% 15.9%;
|
||||||
|
--sidebar-ring: 217.2 91.2% 59.8%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
* {
|
||||||
|
@apply border-border;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
@apply bg-background text-foreground;
|
||||||
|
padding-top: var(--safe-area-inset-top);
|
||||||
|
padding-bottom: var(--safe-area-inset-bottom);
|
||||||
|
padding-left: var(--safe-area-inset-left);
|
||||||
|
padding-right: var(--safe-area-inset-right);
|
||||||
|
}
|
||||||
|
}
|
||||||