Skip to content

fix(service-portal): owner view iteration #16038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 18, 2024
Merged

fix(service-portal): owner view iteration #16038

merged 9 commits into from
Sep 18, 2024

Conversation

albinagu
Copy link
Member

@albinagu albinagu commented Sep 17, 2024

Features:

  • fetched owner lists (overview)
  • fetched single list view
  • cancel collection
  • add collection (constituency) UI

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a feature to copy the signature collection link with user feedback.
    • Introduced a loading skeleton for improved user experience during data fetching.
    • Enhanced the Add Constituency modal to manage selections dynamically.
    • Streamlined the rendering of the Cancel Collection component for better accessibility.
  • Bug Fixes

    • Updated parameter handling in various components for better reliability.
  • Documentation

    • Improved clarity in the rendering logic and user interface elements across components.

@albinagu albinagu requested a review from a team as a code owner September 17, 2024 14:22
Copy link
Contributor

coderabbitai bot commented Sep 17, 2024

Walkthrough

The pull request introduces several changes across multiple components within the signature collection module. Key modifications include the addition of the AddConstituencyModal component for managing constituencies, updates to the ViewList component for improved data handling and user interaction, and enhancements to the OwnerView for dynamic rendering of lists. Additionally, the CancelCollection component has been restructured to focus on list cancellations.

Changes

File Change Summary
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/AddConstituency/index.tsx Added AddConstituencyModal component for adding constituencies, managing state for visibility and selections.
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/index.tsx Transitioned from useLocation to useParams for id, improved dynamic rendering of list information, added link-copying feature with user feedback.
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx Updated to conditionally render a loading skeleton, dynamically mapped over listsForOwner, and adjusted navigation logic.
libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/CancelCollection/index.tsx Removed the CancelCollection component, which managed signature collection cancellations.
libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/index.tsx Updated import of CancelCollection to a shared components directory and simplified rendering logic for better accessibility.
libs/service-portal/signature-collection/src/screens/shared/CancelCollection/index.tsx Modified to accept listId instead of collectionId, updated mutation handling for canceling collections.

Possibly related PRs

Suggested labels

automerge, high priority

Suggested reviewers

  • juni-haukur
  • thordurhhh

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai generate interesting stats about this repository and render them as a table.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI o1 for code reviews: OpenAI's new o1 model is being tested for code reviews. This model has advanced reasoning capabilities and can provide more nuanced feedback on your code.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Copy link
Contributor

@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: 12

Outside diff range and nitpick comments (10)
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/modals/AddConstituency/index.tsx (1)

9-13: Define a Props interface for clarity and reusability

Currently, the component's props are defined inline. For better readability and scalability, consider defining a Props interface or type for the component's props.

Apply this diff to introduce a Props interface:

+ interface Props {
+   lists: SignatureCollectionList[]
+ }

  const AddConstituencyModal = ({
    lists,
- }: {
-   lists: SignatureCollectionList[]
- }) => {
+ }: Props) => {

This approach enhances code clarity and makes it easier to extend or reuse the component in other parts of the application.

libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/modals/CancelCollection/index.tsx (3)

11-11: Define and export a Props type for better type clarity

For improved TypeScript practices and reusability across different Next.js apps, consider defining and exporting a CancelCollectionProps type for your component's props. This enhances readability and maintainability.

Apply this change:

+ interface CancelCollectionProps {
+   listId: string
+ }
- const CancelCollection = ({ listId }: { listId: string }) => {
+ const CancelCollection = ({ listId }: CancelCollectionProps) => {

Line range hint 26-45: Add error handling for the mutation promise

Currently, if the cancelCollection mutation fails, there is no error handling in place. To enhance robustness and provide better user feedback, add a .catch block to handle potential errors and notify the user accordingly.

Update your code as follows:

  const onCancelCollection = async () => {
    await cancelCollection()
      .then(({ data }) => {
        if (data?.signatureCollectionCancel?.success) {
          toast.success(formatMessage(m.cancelCollectionModalToastSuccess))
          setModalIsOpen(false)
          refetchIsOwner()
        } else {
          toast.error(formatMessage(m.cancelCollectionModalToastError))
          setModalIsOpen(false)
        }
      })
+     .catch((error) => {
+       toast.error(formatMessage(m.cancelCollectionModalToastError))
+       setModalIsOpen(false)
+     })
  }

31-35: Simplify type assertions for mutation response data

The current type assertion from unknown to a specific type in the mutation response is unnecessary with the correct typing of the mutation. By updating the mutation's type parameter, you can directly access the response data without unsafe assertions.

Update your code as follows:

-      if (
-        (
-          data as unknown as {
-            signatureCollectionCancel: SignatureCollectionSuccess
-          }
-        ).signatureCollectionCancel.success
-      ) {
+      if (data?.signatureCollectionCancel?.success) {
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/index.tsx (1)

45-45: Use a unique and stable key for list items

Using collector.name as the key may cause issues if collector names are not unique. If available, consider using a unique identifier such as collector.id.

Apply this diff to update the key:

-                      key={collector.name}
+                      key={collector.id}
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx (2)

Line range hint 18-22: Define component props using a TypeScript interface

For better readability and reusability, consider defining a separate interface for the component props instead of inline typing. This aligns with TypeScript best practices.

You can define an interface like:

interface OwnerViewProps {
  currentCollection: SignatureCollection
}

And update the component definition:

const OwnerView: React.FC<OwnerViewProps> = ({ currentCollection }) => {
  // component logic
}

49-81: Handle the case when listsForOwner is empty

Currently, if listsForOwner is empty, nothing is displayed to the user. Consider providing feedback by showing a message indicating that there are no lists available.

You can add conditional rendering to display an appropriate message:

{listsForOwner.length === 0 ? (
  <Text>{formatMessage(m.noListsAvailable)}</Text>
) : (
  listsForOwner.map(/* existing mapping logic */)
)}
libs/service-portal/signature-collection/src/screens/shared/SigneeView/index.tsx (1)

Line range hint 34-38: Ensure type consistency for currentCollection.

The use of optional chaining currentCollection?.isPresidential indicates that currentCollection might be null or undefined, but in the component's props, currentCollection is defined as a required prop of type SignatureCollection. To maintain type safety and prevent potential runtime errors, consider updating the prop definition to make currentCollection optional.

Apply this diff to adjust the prop definition:

-const SigneeView = ({
-  currentCollection,
-}: {
-  currentCollection: SignatureCollection
-}) => {
+const SigneeView = ({
+  currentCollection,
+}: {
+  currentCollection?: SignatureCollection
+}) => {
libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/ViewList/SigneesOverview.tsx (2)

Line range hint 33-37: Include loadingSignees in useEffect dependency array

The loadingSignees variable is used within the useEffect hook but isn't included in the dependency array. Omitting it may lead to stale data or missed updates when loadingSignees changes.

Apply this diff to include loadingSignees in the dependencies:

   useEffect(() => {
     if (!loadingSignees) {
       setSignees(listSignees)
     }
-  }, [listSignees])
+  }, [listSignees, loadingSignees])

Line range hint 40-53: Add listSignees to useEffect dependency array

The useEffect hook filters listSignees based on searchTerm, but listSignees isn't included in the dependency array. If listSignees changes, the effect won't re-run, potentially causing the displayed signees list to be out of sync.

Apply this diff to ensure the effect runs when listSignees changes:

-  }, [searchTerm])
+  }, [searchTerm, listSignees])
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f0e526e and 4b30cff.

Files selected for processing (11)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees.tsx (1 hunks)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/index.tsx (1 hunks)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx (3 hunks)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/modals/AddConstituency/index.tsx (2 hunks)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/modals/CancelCollection/index.tsx (4 hunks)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx (1 hunks)
  • libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/ViewList/SigneesOverview.tsx (1 hunks)
  • libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/ViewList/index.tsx (2 hunks)
  • libs/service-portal/signature-collection/src/screens/shared/SignedList/index.tsx (1 hunks)
  • libs/service-portal/signature-collection/src/screens/shared/SigneeView/index.tsx (2 hunks)
  • libs/service-portal/signature-collection/src/skeletons.tsx (1 hunks)
Files skipped from review due to trivial changes (4)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees.tsx
  • libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx
  • libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/ViewList/index.tsx
  • libs/service-portal/signature-collection/src/screens/shared/SignedList/index.tsx
Additional context used
Path-based instructions (7)
libs/service-portal/signature-collection/src/skeletons.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/modals/AddConstituency/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/modals/CancelCollection/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/service-portal/signature-collection/src/screens/shared/SigneeView/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/ViewList/SigneesOverview.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
Additional comments not posted (6)
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/modals/CancelCollection/index.tsx (2)

56-59: Button configuration follows UI guidelines

The Button component configuration for opening the modal is appropriate, with the correct variant, size, and color scheme. It enhances user experience by clearly indicating a destructive action in a non-intrusive way.


65-85: UI enhancements in the modal are well implemented

The updates to the modal's layout and button styles improve the user interface, providing clear messaging and actions for the user. The use of formatMessage ensures proper localization, and the layout is accessible and responsive.

libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx (2)

14-15: Code adheres to TypeScript best practices for defining and using types

The imports and usage of SignatureCollectionList and OwnerParliamentarySkeleton enhance type safety and maintainability, aligning with TypeScript best practices.


42-42: Confirm that AddConstituency component accepts the new lists prop

Ensure that the AddConstituency component has been updated to accept the lists prop of type SignatureCollectionList[]. This will ensure type safety and proper functionality.

libs/service-portal/signature-collection/src/screens/shared/SigneeView/index.tsx (1)

51-53: Confirm variant="h4" aligns with design specifications.

Adding variant="h4" to the Text component changes its styling and possibly its semantic role. Ensure this update conforms to the design guidelines and maintains consistency across the application.

libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/ViewList/SigneesOverview.tsx (1)

14-14: Importing useParams enhances parameter handling

Importing useParams from react-router-dom improves how route parameters are accessed, making the code cleaner and more reliable.

@albinagu albinagu changed the title fix(service-portal): owner view fix(service-portal): owner view iteration Sep 17, 2024
Copy link

codecov bot commented Sep 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.73%. Comparing base (e994855) to head (239b6b7).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16038   +/-   ##
=======================================
  Coverage   36.73%   36.73%           
=======================================
  Files        6735     6735           
  Lines      138232   138232           
  Branches    39302    39302           
=======================================
  Hits        50784    50784           
  Misses      87448    87448           
Flag Coverage Δ
air-discount-scheme-web 0.00% <ø> (ø)
api 3.39% <ø> (ø)
application-api-files 57.59% <ø> (ø)
application-core 71.29% <ø> (-0.33%) ⬇️
application-system-api 41.64% <ø> (ø)
application-template-api-modules 23.43% <ø> (-0.04%) ⬇️
application-templates-accident-notification 22.14% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 26.63% <ø> (ø)
application-templates-driving-license 18.63% <ø> (ø)
application-templates-estate 12.34% <ø> (ø)
application-templates-example-payment 25.41% <ø> (ø)
application-templates-financial-aid 14.34% <ø> (ø)
application-templates-general-petition 23.68% <ø> (ø)
application-templates-health-insurance 26.62% <ø> (ø)
application-templates-inheritance-report 6.45% <ø> (ø)
application-templates-marriage-conditions 15.23% <ø> (ø)
application-templates-mortgage-certificate 43.93% <ø> (ø)
application-templates-parental-leave 30.19% <ø> (ø)
application-types 6.71% <ø> (ø)
application-ui-components 1.28% <ø> (ø)
application-ui-shell 21.29% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
web 1.85% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e994855...239b6b7. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 17, 2024

Datadog Report

All test runs 16b1ae7 🔗

21 Total Test Services: 0 Failed, 21 Passed
🔻 Test Sessions change in coverage: 2 decreased, 90 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-web 0 0 0 2 0 9.05s 1 no change Link
api 0 0 0 4 0 2.84s 1 no change Link
application-api-files 0 0 0 12 0 6.03s 1 no change Link
application-core 0 0 0 90 0 19.92s 1 decreased (-0.21%) Link
application-system-api 0 0 0 111 2 3m 18.09s 1 no change Link
application-template-api-modules 0 0 0 109 0 1m 50.5s 1 decreased (-0.01%) Link
application-templates-accident-notification 0 0 0 98 0 19.68s 1 no change Link
application-templates-criminal-record 0 0 0 2 0 10.57s 1 no change Link
application-templates-driving-license 0 0 0 13 0 16.92s 1 no change Link
application-templates-example-payment 0 0 0 2 0 11.51s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • application-core - jest 79.36% (-0.21%) - Details
  • application-template-api-modules - jest 25.56% (-0.01%) - Details

Copy link
Contributor

@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: 7

Outside diff range and nitpick comments (6)
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/AddConstituency/index.tsx (3)

36-38: Remove unnecessary initialVisibility prop from Modal

The initialVisibility prop may not be necessary since the modal's visibility is controlled by the isVisible prop. Consider removing initialVisibility to simplify the component.

Apply this diff to remove the prop:

<Modal
  id="addConstituency"
  isVisible={modalIsOpen}
- initialVisibility={false}
  onCloseModal={() => {
    setModalIsOpen(false)
    setSelectedConstituencies([])
  }}
  label={''}
>

43-43: Provide a meaningful label for Modal for accessibility

The label prop is set to an empty string. If it is not needed, consider removing it; otherwise, provide a meaningful label to improve accessibility and assistive technologies like screen readers.

Apply this diff to update the label:

<Modal
  id="addConstituency"
  isVisible={modalIsOpen}
  onCloseModal={() => {
    setModalIsOpen(false)
    setSelectedConstituencies([])
  }}
-  label={''}
+  label={formatMessage(m.addConstituency)}
>

84-84: Consider adding a named export for the component

For better reusability and consistency, consider exporting the component as a named export in addition to the default export. This allows for more flexible imports in other parts of the application.

Apply this diff to add a named export:

+export { AddConstituencyModal }
export default AddConstituencyModal
libs/service-portal/signature-collection/src/screens/shared/CancelCollection/index.tsx (2)

Line range hint 34-48: Simplify onCancelCollection with async/await syntax and proper typing

The onCancelCollection function currently combines async/await with a .then() promise chain, which is unnecessary and can be simplified. Additionally, casting data as unknown may be avoided by ensuring proper typing from the mutation result.

Refactor the function as follows:

-const onCancelCollection = async () => {
-  await cancelCollection().then(({ data }) => {
-    if (
-      (
-        data as unknown as {
-          signatureCollectionCancel: SignatureCollectionSuccess
-        }
-      ).signatureCollectionCancel.success
-    ) {
-      toast.success(formatMessage(m.cancelCollectionModalToastSuccess))
-      setModalIsOpen(false)
-    } else {
-      toast.error(formatMessage(m.cancelCollectionModalToastError))
-      setModalIsOpen(false)
-    }
-  })
-}

+const onCancelCollection = async () => {
+  try {
+    const { data } = await cancelCollection()
+    if (data?.signatureCollectionCancel?.success) {
+      toast.success(formatMessage(m.cancelCollectionModalToastSuccess))
+    } else {
+      toast.error(formatMessage(m.cancelCollectionModalToastError))
+    }
+  } catch (error) {
+    toast.error(formatMessage(m.cancelCollectionModalToastError))
+  } finally {
+    setModalIsOpen(false)
+  }
+}

This improves readability and leverages proper error handling with try...catch.


14-14: Export component prop types for reusability

For enhanced reusability across different NextJS apps, consider defining and exporting the prop types of the CancelCollection component. This promotes type safety and clarity when the component is used elsewhere.

Update the code as follows:

+interface CancelCollectionProps {
+  listId?: string
+}
+
-const CancelCollection = ({ listId }: { listId?: string }) => {
+const CancelCollection = ({ listId }: CancelCollectionProps) => {

And export the interface if needed:

+export type { CancelCollectionProps }
libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/index.tsx (1)

20-20: Consider using absolute import paths for shared components

Importing CancelCollection using an absolute path can improve maintainability and readability, especially in larger projects with complex directory structures. This practice enhances reusability across different NextJS apps and aligns with effective bundling strategies.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4b30cff and 9e1273f.

Files selected for processing (6)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/AddConstituency/index.tsx (1 hunks)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/index.tsx (1 hunks)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx (3 hunks)
  • libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/CancelCollection/index.tsx (0 hunks)
  • libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/index.tsx (2 hunks)
  • libs/service-portal/signature-collection/src/screens/shared/CancelCollection/index.tsx (4 hunks)
Files not reviewed due to no reviewable changes (1)
  • libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/CancelCollection/index.tsx
Files skipped from review as they are similar to previous changes (1)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/index.tsx
Additional context used
Path-based instructions (4)
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/AddConstituency/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/service-portal/signature-collection/src/screens/shared/CancelCollection/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
Additional comments not posted (3)
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx (2)

13-15: Imports are correctly added

The new imports for AddConstituency, SignatureCollectionList, and OwnerParliamentarySkeleton are appropriate and properly structured.


53-84: Good job handling list rendering and optional properties

You've correctly used list.id as the key in the map function, which is a best practice for list rendering in React. Additionally, the use of optional chaining with list.area?.min and default values helps prevent potential runtime errors.

libs/service-portal/signature-collection/src/screens/Presidential/OwnerView/index.tsx (1)

147-147: Verify authorization when rendering CancelCollection component

By changing the condition to only check currentCollection.isActive, the CancelCollection component will render whenever the collection is active, regardless of the user's profile actor status. Previously, the component was rendered based on both currentCollection.isActive and !user?.profile.actor. Please ensure that this change doesn't allow unauthorized users to access cancellation functionality.

Copy link
Contributor

@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

Outside diff range and nitpick comments (1)
libs/service-portal/signature-collection/src/screens/shared/CancelCollection/index.tsx (1)

Line range hint 35-49: Simplify asynchronous handling by using async/await consistently

Mixing await with .then() can make the code less readable and harder to maintain. It's best to use one approach consistently. Also, the casting of data to unknown is unnecessary and can be avoided.

Apply this diff to refactor the code:

-  const onCancelCollection = async () => {
-    await cancelCollection().then(({ data }) => {
-      if (
-        (
-          data as unknown as {
-            signatureCollectionCancel: SignatureCollectionSuccess
-          }
-        ).signatureCollectionCancel.success
-      ) {
-        toast.success(formatMessage(m.cancelCollectionModalToastSuccess))
-        setModalIsOpen(false)
-      } else {
-        toast.error(formatMessage(m.cancelCollectionModalToastError))
-        setModalIsOpen(false)
-      }
-    })
-  }
+  const onCancelCollection = async () => {
+    try {
+      const { data } = await cancelCollection()
+      if (data?.signatureCollectionCancel.success) {
+        toast.success(formatMessage(m.cancelCollectionModalToastSuccess))
+      } else {
+        toast.error(formatMessage(m.cancelCollectionModalToastError))
+      }
+    } catch (error) {
+      toast.error(formatMessage(m.cancelCollectionModalToastError))
+    } finally {
+      setModalIsOpen(false)
+    }
+  }

This refactor improves readability by consistently using async/await and removes unnecessary type casting.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9e1273f and 9a2f90c.

Files selected for processing (2)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/index.tsx (1 hunks)
  • libs/service-portal/signature-collection/src/screens/shared/CancelCollection/index.tsx (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/index.tsx
Additional context used
Path-based instructions (1)
libs/service-portal/signature-collection/src/screens/shared/CancelCollection/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
Additional comments not posted (1)
libs/service-portal/signature-collection/src/screens/shared/CancelCollection/index.tsx (1)

Line range hint 14-97: Component is reusable and follows best practices

The CancelCollection component is well-structured, with props defined using TypeScript interfaces. This enhances type safety and reusability across different NextJS apps. Imports are specific, promoting effective tree-shaking and bundling practices.

Copy link
Member

@juni-haukur juni-haukur left a comment

Choose a reason for hiding this comment

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

🚀

@albinagu albinagu added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants