Skip to content
This repository was archived by the owner on Jul 7, 2026. It is now read-only.

feat(admin): load pedidos asynchronously#190

Merged
marpisco merged 4 commits into
mainfrom
codex/add-asynchronous-loading-for-pedidos-list
Jul 5, 2026
Merged

feat(admin): load pedidos asynchronously#190
marpisco merged 4 commits into
mainfrom
codex/add-asynchronous-loading-for-pedidos-list

Conversation

@marpisco

@marpisco marpisco commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Remove the initial page-load animation class that affects the pedidos list and provide a faster, non-blocking UX for administrators.
  • Provide focused API endpoints to fetch filtered/paginated reservation requests and to approve/reject requests programmatically while reusing the app's existing auth/session/CSRF patterns.
  • Keep the existing server-side behavior as a non-JavaScript fallback and preserve current email notification and logging behavior for approvals/rejections.

Description

  • Add admin/api/pedidos_list.php which returns authenticated, paginated, filtered reservation records (sala / requisitor) with prepared statements and the same session/auth guards used by other admin APIs.
  • Add admin/api/pedidos_action.php which accepts CSRF-protected POSTs to aprovar / rejeitar single or bulk reservations, performs DB updates/deletes, logs actions via logaction, and invokes the existing email helpers for notifications.
  • Update admin/pedidos.php to stop applying the fade-in class on initial load, add skeleton styling, wrap the server-rendered pedidos area in #pedidosResults and #pedidosAlerts, and inject client-side JS that intercepts filter submissions, shows skeleton rows while loading, fetches page 1 via AJAX from pedidos_list.php, appends more results on scroll via a page parameter, and submits approve/reject (single and bulk) via pedidos_action.php while falling back to the original form/URL when network/JS handling fails.
  • Preserve CSRF handling by reading the global-csrf-token hidden value and including it in programmatic requests, and reuse the existing sendReservationApprovedEmail, sendReservationRejectedEmail, sendBulkReservationApprovedEmail, and sendBulkReservationRejectedEmail helpers for notifications.

Testing

  • Ran PHP syntax checks: php -l admin/pedidos.php, php -l admin/api/pedidos_list.php, and php -l admin/api/pedidos_action.php, all reporting no syntax errors.
  • Ran git diff --check to verify whitespace/format issues and fixed trailing whitespace reported by the check.
  • Verified added files pass the same session/auth/CSRF guard patterns used by existing admin APIs by mirroring checks from admin/api/dashboard_stats.php and admin/api/users_search.php.

Codex Task

Copilot AI review requested due to automatic review settings July 5, 2026 02:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

📝 Manual Update Required? It looks like you've modified core logic. Please check if the user manual needs a refresh! @marpisco

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be69d0934c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread admin/pedidos.php Outdated
Comment thread admin/pedidos.php Outdated
Comment thread admin/pedidos.php Outdated
Comment thread admin/api/pedidos_list.php Outdated
Comment thread admin/pedidos.php
Comment thread admin/pedidos.php Outdated
Comment thread admin/pedidos.php Outdated
Comment thread admin/pedidos.php Outdated
Comment thread admin/api/pedidos_action.php
Resolves the main merge conflict in the pedidos admin page while keeping the current admin shell layout and the async loading skeleton.

Fixes the async pedidos review findings by moving rendered row actions off fragile inline handlers, preserving server-rendered action results, surfacing email warnings, refreshing stats, searching through the list API, keeping pagination deterministic, replacing stale filter loads, and preserving single-reservation email templates.

Tested with git diff --check, git diff --cached --check, PHP lint on admin/pedidos.php and both pedidos API endpoints, and node --check on the extracted inline pedidos script.

Co-authored-by: Codex <noreply@openai.com>
@marpisco marpisco force-pushed the codex/add-asynchronous-loading-for-pedidos-list branch from be69d09 to 05a122b Compare July 5, 2026 03:24
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

📝 Manual Update Required? It looks like you've modified core logic. Please check if the user manual needs a refresh! @marpisco

@marpisco

marpisco commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

@codex
Minor detail,

Search box is also reloaded, so if I'm typing, it'll remove my focus from the searchbox,

Also, since it's being reloaded, if I type something that has no results, it'll make the searchbox disappear and force me to have to reload the entire page.

@chatgpt-codex-connector

Copy link
Copy Markdown

Summary

Testing

  • php -l admin/pedidos.php
  • git diff --check

View task →

Copilot AI review requested due to automatic review settings July 5, 2026 03:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

📝 Manual Update Required? It looks like you've modified core logic. Please check if the user manual needs a refresh! @marpisco

Moves the async pedidos empty-state container below the search and bulk controls so the controls stay first when a search has no results. This keeps the previous focus-preservation behavior while matching the expected layout.

Tested with php -l admin/pedidos.php and git diff --check.

Co-authored-by: Codex <noreply@openai.com>
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

📝 Manual Update Required? It looks like you've modified core logic. Please check if the user manual needs a refresh! @marpisco

Moves the AJAX pedidos search field into a stable header, matching the simple form-control search used on the salas page. The async renderer now updates only the results area, so typing does not lose focus or trigger the blue focus flicker when new data arrives.

Shows the existing loading spinner during focused search reloads instead of replacing the search input. The server-side fallback remains hidden from the async header when an action result is being shown.

Tested with php -l admin/pedidos.php and git diff --check.

Co-authored-by: Codex <noreply@openai.com>
Copilot AI review requested due to automatic review settings July 5, 2026 03:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

📝 Manual Update Required? It looks like you've modified core logic. Please check if the user manual needs a refresh! @marpisco

@marpisco marpisco left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@marpisco marpisco merged commit f77772e into main Jul 5, 2026
6 checks passed
@marpisco marpisco deleted the codex/add-asynchronous-loading-for-pedidos-list branch July 5, 2026 03:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 10ae7e7faf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

echo json_encode(['error' => 'Acesso negado.']);
exit;
}
if (!isset($_SESSION['validity']) || $_SESSION['validity'] < time()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Extend sessions for async pedidos requests

When admins keep this page open and interact only through the new async list/action endpoints, these requests bypass admin/index.php, where near-expiry sessions are extended by another 30 minutes. This guard only rejects once validity is in the past, so an actively filtering/scrolling admin can still be logged out as soon as the original timestamp expires; mirror the sliding-session refresh in the API auth path as well.

Useful? React with 👍 / 👎.

Comment thread admin/pedidos.php
const hasServerAction = new URLSearchParams(window.location.search).has('subaction');
if (!hasServerAction) {
document.getElementById('pedidosAsyncHeader')?.classList.remove('d-none');
loadPedidos(true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip full server render before async fetch

On /admin/pedidos.php without subaction, this async fetch starts only after the PHP default branch above has already queried and emitted every pending reservation, including the per-row sala/cache/tempo lookups. Installations with many pending requests now pay the full old render plus an extra API request before the browser replaces it, so the new pagination does not protect the initial load; gate the server-side table to a fallback/no-JS path or leave the container empty for the async path.

Useful? React with 👍 / 👎.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants