Skip to content

Conversation

@priyanshu6238
Copy link
Collaborator

@priyanshu6238 priyanshu6238 commented Dec 9, 2025

Target issue: #3684

@coderabbitai
Copy link

coderabbitai bot commented Dec 9, 2025

Walkthrough

Adds a new GraphQL mutation SYNC_WHATSAPP_FORM and integrates it into the WhatsApp forms flow. The WhatsAppFormList component now maps and calls the mutation via a new mutation hook, introduces a loading state syncWhatsappFormLoad, adds handleFormUpdates that calls the mutation with organization_id from getUserSession, and renders a secondary "Sync Whatsapp Form" button wired to that handler. Tests and mocks for success and error mutation responses were added.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Changes span UI component, GraphQL mutation file, tests, and mocks — mixed logic and test coverage.
  • Areas to pay extra attention:
    • Correct extraction and shape of organization_id from getUserSession.
    • GraphQL variable name/type (organization_id) matches backend schema.
    • Mutation error handling and Notification calls.
    • Tests' mock wiring for success and error flows.

Possibly related issues

Possibly related PRs

Suggested labels

status: ready for review

Suggested reviewers

  • akanshaaa19
  • shijithkjayan
  • madclaws

Poem

🐰 I hopped through code with eager cheer,
A sync button bright — I gave a nudge,
Mocks lined up and tests drew near,
Messages danced without a judge,
Hooray — the WhatsApp forms now budge! 🎋

Pre-merge checks and finishing touches

✅ 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 contains a typo ('WhatsApp From' instead of 'WhatsApp Form') and describes the main change accurately—adding a sync button to the WhatsApp Forms List page, which aligns with the code changes shown.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/add_sync_button

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e119393 and 2ab1121.

📒 Files selected for processing (2)
  • src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.test.tsx (2 hunks)
  • src/mocks/WhatsAppForm.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.test.tsx
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

⚙️ CodeRabbit configuration file

Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Files:

  • src/mocks/WhatsAppForm.tsx
🧬 Code graph analysis (1)
src/mocks/WhatsAppForm.tsx (1)
src/graphql/mutations/WhatsAppForm.ts (1)
  • SYNC_WHATSAPP_FORM (93-103)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build
  • GitHub Check: glific (1.18.3-otp-27, 27.3.3)
  • GitHub Check: CI
🔇 Additional comments (1)
src/mocks/WhatsAppForm.tsx (1)

1-7: Importing SYNC_WHATSAPP_FORM alongside other WhatsAppForm mutations looks correct

The new import is consistent with existing GraphQL mutation imports and keeps concerns centralized in graphql/mutations/WhatsAppForm.

Please just confirm that SYNC_WHATSAPP_FORM is exported from graphql/mutations/WhatsAppForm with the same name/signature as used here (per the snippet in src/graphql/mutations/WhatsAppForm.ts:92-102).


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.

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

@github-actions github-actions bot temporarily deployed to pull request December 9, 2025 06:00 Inactive
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: 3

🧹 Nitpick comments (2)
src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.tsx (2)

16-16: Remove unused imports.

The useQuery and gql imports are not used anywhere in this file. The SYNC_WHATSAPP_FORM mutation is already imported from the mutations file.

Apply this diff:

-import { useQuery, gql } from '@apollo/client';

101-127: Consider using Apollo's callbacks for consistency.

The current .then/.catch approach works but is inconsistent with other mutations in this file (e.g., publishForm on lines 90-99 uses onCompleted/onError). Apollo's callbacks provide automatic refetch and cache updates.

Consider this refactor:

-  const handleHsmUpdates = () => {
-    setSyncTemplateLoad(true);
-
-    syncWhatsappForm({
+  const [syncWhatsappForm, { loading: syncTemplateLoad }] = useMutation(SYNC_WHATSAPP_FORM, {
+    onCompleted: (res) => {
+      const result = res?.syncWhatsappForm;
+      if (result?.errors?.length) {
+        const errorMessages = result.errors.map((err: any) => err.message).join(', ');
+        setErrorMessage(errorMessages, 'An error occurred');
+      } else {
+        setNotification(result?.message || 'WhatsApp Forms synced successfully');
+      }
+    },
+    onError: (errors) => {
+      setErrorMessage(formatError(errors.message), 'An error occurred');
+    },
+  });
+
+  const handleHsmUpdates = () => {
+    syncWhatsappForm({
       variables: {
         organization_id: getUserSession('organizationId'),
       },
-    })
-      .then((res) => {
-        setSyncTemplateLoad(false);
-
-        const result = res?.data?.syncWhatsappForm;
-        console.log(result, 'result');
-
-        if (result?.errors?.length) {
-          const errorMessages = result.errors.map((err: any) => err.message).join(', ');
-          setErrorMessage(errorMessages, 'An error occurred');
-        } else {
-          setNotification(result?.message || 'WhatsApp Forms synced successfully');
-        }
-      })
-      .catch((errors) => {
-        console.log('error');
-        setSyncTemplateLoad(false);
-        setErrorMessage(formatError(errors.message), 'An error occurred');
-      });
+    });
   };

This would also eliminate the manual syncTemplateLoad state (line 85) and use Apollo's built-in loading state instead.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 104e45c and 8fa892e.

📒 Files selected for processing (2)
  • src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.tsx (6 hunks)
  • src/graphql/mutations/WhatsAppForm.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

⚙️ CodeRabbit configuration file

Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Files:

  • src/graphql/mutations/WhatsAppForm.ts
  • src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.tsx
🧬 Code graph analysis (1)
src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.tsx (5)
src/graphql/mutations/WhatsAppForm.ts (1)
  • SYNC_WHATSAPP_FORM (93-103)
src/services/AuthService.tsx (1)
  • getUserSession (140-176)
src/common/notification.ts (2)
  • setErrorMessage (15-40)
  • setNotification (4-13)
src/containers/WhatsAppForms/WhatsAppForms.tsx (1)
  • formatError (28-31)
src/components/UI/Form/Button/Button.tsx (1)
  • Button (12-29)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: CI
  • GitHub Check: glific (1.18.3-otp-27, 27.3.3)
  • GitHub Check: build
🔇 Additional comments (4)
src/graphql/mutations/WhatsAppForm.ts (1)

92-103: LGTM! Mutation follows established patterns.

The SYNC_WHATSAPP_FORM mutation is well-structured and consistent with other mutations in this file.

src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.tsx (3)

85-88: LGTM! State and mutation hook properly defined.

The loading state and mutation hook are correctly set up for the sync operation.


242-254: LGTM! Button implementation is correct.

The secondary button properly integrates loading state and triggers the sync operation.


302-302: LGTM! Secondary button properly integrated.

The button is correctly passed to the List component.

@github-actions github-actions bot temporarily deployed to pull request December 9, 2025 06:10 Inactive
@github-actions github-actions bot temporarily deployed to pull request December 9, 2025 06:12 Inactive
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: 1

♻️ Duplicate comments (1)
src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.tsx (1)

8-14: Remove unused syncWhatsappForm entry from queries object.

SYNC_WHATSAPP_FORM is correctly used via the syncWhatsappForm mutation hook, but the syncWhatsappForm key inside queries is not consumed by the List component and breaks the existing naming convention of that object. It just adds noise to the props being spread into <List />.

You can keep the import for the hook usage and drop the extra entry:

 const queries = {
   filterItemsQuery: LIST_WHATSAPP_FORMS,
   deleteItemQuery: DELETE_FORM,
   getItemQuery: GET_WHATSAPP_FORM,
   publishFlowQuery: PUBLISH_FORM,
-  syncWhatsappForm: SYNC_WHATSAPP_FORM,
 };

Also applies to: 33-34

🧹 Nitpick comments (1)
src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.tsx (1)

21-22: Tighten sync handler: guard missing org id, de‑duplicate loading reset, and avoid any for errors.

The overall flow looks good, but a few small tweaks will make it safer and cleaner:

  • Guard against a missing organizationId before firing the mutation, so you fail fast rather than sending an invalid variable.
  • Move setSyncWhatsappFormLoad(false) into a .finally() to ensure it always runs and to avoid duplication.
  • Replace err: any with a minimal structural type to keep type safety without over‑specifying the GraphQL shape.

Example refactor:

-  const handleHsmUpdates = () => {
-    setSyncWhatsappFormLoad(true);
-
-    syncWhatsappForm({
-      variables: {
-        organization_id: getUserSession('organizationId'),
-      },
-    })
-      .then((res) => {
-        setSyncWhatsappFormLoad(false);
-
-        const result = res?.data?.syncWhatsappForm;
-        if (result?.errors?.length) {
-          const errorMessages = result.errors.map((err: any) => err.message).join(', ');
-          setErrorMessage(errorMessages, 'An error occurred');
-        } else {
-          setNotification(result?.message || 'WhatsApp Forms synced successfully');
-        }
-      })
-      .catch((errors) => {
-        setSyncWhatsappFormLoad(false);
-        setErrorMessage(formatError(errors.message), 'An error occurred');
-      });
-  };
+  const handleHsmUpdates = () => {
+    const organizationId = getUserSession('organizationId');
+    if (!organizationId) {
+      setErrorMessage('Missing organization id in session', 'An error occurred');
+      return;
+    }
+
+    setSyncWhatsappFormLoad(true);
+
+    syncWhatsappForm({
+      variables: {
+        organization_id: organizationId,
+      },
+    })
+      .then((res) => {
+        const result = res?.data?.syncWhatsappForm;
+        if (result?.errors?.length) {
+          const errorMessages = result.errors
+            .map((err: { message: string }) => err.message)
+            .join(', ');
+          setErrorMessage(errorMessages, 'An error occurred');
+        } else {
+          setNotification(result?.message || 'WhatsApp Forms synced successfully');
+        }
+      })
+      .catch((errors) => {
+        setErrorMessage(formatError(errors.message), 'An error occurred');
+      })
+      .finally(() => {
+        setSyncWhatsappFormLoad(false);
+      });
+  };

Also applies to: 84-87, 100-123

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22e8fbf and 102071f.

📒 Files selected for processing (1)
  • src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.tsx (6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

⚙️ CodeRabbit configuration file

Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Files:

  • src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build
  • GitHub Check: glific (1.18.3-otp-27, 27.3.3)
  • GitHub Check: CI

@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.55%. Comparing base (1bb7a07) to head (13bc7c9).

Files with missing lines Patch % Lines
...hatsAppForms/WhatsAppFormList/WhatsAppFormList.tsx 93.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3683      +/-   ##
==========================================
+ Coverage   82.53%   82.55%   +0.01%     
==========================================
  Files         348      348              
  Lines       11729    11748      +19     
  Branches     2478     2480       +2     
==========================================
+ Hits         9681     9699      +18     
- Misses       1298     1299       +1     
  Partials      750      750              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cypress
Copy link

cypress bot commented Dec 9, 2025

Glific    Run #6876

Run Properties:  status check passed Passed #6876  •  git commit be18769011 ℹ️: Merge 13bc7c9c4cace51cfa9af8ea615e4330b670966e into 1bb7a071a558aead4e8a7f62457e...
Project Glific
Branch Review feat/add_sync_button
Run status status check passed Passed #6876
Run duration 28m 40s
Commit git commit be18769011 ℹ️: Merge 13bc7c9c4cace51cfa9af8ea615e4330b670966e into 1bb7a071a558aead4e8a7f62457e...
Committer Priyanshu singh
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 2
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 191
View all changes introduced in this branch ↗︎

@priyanshu6238 priyanshu6238 marked this pull request as draft December 9, 2025 08:44
@github-actions github-actions bot temporarily deployed to pull request December 9, 2025 13:08 Inactive
@priyanshu6238 priyanshu6238 changed the title feat: add new sync button WhatsApp From: Add Sync Button on WhatsApp Forms List Page Dec 9, 2025
@priyanshu6238 priyanshu6238 marked this pull request as ready for review December 9, 2025 13:11
@priyanshu6238 priyanshu6238 self-assigned this Dec 9, 2025
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: 2

🧹 Nitpick comments (1)
src/mocks/WhatsAppForm.tsx (1)

373-392: Align error mock response shape and variables with the mutation schema

The error mock currently returns:

syncWhatsappForm: {
  whatsappForm: null,
  errors: [{ message: 'Something went wrong' }],
}

while the documented selection set for SYNC_WHATSAPP_FORM only includes message and errors { key, message }. The extra whatsappForm field and missing message/key may confuse future readers and could break if the UI later relies on message or error.key.

Also, this mock uses organization_id: 'org-123' while the success mock used null, so only one of them will match depending on what WhatsAppFormList actually sends.

Consider:

  • Using the same (non‑null) organization_id here as in the success mock, and
  • Shaping the result to mirror the mutation:
 const syncWhatsappFormQueryWithErrors = {
   request: {
     query: SYNC_WHATSAPP_FORM,
     variables: {
-      organization_id: 'org-123',
+      organization_id: 'org-123', // keep in sync with success mock / component usage
     },
   },
   result: {
     data: {
       syncWhatsappForm: {
-        whatsappForm: null,
-        errors: [
-          {
-            message: 'Something went wrong',
-          },
-        ],
+        message: 'Something went wrong',
+        errors: [
+          {
+            key: 'base',
+            message: 'Something went wrong',
+          },
+        ],
       },
     },
   },
 };

(Feel free to adjust key and the exact message to whatever your backend actually returns.)

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 102071f and d604e40.

📒 Files selected for processing (3)
  • src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.test.tsx (2 hunks)
  • src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.tsx (6 hunks)
  • src/mocks/WhatsAppForm.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.tsx
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

⚙️ CodeRabbit configuration file

Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Files:

  • src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.test.tsx
  • src/mocks/WhatsAppForm.tsx
🧬 Code graph analysis (2)
src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.test.tsx (1)
src/mocks/WhatsAppForm.tsx (2)
  • syncWhatsappForm (407-407)
  • syncWhatsappFormQueryWithErrors (407-407)
src/mocks/WhatsAppForm.tsx (1)
src/graphql/mutations/WhatsAppForm.ts (1)
  • SYNC_WHATSAPP_FORM (93-103)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: CI
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: glific (1.18.3-otp-27, 27.3.3)
🔇 Additional comments (3)
src/containers/WhatsAppForms/WhatsAppFormList/WhatsAppFormList.test.tsx (1)

10-12: Sync mocks import wiring looks correct

The added imports for syncWhatsappForm and syncWhatsappFormQueryWithErrors line up with the new mocks and keep the test setup consistent with the rest of the file.

src/mocks/WhatsAppForm.tsx (2)

1-7: Mutation import integration is consistent

Bringing SYNC_WHATSAPP_FORM into the existing WhatsApp form mutation imports keeps the mocks aligned with the real GraphQL API and follows the established pattern in this file.


406-407: Exports for new sync mocks look good

Re‑exporting syncWhatsappFormQueryWithErrors and syncWhatsappForm from this module cleanly exposes the new mocks to tests and is consistent with existing patterns.

@github-actions github-actions bot temporarily deployed to pull request December 9, 2025 13:18 Inactive
@github-actions github-actions bot temporarily deployed to pull request December 9, 2025 13:50 Inactive
@github-actions github-actions bot temporarily deployed to pull request December 10, 2025 03:09 Inactive
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