Skip to content

Comments

INJIWEB-1667 Success message will appear after downloading VC's#501

Open
sanehema9 wants to merge 3 commits intoinji:developfrom
sanehema9:inji-1667
Open

INJIWEB-1667 Success message will appear after downloading VC's#501
sanehema9 wants to merge 3 commits intoinji:developfrom
sanehema9:inji-1667

Conversation

@sanehema9
Copy link

@sanehema9 sanehema9 commented Jan 20, 2026

Description

Fixed an issue where the VC download success message was not displayed immediately after logging in with Google. The success toast now appears as soon as the VC download is completed, without requiring navigation to the Home or Stored Cards page.

Files Changed

RedirectionPage

Issue TicketNumber and Link

INJIWEB-1667(https://mosip.atlassian.net/browse/INJIWEB-1667)

Video

INJIWEB-1667.mp4

Summary by CodeRabbit

  • Bug Fixes
    • Added toast notifications to clearly indicate success or failure after download attempts.
    • Ensured download completion state is consistently set for both logged-in and guest flows, improving feedback and reliability during credential downloads.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: sanehema9 <sanehema9@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

Walkthrough

Reworked RedirectionPage to remove automatic navigation and surface download outcomes via localized toast notifications; both logged-in and guest download flows now mark completion on both success and error, triggering a toast effect when completedDownload becomes true.

Changes

Cohort / File(s) Summary
RedirectionPage (notification & flow changes)
inji-web/src/pages/RedirectionPage.tsx
Added showToast import and tLayout translation hook. Removed navigate(ROUTES.USER_ISSUER(issuerId)). Ensured setCompletedDownload(true) is called on both success and error paths for logged-in and guest download flows. Added a useEffect that, when completedDownload becomes true, shows a localized success or error toast based on vcDownload state. Updated useEffect dependency list to include completedDownload, vcDownloadApi.state, credentialType, and credentialTypeDisplayObj.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • jackjain

Poem

🐰 I hopped in, swapped a redirect for cheer,
Now toasts trumpet outcomes far and near.
Success or fail, the message is clear,
A bunny-approved update — hip hip, hooray! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a success message display after VC download completes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
inji-web/src/pages/RedirectionPage.tsx (1)

29-30: Prevent duplicate/incorrect toasts by persisting the outcome at the time of response.

The concern is valid. When vcDownloadApi.fetchData() completes, it returns the response immediately but queues state updates asynchronously. In handleLoggedInDownloadFlow and handleGuestDownloadFlow, setCompletedDownload(true) is called before React processes the setState() calls from useApi, meaning vcDownloadApi.state doesn't reflect the actual outcome yet.

The useEffect (lines 111–123) depends on both completedDownload and vcDownloadApi.state, so it will fire again when vcDownloadApi.state updates asynchronously, potentially showing a duplicate or incorrect toast. Capture the outcome ('success' | 'error' | null) immediately when the response resolves, use it solely for the toast decision, then clear it to prevent re-runs.

Suggested fix
- const [completedDownload, setCompletedDownload] = useState<boolean>(false);
+ const [completedDownload, setCompletedDownload] = useState<boolean>(false);
+ const [downloadOutcome, setDownloadOutcome] = useState<'success' | 'error' | null>(null);

  const handleLoggedInDownloadFlow = async (issuerId: string, requestBody: TokenRequestBody) => {
    const downloadId = addSession(credentialTypeDisplayObj, RequestStatus.LOADING);
    const credentialDownloadResponse = await vcDownloadApi.fetchData({
      body: requestBody,
      apiConfig: api.downloadVCInloginFlow,
      headers: api.downloadVCInloginFlow.headers(language)
    });

    if (credentialDownloadResponse.ok()) {
      updateSession(downloadId, RequestStatus.DONE)
+     setDownloadOutcome('success');
      setCompletedDownload(true);
    } else {
      updateSession(downloadId, RequestStatus.ERROR)
+     setDownloadOutcome('error');
      setCompletedDownload(true);
    }
  }

  const handleGuestDownloadFlow = async (requestBody: TokenRequestBody) => {
    const urlState = searchParams.get('state') ?? '';
    const credentialDownloadResponse = await vcDownloadApi.fetchData({
      body: requestBody,
      apiConfig: api.fetchTokenAnddownloadVc
    })

    if (credentialDownloadResponse.state !== RequestStatus.ERROR) {
      await downloadCredentialPDF(
        credentialDownloadResponse.data,
        credentialType + ".pdf"
      );
+     setDownloadOutcome('success');
      setCompletedDownload(true);
    } else {
+     setDownloadOutcome('error');
      setCompletedDownload(true);
    }
    ...
  }

  useEffect(() => {
-   if (completedDownload) {
-     const isError = vcDownloadApi.state === RequestStatus.ERROR;
+   if (downloadOutcome) {
+     const isError = downloadOutcome === 'error';
      showToast({
        message: i18next.t(`VCDownload.${isError ? 'error' : 'success'}`, {
          ns: 'Layout',
          cardType: credentialTypeDisplayObj?.[0]?.name || credentialType
        }),
        type: isError ? 'error' : 'success',
        testId: `download-${isError ? 'error' : 'success'}-toast`
      });
+     setDownloadOutcome(null);
    }
- }, [completedDownload, vcDownloadApi.state, credentialType, credentialTypeDisplayObj]);
+ }, [downloadOutcome, credentialType, credentialTypeDisplayObj]);

Applies to: lines 37–51, 54–69, 111–123

@sanehema9
Copy link
Author

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)

inji-web/src/pages/RedirectionPage.tsx (1)> 29-30: Prevent duplicate/incorrect toasts by persisting the outcome at the time of response.

The concern is valid. When vcDownloadApi.fetchData() completes, it returns the response immediately but queues state updates asynchronously. In handleLoggedInDownloadFlow and handleGuestDownloadFlow, setCompletedDownload(true) is called before React processes the setState() calls from useApi, meaning vcDownloadApi.state doesn't reflect the actual outcome yet.
The useEffect (lines 111–123) depends on both completedDownload and vcDownloadApi.state, so it will fire again when vcDownloadApi.state updates asynchronously, potentially showing a duplicate or incorrect toast. Capture the outcome ('success' | 'error' | null) immediately when the response resolves, use it solely for the toast decision, then clear it to prevent re-runs.

Suggested fix

- const [completedDownload, setCompletedDownload] = useState<boolean>(false);
+ const [completedDownload, setCompletedDownload] = useState<boolean>(false);
+ const [downloadOutcome, setDownloadOutcome] = useState<'success' | 'error' | null>(null);

  const handleLoggedInDownloadFlow = async (issuerId: string, requestBody: TokenRequestBody) => {
    const downloadId = addSession(credentialTypeDisplayObj, RequestStatus.LOADING);
    const credentialDownloadResponse = await vcDownloadApi.fetchData({
      body: requestBody,
      apiConfig: api.downloadVCInloginFlow,
      headers: api.downloadVCInloginFlow.headers(language)
    });

    if (credentialDownloadResponse.ok()) {
      updateSession(downloadId, RequestStatus.DONE)
+     setDownloadOutcome('success');
      setCompletedDownload(true);
    } else {
      updateSession(downloadId, RequestStatus.ERROR)
+     setDownloadOutcome('error');
      setCompletedDownload(true);
    }
  }

  const handleGuestDownloadFlow = async (requestBody: TokenRequestBody) => {
    const urlState = searchParams.get('state') ?? '';
    const credentialDownloadResponse = await vcDownloadApi.fetchData({
      body: requestBody,
      apiConfig: api.fetchTokenAnddownloadVc
    })

    if (credentialDownloadResponse.state !== RequestStatus.ERROR) {
      await downloadCredentialPDF(
        credentialDownloadResponse.data,
        credentialType + ".pdf"
      );
+     setDownloadOutcome('success');
      setCompletedDownload(true);
    } else {
+     setDownloadOutcome('error');
      setCompletedDownload(true);
    }
    ...
  }

  useEffect(() => {
-   if (completedDownload) {
-     const isError = vcDownloadApi.state === RequestStatus.ERROR;
+   if (downloadOutcome) {
+     const isError = downloadOutcome === 'error';
      showToast({
        message: i18next.t(`VCDownload.${isError ? 'error' : 'success'}`, {
          ns: 'Layout',
          cardType: credentialTypeDisplayObj?.[0]?.name || credentialType
        }),
        type: isError ? 'error' : 'success',
        testId: `download-${isError ? 'error' : 'success'}-toast`
      });
+     setDownloadOutcome(null);
    }
- }, [completedDownload, vcDownloadApi.state, credentialType, credentialTypeDisplayObj]);
+ }, [downloadOutcome, credentialType, credentialTypeDisplayObj]);

