Skip to content

feat: fixed pdf download with improved functionality#1427

Open
madsysharma wants to merge 1 commit into
viru0909-dev:mainfrom
madsysharma:feat/pdf-download
Open

feat: fixed pdf download with improved functionality#1427
madsysharma wants to merge 1 commit into
viru0909-dev:mainfrom
madsysharma:feat/pdf-download

Conversation

@madsysharma

@madsysharma madsysharma commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Pull Request

feat: multi-language, error handling, and a11y for Constitution PDF download

Closes #666

Description

The "Download PDF" button on the Constitution page does work, but only for English and Hindi: and it gives the user no feedback. This PR bridges such remaining gaps in that feature:

  • Multi-language behaviour. the app ships locales for Telugu, Tamil, and Marathi, but only English and Hindi Constitution PDFs exist in public/documents. Previously, te/ta/mr users silently received the English PDF with no explanation. Now they get a brief notice that the PDF is currently available only in English and Hindi, and the English version is downloaded: so there is no silent surprise.
  • Real error handling. the download now fetches the file as a Blob, so a missing file or network failure surfaces a clear error toast instead of a dead, no-op anchor click.
  • User feedback. a loading toast and a disabled button with a spinner are shown while the file downloads (the Hindi PDF is ~19 MB, so this matters on slower connections), followed by a success or error toast. The button is also guarded against double-clicks.
  • Accessibility. the button gets an aria-label and aria-busy, and the loader actually animates now (the page's existing animate-spin class was a no-op because no stylesheet defined it).
  • Cleanup & testability. the download logic is extracted into a small, unit-tested helper, and the stale pdfComingSoon i18n key (which still said "coming soon") is retired.

Note: the core button was already made functional in #873; this builds on top of that rather than re-implementing it.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change
  • This change requires a documentation update

Testing

PS C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend> npx vitest run src/utils/downloadConstitutionPdf.test.js

 RUN  v3.2.6 C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend

stderr | src/utils/downloadConstitutionPdf.test.js > downloadConstitutionPdf > reports an error toast (and does not click) when the fetch fails
[Constitution] PDF download failed: Error: Failed to fetch /documents/COI_MAY2024.pdf: 404
    at Module.downloadConstitutionPdf (C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend\src\utils\downloadConstitutionPdf.js:79:19)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend\src\utils\downloadConstitutionPdf.test.js:120:24
    at file:///C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend/node_modules/@vitest/runner/dist/chunk-hooks.js:752:20

stderr | src/utils/downloadConstitutionPdf.test.js > downloadConstitutionPdf > reports an error toast when the network request rejects
[Constitution] PDF download failed: Error: network down
    at C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend\src\utils\downloadConstitutionPdf.test.js:128:48
    at mockCall (file:///C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend/node_modules/@vitest/spy/dist/index.js:96:15)
    at spy (file:///C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend/node_modules/tinyspy/dist/index.js:47:80)
    at Module.downloadConstitutionPdf (C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend\src\utils\downloadConstitutionPdf.js:77:32)
    at run (C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend\src\utils\downloadConstitutionPdf.test.js:82:9)
    at C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend\src\utils\downloadConstitutionPdf.test.js:129:30
    at file:///C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend/node_modules/@vitest/runner/dist/chunk-hooks.js:155:11
    at file:///C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend/node_modules/@vitest/runner/dist/chunk-hooks.js:752:26
    at file:///C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend/node_modules/@vitest/runner/dist/chunk-hooks.js:1897:20
    at new Promise (<anonymous>)

 ✓ src/utils/downloadConstitutionPdf.test.js (10 tests) 47ms
   ✓ resolvePdfLang > returns the base code for supported languages 2ms
   ✓ resolvePdfLang > normalises region-suffixed codes (en-US, hi-IN) 0ms
   ✓ resolvePdfLang > returns null for languages without a shipped PDF 0ms
   ✓ resolvePdfLang > falls back gracefully on empty/undefined input 0ms
   ✓ downloadConstitutionPdf > downloads the English PDF when the language is English 8ms
   ✓ downloadConstitutionPdf > downloads the Hindi PDF when the language is Hindi 1ms
   ✓ downloadConstitutionPdf > falls back to English and notifies the user for unsupported languages 4ms
   ✓ downloadConstitutionPdf > does not show the fallback notice for supported languages 1ms
   ✓ downloadConstitutionPdf > reports an error toast (and does not click) when the fetch fails 22ms
   ✓ downloadConstitutionPdf > reports an error toast when the network request rejects 4ms

 Test Files  1 passed (1)
      Tests  10 passed (10)
   Start at  15:08:41
   Duration  3.61s (transform 82ms, setup 0ms, collect 153ms, tests 47ms, environment 2.55s, prepare 296ms)
PS C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend> npx vitest run

 RUN  v3.2.6 C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend

 ✓ src/utils/streamResilience.test.js (5 tests) 17ms
 ✓ src/layouts/Sidebar.adminRoutes.test.js (1 test) 9ms
 ✓ src/store/authStore.test.js (8 tests) 23ms
 ✓ src/services/NotificationService.test.js (1 test) 18ms
stderr | src/utils/downloadConstitutionPdf.test.js > downloadConstitutionPdf > reports an error toast (and does not click) when the fetch fails
[Constitution] PDF download failed: Error: Failed to fetch /documents/COI_MAY2024.pdf: 404
    at Module.downloadConstitutionPdf (C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend\src\utils\downloadConstitutionPdf.js:79:19)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend\src\utils\downloadConstitutionPdf.test.js:120:24
    at file:///C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend/node_modules/@vitest/runner/dist/chunk-hooks.js:752:20

stderr | src/utils/downloadConstitutionPdf.test.js > downloadConstitutionPdf > reports an error toast when the network request rejects
[Constitution] PDF download failed: Error: network down
    at C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend\src\utils\downloadConstitutionPdf.test.js:128:48
    at mockCall (file:///C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend/node_modules/@vitest/spy/dist/index.js:96:15)
    at spy (file:///C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend/node_modules/tinyspy/dist/index.js:47:80)
    at Module.downloadConstitutionPdf (C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend\src\utils\downloadConstitutionPdf.js:77:32)
    at run (C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend\src\utils\downloadConstitutionPdf.test.js:82:9)
    at C:\Users\madhu\Documents\nyay-setu-working\frontend\nyaysetu-frontend\src\utils\downloadConstitutionPdf.test.js:129:30
    at file:///C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend/node_modules/@vitest/runner/dist/chunk-hooks.js:155:11
    at file:///C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend/node_modules/@vitest/runner/dist/chunk-hooks.js:752:26
    at file:///C:/Users/madhu/Documents/nyay-setu-working/frontend/nyaysetu-frontend/node_modules/@vitest/runner/dist/chunk-hooks.js:1897:20
    at new Promise (<anonymous>)

 ✓ src/utils/downloadConstitutionPdf.test.js (10 tests) 75ms
 ✓ src/components/__tests__/BackToTop.test.jsx (3 tests) 586ms
   ✓ BackToTop > is hidden when page is at top  506ms
 ✓ src/contexts/LanguageContext.test.jsx (8 tests) 619ms
   ✓ LanguageProvider > updates static text to Hindi after toggleLanguage without page reload  397ms
 ✓ src/__tests__/xss.test.jsx (2 tests) 105ms
 ✓ src/pages/police/MyFirsPage.test.jsx (1 test) 444ms
   ✓ MyFirsPage > opens the registered investigation detail route when a FIR card is clicked  440ms
stdout | src/pages/litigant/FileUnifiedPage.test.jsx
[api.js] Using API_BASE_URL: http://localhost:8080

 ✓ src/pages/ResetPassword.test.jsx (1 test) 818ms
   ✓ ResetPassword > uses versioned auth endpoints to verify and reset the password  814ms
 ✓ src/pages/lawyer/AILegalAssistantPage.test.jsx (1 test) 673ms
   ✓ AILegalAssistantPage E2E Integration Test > renders user query and correctly formats deterministic markdown response from AI backend  668ms
 ✓ src/pages/judge/LiveHearing.test.jsx (2 tests) 1330ms
   ✓ LiveHearing Accessibility Verification > Dashboard layout structure matches basic screen reader role expectations  913ms
   ✓ LiveHearing Accessibility Verification > Active hearing workspace contains accessible navigation controls  413ms
stderr | src/pages/litigant/FileUnifiedPage.test.jsx > FileUnifiedPage > preserves form state when navigating backwards
react-i18next:: useTranslation: You will need to pass in an i18next instance by using initReactI18next { code: 'NO_I18NEXT_INSTANCE' }

 ✓ src/pages/litigant/FileUnifiedPage.test.jsx (1 test) 889ms
   ✓ FileUnifiedPage > preserves form state when navigating backwards  884ms
 ✓ src/pages/litigant/CaseDetailPage.test.jsx (1 test) 807ms
   ✓ CaseDetailPage timeline > loads timeline data from versioned timeline and case event endpoints  804ms
 ✓ src/pages/litigant/DocumentGeneratePage.test.jsx (4 tests) 3521ms
   ✓ DocumentGeneratePage > renders backend validation errors for missing fields  1177ms
   ✓ DocumentGeneratePage > shows prompt-injection warnings from backend error responses  510ms
   ✓ DocumentGeneratePage > copies generated content and calls DOCX export actions  1073ms
   ✓ DocumentGeneratePage > downloads PDF and handles filename and blob flow  756ms

 Test Files  15 passed (15)
      Tests  49 passed (49)
   Start at  15:09:21
   Duration  12.51s (transform 4.19s, setup 0ms, collect 28.41s, tests 9.93s, environment 64.74s, prepare 7.89s)
  • npm run build compiles the Constitution changes cleanly.
  • Manual: English download works; switching to Hindi downloads the Hindi PDF; Telugu/Tamil/Marathi show the fallback notice and download English; simulated fetch failure shows the error toast; button is disabled with a spinner during download.

Screenshots / Videos

Marathi

Screen.Recording.2026-06-18.174618.mp4
Screenshot 2026-06-18 174815

Tamil

Screen.Recording.2026-06-18.174930.mp4
Screenshot 2026-06-18 175018

Telugu

Screen.Recording.2026-06-18.175118.mp4
Screenshot 2026-06-18 175224

Breaking Changes

None.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes

Reviewer notes

  • The te/ta/mr strings are careful translations but would benefit from a native-speaker check: happy to adjust accordingly.
  • As a native Kannada speaker, I would be happy to integrate support for fellow Kannada speakers.
  • Out of scope but worth a mention: src/pages/Login.jsx had a duplicate react-router-dom import on main that breaks npm run build for the whole app. It's unrelated to this PR, but have included the relevant fixes here.

@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

@madsysharma is attempting to deploy a commit to the CodeBlooded's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @madsysharma, thanks for contributing to Nyay Setu! 🎉

I have automatically:

  • 👤 Assigned this PR to you.
  • 🏷️ Applied the gssoc:approved label.

Our workflows will now analyze your changes to classify:

  • 📈 PR Difficulty: level:*
  • 🧩 PR Type: type:*
  • 🌟 PR Quality: quality:*

Tip

Ensure your PR description references the issue it resolves (e.g. Closes #123). This allows the bot to inherit any additional labels from that issue!

Happy coding! 🚀

@madsysharma

Copy link
Copy Markdown
Contributor Author

Hi @viru0909-dev , please review this PR. Thank you.

@viru0909-dev viru0909-dev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

⚠️ Critical DB Migration Issue

This PR includes dangerous renames of existing Flyway migrations (V51 to V52, V52 to V53, etc.).
Renaming migrations that have already been executed breaks Flyway checksums, which will cause the application to crash on startup for anyone pulling these changes (including our CI/CD pipelines and production DB).

Additionally, this PR includes unrelated changes to SecurityConfig, AuditLogRepository, and CaseRepository which do not align with the PR title (fixing PDF download).

Please revert all migration renames and isolate this PR to only contain the PDF download fix.

@madsysharma

Copy link
Copy Markdown
Contributor Author

Hi @viru0909-dev , have made the changes you requested for, and have updated the PR. Please review it. Thank you.

@viru0909-dev viru0909-dev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

PR modifies App.jsx and inadvertently removes component lazy loading imports. Please restrict changes to Constitution.jsx and the download utility.

@madsysharma

Copy link
Copy Markdown
Contributor Author

Hi @viru0909-dev , have included only the necessary changes. Please review this updated PR.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Fix] Implement Functional Constitution PDF Download

2 participants