Commit Graph

88 Commits

Author SHA1 Message Date
Cauê Faleiros
b5c8e97701 fix: revert backup volume path to exact specification
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m2s
- Updated the host bind mount path to exactly '/opt/backups_db' as explicitly required by the server configuration.
2026-03-25 14:20:05 -03:00
Cauê Faleiros
f65ff97434 fix: change mysql backup volume path to prevent permission denied errors
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m7s
- Updated the host bind mount from the restricted '/root' directory to '/opt/fasto_backups' to ensure the Docker daemon has the necessary permissions to read and write database dumps.
2026-03-25 14:18:16 -03:00
Cauê Faleiros
958a2cdbd9 chore: force recreate database init sql config in docker swarm
All checks were successful
Build and Deploy / build-and-push (push) Successful in 58s
- Appended a version suffix to the `init_sql` config name to bypass Docker Swarm's immutable config cache and force the cluster to pick up the latest database schema changes on deployment.
2026-03-25 13:55:31 -03:00
Cauê Faleiros
eb483f903b chore: remove swarm deployment constraint from mysql backup service
All checks were successful
Build and Deploy / build-and-push (push) Successful in 58s
- Dropped the 'node.role == manager' deployment constraint to allow the backup container to be scheduled on any available node or to run smoothly in non-swarm Docker Compose environments.
2026-03-25 13:23:34 -03:00
Cauê Faleiros
9ffcfcdcc8 chore: add automated database backup service and tighten backend security
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m56s
- Added `databack/mysql-backup` service to the production docker-compose Swarm stack, scheduling a daily 02:55 AM cron backup of the database with a 3-day local retention policy.

- Fixed a critical race condition in the backend JWT authentication middleware where an invalid token returning 401 could crash the response flow if the route executed before the defensive checks caught it.

- Added strict undefined defensive checks to the `getUserById` endpoint and RBAC middleware to gracefully reject requests that somehow bypass the token parser.

- Updated `GEMINI.md` technical documentation to fully match the real codebase logic.

- Fixed UX rule to prevent `manager` role from seeing Funnels or Origins tabs in the sidebar.

- Blocked `agent` role from modifying their own 'fullName' string in the Profile UI.
2026-03-25 12:40:53 -03:00
Cauê Faleiros
3663d03cb9 refactor(rbac): complete the removal of 'owner' role from backend routes and logic
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m48s
- Cleaned up the requireRole middleware across all Funnel and Origin API routes to strictly allow only 'admin' and 'super_admin' to perform structural changes.

- Updated the tenant creation script to assign the 'admin' role to new signups instead of 'owner'.
2026-03-23 15:40:36 -03:00
Cauê Faleiros
2317c46ac9 fix: change expired JWT response code to 401 to properly trigger frontend interceptor
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m42s
- The backend was returning 403 Forbidden when a token expired, causing the frontend apiFetch interceptor (which listens for 401) to ignore it and crash the session.
2026-03-19 16:31:20 -03:00
Cauê Faleiros
4489f0a74d refactor: completely remove 'owner' role from RBAC system
- The platform now strictly uses 'super_admin', 'admin', 'manager', and 'agent' to simplify permissions and match business requirements.
2026-03-19 15:33:16 -03:00
Cauê Faleiros
327ad064a4 feat: implement secure 2-token authentication with rolling sessions
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m43s
- Refactored POST /auth/login to issue a 15-minute Access Token and a 30-day Refresh Token.

- Added POST /auth/refresh endpoint to automatically issue new Access Tokens and extend the Refresh Token's lifespan by 30 days upon use (Sliding Expiration).

- Built an HTTP interceptor wrapper (apiFetch) in dataService.ts that automatically catches 401 Unauthorized errors, calls the refresh endpoint, updates localStorage, and silently retries the original request without logging the user out.
2026-03-19 14:45:53 -03:00
Cauê Faleiros
8f7e5ee487 feat: synchronize dashboard origins with management page and add integration endpoints
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m53s
- Updated Dashboard origin chart to strictly reflect only configured origins, grouping unmapped data into an 'Outros' category.

- Added GET /api/integration/funnels and GET /api/integration/origins endpoints to allow external AIs to dynamically map stages and lead sources.
2026-03-18 16:43:42 -03:00
Cauê Faleiros
f11db95a2f fix: allow origin colors to be edited and display correctly in dashboard
- Fixed database initialization where default origins were seeded without color_classes.

- Added a visual color picker to the Origens admin page to allow users to assign colors to origin tags.

- Updated Dashboard Pie Chart to read the color classes correctly and display them.
2026-03-18 13:43:43 -03:00
Cauê Faleiros
1d3315a1d0 feat: implement relational lead origins with team assignments
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m51s
- Dropped simple origins table in favor of origin_groups and origin_items to match the Funnels architecture.

- Added origin_group_id to teams table to assign specific origins to specific teams.

- Updated /admin/origins page to support creating origin groups, adding origin items to them, and assigning teams to groups.

- Updated Dashboard and UserDetail pages to dynamically load the exact origin items belonging to the active team/user.
2026-03-18 11:18:30 -03:00
Cauê Faleiros
64c4ca8fb5 style: add 2-digit year to calendar date display
All checks were successful
Build and Deploy / build-and-push (push) Successful in 53s
- Updated the DateRangePicker component to display the date in DD/MM/YY format (e.g. 18/03/26) instead of just DD/MM for better clarity.
2026-03-18 09:39:55 -03:00
Cauê Faleiros
47799990e3 fix: auto-redirect super admins to the super admin panel from root
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m45s
- Updated AuthGuard to intercept navigation to the standard dashboard ('/') for users with the 'super_admin' role and automatically redirect them to '/super-admin'.
2026-03-18 09:32:21 -03:00
Cauê Faleiros
22a1228a60 fix: resolve login persistence bug and aggressive logout on network blips
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m58s
- Updated Login.tsx to automatically redirect users to the dashboard if a valid token is already present in localStorage.

- Refactored getUserById to properly throw server/network errors instead of silently returning undefined.

- Updated AuthGuard in App.tsx to gracefully handle network errors without destroying the user's valid localStorage tokens.
2026-03-17 15:40:13 -03:00
Cauê Faleiros
f884f6dc3c fix: resolve date range picker timezone offset bug
All checks were successful
Build and Deploy / build-and-push (push) Successful in 56s
- Fixed a bug where selecting a date in the native date picker resulted in the previous day being selected due to the browser converting the 'YYYY-MM-DD' string to UTC midnight and then shifting it back to local time (e.g. UTC-3 in Brazil).

- Explicitly parsed the date string and constructed the Date object using local time coordinates to ensure visual and data consistency.
2026-03-17 14:12:20 -03:00
Cauê Faleiros
a6686c6f7c style: force brazilian locale formatting on all date pickers
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m4s
- Updated the DateRangePicker component to visually display dates in DD/MM/YYYY format using a focus/blur technique, overriding the browser's default OS language formatting.
2026-03-17 13:40:29 -03:00
Cauê Faleiros
96cfb3d125 refactor: remove mock data and finalize n8n data schema
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m50s
- Removed all hardcoded MOCK_ATTENDANCES, USERS, and TENANTS generators from constants.ts since the system is now production-ready.

- Renamed 'summary' to 'title' in the database and across all frontend components for clarity.

- Added 'full_summary' to the attendances schema to explicitly store the large, detailed AI analysis texts from n8n.

- Updated the 'Resumo da Interação' UI to render the 'full_summary' without adding any artificial filler text.

- Localized all dates and times across the dashboard to Brazilian formatting (pt-BR).
2026-03-17 12:45:15 -03:00
Cauê Faleiros
baa1bd66f6 fix: resolve sidebar active state bug and update navigation labels
- Added 'end' prop to NavLink in SidebarItem to ensure exact route matching.

- Renamed 'Integrações (API)' to 'Integrações' for a cleaner UI.
2026-03-16 14:49:37 -03:00
Cauê Faleiros
fbf3edb7a1 feat: migrate api key management to dedicated super admin page
- Extracted API Key generation and management from UserProfile to a new /super-admin/api-keys route.

- Added cross-tenant selection in the new ApiKeys page so Super Admins can manage integrations for any organization.
2026-03-16 14:44:16 -03:00
Cauê Faleiros
ef6d1582b3 feat: implement n8n api integration endpoints and api key management
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m6s
- Added api_keys table to database schema.

- Added API Key authentication middleware to express router.

- Created GET /api/integration/users endpoint for n8n to map agents.

- Created POST /api/integration/attendances endpoint to accept webhooks from n8n.

- Added UI in UserProfile (for Admins/Owners) to generate, view, and revoke API keys.
2026-03-16 14:29:21 -03:00
Cauê Faleiros
2ae0e9fdac docs: add n8n api integration to roadmap priority
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m54s
2026-03-16 14:04:05 -03:00
Cauê Faleiros
76c974bcd0 fix: integrate final user-provided notification sound and clean up unused assets
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m4s
- Replaced placeholder audio with the requested high-quality sound file.

- Removed deprecated audio files from the public directory.
2026-03-16 11:03:35 -03:00
Cauê Faleiros
b2f75562e7 fix: resolve notification routing bug, audio playback format, and backend 500 errors
- Fixed audio playback by downloading a valid mp3 file and importing it directly via Vite.

- Fixed the route collision where DELETE /notifications/clear-all was being captured by /notifications/:id.

- The notification badge now automatically clears (optimistic UI update) when the tray is opened.

- The backend no longer throws a 500 error when querying users during impersonation handoffs.
2026-03-13 16:33:44 -03:00
Cauê Faleiros
750ad525c8 fix: resolve notification ui bugs, audio playback, and team deletion
- Fixed audio playback by rendering a hidden audio tag to comply with browser policies.

- Renamed DELETE /notifications to /notifications/clear-all to prevent route conflicts.

- Notifications badge now clears automatically when the tray is opened.

- Translated notification types to Portuguese (SUCESSO, AVISO, ERRO, INFO).

- Implemented team deletion functionality for Admins.
2026-03-13 15:52:27 -03:00
Cauê Faleiros
4b0d84f2a0 style: rename 'Meus Funis' to 'Gerenciar Funis'
- Updated sidebar navigation and page title to accurately reflect the management nature of the funnels page.
2026-03-13 15:00:14 -03:00
Cauê Faleiros
ea8441d4be feat: implement advanced funnel management with multiple funnels and team assignments
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m32s
- Updated DB schema to support multiple funnels (funnels table) and their stages (funnel_stages table).

- Added funnel_id to teams table to link teams to specific funnels.

- Redesigned /admin/funnels page ('Meus Funis') to allow creating multiple funnels, managing their stages, and assigning them to teams.

- Updated Dashboard, UserDetail, and AttendanceDetail to dynamically load the correct funnel based on the selected team or user's assigned team.
2026-03-13 14:19:52 -03:00
Cauê Faleiros
7ab54053db feat: implement customizable funnel stages per tenant
- Modified attendances.funnel_stage in DB from ENUM to VARCHAR.

- Created tenant_funnels table and backend API routes to manage custom stages.

- Added /admin/funnels page for Admins/Managers to create, edit, order, and color-code their funnel stages.

- Updated Dashboard, UserDetail, and AttendanceDetail to fetch and render dynamic funnel stages instead of hardcoded enums.

- Added defensive checks and logging to GET /users/:idOrSlug to fix sporadic 500 errors during impersonation handoffs.
2026-03-13 10:25:23 -03:00
Cauê Faleiros
1d49161a05 fix: block race condition causing logout during impersonation handoff
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m31s
- Introduced isReloadingForImpersonation flag to temporarily disable the logout function while tokens are being swapped before the hard reload.
2026-03-11 15:49:03 -03:00
Cauê Faleiros
bf157687d4 fix: resolve race conditions during impersonation handoff by reloading directly from dataService 2026-03-11 15:33:38 -03:00
Cauê Faleiros
7cb78f13c0 fix: pad base64 string when parsing jwt during impersonation exit
- Prevented the browser's atob() function from throwing a 'String contains an invalid character' exception by adding proper Base64 padding to the JWT payload before decoding.
2026-03-11 15:13:19 -03:00
Cauê Faleiros
684b98bd0e fix: resolve HashRouter reload issues during impersonation handoffs
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m2s
- Updated Layout and SuperAdmin to explicitly set window.location.hash before triggering window.location.reload() to guarantee correct routing after state resets.
2026-03-11 14:54:35 -03:00
Cauê Faleiros
89f250a43b fix: correct redirect url when exiting impersonation mode
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m3s
- Now correctly routes the Super Admin back to /#/super-admin instead of the standard root dashboard.
2026-03-11 14:42:04 -03:00
Cauê Faleiros
671633b813 style: remove hover requirement for action buttons across all tables
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m6s
- Action buttons (Edit, Delete, Impersonate) are now permanently visible for better UX and discoverability.
2026-03-11 14:37:23 -03:00
Cauê Faleiros
bff54def9f fix: include missing files for tenant impersonation feature
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m7s
- Added backend impersonate endpoint.

- Added frontend impersonate button and functions.

- Fixed build failure by including missing exported functions in dataService.ts.
2026-03-11 14:16:41 -03:00
Cauê Faleiros
b7f9efd0d1 feat: implement tenant impersonation for super admins
Some checks failed
Build and Deploy / build-and-push (push) Failing after 1m38s
- Added POST /api/impersonate/:tenantId to generate a specialized tenant-scoped JWT.

- Added UI button in SuperAdmin page to trigger impersonation.

- Saved original super_admin token to localStorage to allow returning without re-login.

- Added 'Retornar ao Painel Central' button in sidebar to quickly revert to super admin status.
2026-03-10 16:20:06 -03:00
Cauê Faleiros
ee3b9f4ce6 feat: add loading animation to tenant creation button
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m10s
- Implemented isSaving state in SuperAdmin to provide visual feedback during organization creation and updates.
2026-03-10 15:10:44 -03:00
Cauê Faleiros
ab35cf9126 fix: resolve smtp authentication error and notification issues
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m12s
- Stripped literal quotes from SMTP credentials in nodemailer config to prevent '535 Incorrect auth data' in Docker Swarm.

- Reduced notification polling interval from 60s to 10s for real-time updates.

- Fixed browser autoplay block for audio notifications by properly initializing the audio context.
2026-03-10 14:37:24 -03:00
Cauê Faleiros
d3587344a3 fix: resolve notification sound autoplay block and polling delay
- Prevented sound from triggering on initial page load.

- Confirmed polling interval is set to 10 seconds for real-time alerts.
2026-03-10 11:09:03 -03:00
Cauê Faleiros
754c1e2a21 feat: add user preference for audio notifications and play sound on new alerts
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m53s
- Added sound_enabled column to users table with a default of true.

- Implemented a pleasant pop sound (notification.mp3) that plays when a new unread notification arrives.

- Added a toggle in the User Profile page allowing users to enable/disable the sound.
2026-03-10 10:38:03 -03:00
Cauê Faleiros
ccbba312bb feat: implement persistent notification system
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m38s
- Added notifications table with auto-migration on startup.

- Created backend endpoints for fetching and managing notifications.

- Implemented interactive notification tray in the header with unread badges.

- Added automated triggers for organization creation and user registration completion.
2026-03-09 17:08:41 -03:00
Cauê Faleiros
ec7cb18928 feat: customize search placeholder based on user role
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m10s
- Agents see 'Buscar atendimentos...'

- Super admins see 'Buscar membros, equipes, atendimentos ou organizações...'

- Admin and managers see 'Buscar membros, equipes ou atendimentos...'
2026-03-09 16:29:41 -03:00
Cauê Faleiros
12d24e9255 feat: refine global search RBAC and fix image loading
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m24s
- Restricted Agent search to Attendances only.

- Enabled Super Admin search for Organizations (Tenants).

- Fixed user avatar URL construction in search results.

- Added Organizations category to search dropdown for Super Admins.
2026-03-09 16:09:41 -03:00
Cauê Faleiros
13bcfc1314 feat: enhance global search UI and positioning
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m55s
- Moved search bar to the left/center for better accessibility.

- Increased search bar width to max-w-2xl.

- Refined search results dropdown layout and styling.
2026-03-09 15:54:49 -03:00
Cauê Faleiros
c07967188a feat: implement categorized global search with RBAC
- Added /api/search endpoint with strict role-based data isolation.

- Created searchGlobal function in dataService.

- Refined header UI with an interactive, categorized search results dropdown.
2026-03-09 15:25:12 -03:00
Cauê Faleiros
000bc38712 fix: remove duplicated layout titles and use singular team terminology for managers
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m48s
2026-03-09 11:07:18 -03:00
Cauê Faleiros
56b1f0c884 fix: sanitize rbac error msg and enforce manager creation constraints
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m8s
- Prevented API error messages from leaking system roles.

- Updated POST /users to safely allow managers to create users while strictly forcing them to be agents assigned to the manager's team.
2026-03-09 10:15:16 -03:00
Cauê Faleiros
3481e698bc fix: change sidebar label to 'Meu Time' for managers
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m10s
2026-03-06 16:34:54 -03:00
Cauê Faleiros
0d3ce93e32 fix: populate slugs for old users and include slug/team_id in jwt token
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m53s
2026-03-06 16:15:16 -03:00
Cauê Faleiros
feb98d830b fix: resolve sql query logic preventing managers from seeing themselves or their team if team_id is null
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m2s
2026-03-06 15:26:10 -03:00