Applies to: lines 37–51, 54–69, 111–123

. I’ve updated the VC download flow to capture the outcome immediately (success or error) and refactored the useEffect to depend only on that outcome. This ensures the toast is shown exactly once, at the right time, and prevents duplicates or delayed messages.

}, []);

useEffect(() => {
if (completedDownload) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add unit tests for the newly added code

if (completedDownload) {
const isError = vcDownloadApi.state === RequestStatus.ERROR;
showToast({
message: i18next.t(`VCDownload.${isError ? 'error' : 'success'}`, {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we please use useTranslation hook instead of i18next ?

@jackjain
Copy link
Contributor

@sanchi-singh24 can you please confirm on the UI design

Signed-off-by: sanehema9 <sanehema9@gmail.com>
@sanehema9 sanehema9 changed the title inji-1667 INJIWEB-1667 Success message will appear after downloading VC's Jan 31, 2026
Signed-off-by: sanehema9 <sanehema9@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
inji-web/src/pages/RedirectionPage.tsx (1)

37-69: ⚠️ Potential issue | 🟠 Major

Toast can fire with the wrong status (or twice) due to async state updates.

completedDownload is set immediately after fetchData resolves, but vcDownloadApi.state can lag. The effect reads vcDownloadApi.state and re-runs when it updates, so you can show a success toast on an error (then later an error toast), or duplicate toasts when state changes. Consider storing the outcome from the response and driving the toast off that, then clearing it after display.

✅ Suggested fix (capture outcome + show toast once)
-    const [completedDownload, setCompletedDownload] = useState<boolean>(false);
+    const [completedDownload, setCompletedDownload] = useState<boolean>(false);
+    const [downloadOutcome, setDownloadOutcome] = useState<'success' | 'error' | null>(null);
@@
-        if (credentialDownloadResponse.ok()) {
+        if (credentialDownloadResponse.ok()) {
             updateSession(downloadId, RequestStatus.DONE)
-            setCompletedDownload(true);
+            setDownloadOutcome('success');
+            setCompletedDownload(true);
         } else {
             updateSession(downloadId, RequestStatus.ERROR)
-            setCompletedDownload(true);
+            setDownloadOutcome('error');
+            setCompletedDownload(true);
         }
@@
-        if (credentialDownloadResponse.state !== RequestStatus.ERROR) {
+        if (credentialDownloadResponse.state !== RequestStatus.ERROR) {
             await downloadCredentialPDF(
                 credentialDownloadResponse.data,
                 credentialType + ".pdf"
             );
-            setCompletedDownload(true);
+            setDownloadOutcome('success');
+            setCompletedDownload(true);
         } else {
-            setCompletedDownload(true);
+            setDownloadOutcome('error');
+            setCompletedDownload(true);
         }
@@
-    useEffect(() => {
-        if (completedDownload) {
-            const isError = vcDownloadApi.state === RequestStatus.ERROR;
+    useEffect(() => {
+        if (downloadOutcome) {
+            const isError = downloadOutcome === 'error';
             showToast({
                 message: tLayout(`VCDownload.${isError ? 'error' : 'success'}`, {
                     cardType: credentialTypeDisplayObj?.[0]?.name || credentialType
                 }),
                 type: isError ? 'error' : 'success',
                 testId: `download-${isError ? 'error' : 'success'}-toast`
             });
+            setDownloadOutcome(null);
         }
-    }, [completedDownload, vcDownloadApi.state, credentialType, credentialTypeDisplayObj]);
+    }, [downloadOutcome, credentialType, credentialTypeDisplayObj, tLayout]);

Also applies to: 111-122

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants