Skip to content

Comments

improvement: enhance workspace invitation modularity#6594

Merged
sriramveeraghanta merged 1 commit intopreviewfrom
improvement-workspace-invite
Feb 12, 2025
Merged

improvement: enhance workspace invitation modularity#6594
sriramveeraghanta merged 1 commit intopreviewfrom
improvement-workspace-invite

Conversation

@prateekshourya29
Copy link
Member

@prateekshourya29 prateekshourya29 commented Feb 12, 2025

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Summary by CodeRabbit

  • New Features
    • Added a member count badge on the workspace settings page for quick visibility of workspace size.
    • Upgraded the invitation modal to streamline bulk member invitations with dynamic input fields and localized content.
    • Introduced a billing actions button that appears for users with administrative permissions, enhancing workspace management.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 12, 2025

Walkthrough

This pull request integrates updates in the workspace settings and invitation flow. It adds a new CountChip component to display member counts and a new BillingActionsButton component for billing actions. The modal invitation system is refactored by replacing the old send-workspace-invitation-modal with a new invite-modal structure, including sub-components for actions, fields, and form. Additionally, a custom hook useWorkspaceInvitationActions has been introduced to manage invitation form state and logic. Several export files have been updated to reflect these changes.

Changes

File(s) Change Summary
web/app/[workspaceSlug]/…/settings/members/page.tsx Integrated CountChip next to the title; added import for BillingActionsButton; updated error handling in handleWorkspaceInvite.
web/ce/components/workspace/billing/billing-actions-button.tsx,
web/ce/components/workspace/billing/index.ts
Introduced new BillingActionsButton component (placeholder) and updated billing module exports.
web/ce/components/workspace/index.ts,
web/ce/components/workspace/members/index.ts,
web/ce/components/workspace/members/invite-modal.tsx
Added export for members; introduced SendWorkspaceInvitationModal component within invite-modal; consolidated members exports.
web/core/components/workspace/index.ts,
web/core/components/workspace/invite-modal/actions.tsx,
web/core/components/workspace/invite-modal/fields.tsx,
web/core/components/workspace/invite-modal/form.tsx,
web/core/components/workspace/invite-modal/index.ts,
web/core/components/workspace/send-workspace-invitation-modal.tsx
Replaced old send-workspace-invitation-modal with invite-modal components; added InvitationModalActions, InvitationFields, and InvitationForm; updated modal exports.
web/core/hooks/use-workspace-invitation.tsx Added useWorkspaceInvitationActions hook to manage invitation form state and submission logic.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant WM as Workspace Members Page
    participant IM as Invite Modal
    participant UH as UseWorkspaceInvitationActions
    participant BE as Backend
    U->>WM: Click "Invite"
    WM->>IM: Open Invitation Modal
    IM->>UH: Initialize form state
    U->>IM: Enter invitation details
    U->>IM: Submit form
    IM->>UH: Process submission
    UH->>BE: Validate and process invitations
    BE-->>UH: Return response
    UH-->>IM: Update state
    IM-->>U: Display success/error message
Loading

Possibly related PRs

Suggested labels

🌟improvement, 🌐frontend

Suggested reviewers

  • sriramveeraghanta
  • rahulramesha
  • anmolsinghbhatia

Poem

I'm a bunny hopping through the lines of code,
Skipping through updates on a merry road.
CountChip hops in to display a lively count,
While modals and hooks make the logic mount.
With Billing buttons and invitations so neat,
My rabbit heart dances to every beat!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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

🔭 Outside diff range comments (1)
web/app/[workspaceSlug]/(projects)/settings/members/page.tsx (1)

49-91: 🛠️ Refactor suggestion

Improve error handling in workspace invitation.

The error handling in handleWorkspaceInvite could be more robust with better error types and user feedback.

 const handleWorkspaceInvite = (data: IWorkspaceBulkInviteFormData) => {
-  if (!workspaceSlug) return;
+  if (!workspaceSlug) {
+    setToast({
+      type: TOAST_TYPE.ERROR,
+      title: "Error!",
+      message: t("workspace_settings.settings.members.invalid_workspace"),
+    });
+    return;
+  }

   return inviteMembersToWorkspace(workspaceSlug.toString(), data)
     .then(() => {
       setInviteModal(false);
       captureEvent(MEMBER_INVITED, {
         emails: [
           ...data.emails.map((email) => ({
             email: email.email,
             role: getUserRole(email.role as unknown as EUserPermissions),
           })),
         ],
         project_id: undefined,
         state: "SUCCESS",
         element: "Workspace settings member page",
       });
       setToast({
         type: TOAST_TYPE.SUCCESS,
         title: "Success!",
         message: t("workspace_settings.settings.members.invitations_sent_successfully"),
       });
     })
     .catch((err) => {
+      const errorMessage = err.error ?? t("something_went_wrong_please_try_again");
+      console.error("Workspace invitation failed:", errorMessage);
       captureEvent(MEMBER_INVITED, {
         emails: [
           ...data.emails.map((email) => ({
             email: email.email,
             role: getUserRole(email.role as unknown as EUserPermissions),
           })),
         ],
         project_id: undefined,
         state: "FAILED",
         element: "Workspace settings member page",
       });
       setToast({
         type: TOAST_TYPE.ERROR,
         title: "Error!",
-        message: `${err.error ?? t("something_went_wrong_please_try_again")}`,
+        message: errorMessage,
       });
       throw err;
     });
 };
🧹 Nitpick comments (6)
web/core/components/workspace/invite-modal/form.tsx (1)

6-13: Consider adding prop types validation.

The component's props are well-typed, but consider adding runtime validation for better error handling.

Consider using a validation library like zod or prop-types:

import { z } from 'zod';

const invitationFormSchema = z.object({
  title: z.string(),
  description: z.any(),
  children: z.any(),
  onSubmit: z.function(),
  actions: z.any(),
  className: z.string().optional(),
});
web/ce/components/workspace/members/invite-modal.tsx (1)

23-34: Consider adding error boundary and loading state.

The component could benefit from error handling and loading state management.

Consider wrapping the component with an error boundary and adding loading state:

+import { ErrorBoundary } from '@/components/error-boundary';
+
 export const SendWorkspaceInvitationModal: React.FC<TSendWorkspaceInvitationModalProps> = observer((props) => {
   const { isOpen, onClose, onSubmit } = props;
+  const [isLoading, setIsLoading] = React.useState(false);
   // store hooks
   const { t } = useTranslation();
   // router
   const { workspaceSlug } = useParams();
   // derived values
   const { control, fields, formState, remove, onFormSubmit, handleClose, appendField } = useWorkspaceInvitationActions({
     onSubmit,
     onClose,
   });

   return (
+    <ErrorBoundary>
     <ModalCore isOpen={isOpen} position={EModalPosition.TOP} width={EModalWidth.XXL}>
web/core/components/workspace/invite-modal/actions.tsx (1)

38-51: Enhance accessibility of the "Add More" button.

The button could benefit from improved accessibility attributes and consistent styling with other buttons.

 <button
   type="button"
+  aria-label={addMoreButtonText || t("common.add_more")}
   className={cn(
-    "flex items-center gap-1 bg-transparent py-2 pr-3 text-xs font-medium text-custom-primary outline-custom-primary",
+    "flex items-center gap-1 bg-transparent py-2 px-3 text-xs font-medium text-custom-primary outline-none focus:ring-2 focus:ring-custom-primary/20",
     {
       "cursor-not-allowed opacity-60": isInviteDisabled,
     }
   )}
   onClick={appendField}
   disabled={isInviteDisabled}
 >
   <Plus className="h-3.5 w-3.5" />
   {addMoreButtonText || t("common.add_more")}
 </button>
web/core/hooks/use-workspace-invitation.tsx (1)

70-72: Add cleanup to useEffect.

The effect should clean up any pending operations when the component unmounts.

 useEffect(() => {
   if (fields.length === 0) append([{ email: "", role: EUserPermissions.MEMBER }]);
+  return () => {
+    // Clean up any pending operations
+    reset(SEND_WORKSPACE_INVITATION_MODAL_DEFAULT_VALUES);
+  };
 }, [fields, append]);
web/core/components/workspace/invite-modal/fields.tsx (1)

90-98: Optimize role options rendering.

The role options mapping could be memoized to prevent unnecessary re-renders.

+const getRoleOptions = (currentWorkspaceRole: number) =>
+  Object.entries(ROLE).filter(([key]) => currentWorkspaceRole && currentWorkspaceRole >= parseInt(key))
+    .map(([key, value]) => (
+      <CustomSelect.Option key={key} value={parseInt(key)}>
+        {value}
+      </CustomSelect.Option>
+    ));

-{Object.entries(ROLE).map(([key, value]) => {
-  if (currentWorkspaceRole && currentWorkspaceRole >= parseInt(key))
-    return (
-      <CustomSelect.Option key={key} value={parseInt(key)}>
-        {value}
-      </CustomSelect.Option>
-    );
-})}
+{getRoleOptions(currentWorkspaceRole ?? 0)}
web/app/[workspaceSlug]/(projects)/settings/members/page.tsx (1)

121-130: Enhance search input accessibility.

The search input could benefit from improved accessibility attributes and better ARIA support.

 <div className="ml-auto flex items-center gap-1.5 rounded-md border border-custom-border-200 bg-custom-background-100 px-2.5 py-1.5">
-  <Search className="h-3.5 w-3.5 text-custom-text-400" />
+  <Search className="h-3.5 w-3.5 text-custom-text-400" aria-hidden="true" />
   <input
+    role="searchbox"
+    aria-label={`${t("search")}...`}
     className="w-full max-w-[234px] border-none bg-transparent text-sm outline-none placeholder:text-custom-text-400"
     placeholder={`${t("search")}...`}
     value={searchQuery}
     autoFocus
     onChange={(e) => setSearchQuery(e.target.value)}
   />
 </div>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 03cc819 and ec619c5.

📒 Files selected for processing (13)
  • web/app/[workspaceSlug]/(projects)/settings/members/page.tsx (5 hunks)
  • web/ce/components/workspace/billing/billing-actions-button.tsx (1 hunks)
  • web/ce/components/workspace/billing/index.ts (1 hunks)
  • web/ce/components/workspace/index.ts (1 hunks)
  • web/ce/components/workspace/members/index.ts (1 hunks)
  • web/ce/components/workspace/members/invite-modal.tsx (1 hunks)
  • web/core/components/workspace/index.ts (1 hunks)
  • web/core/components/workspace/invite-modal/actions.tsx (1 hunks)
  • web/core/components/workspace/invite-modal/fields.tsx (1 hunks)
  • web/core/components/workspace/invite-modal/form.tsx (1 hunks)
  • web/core/components/workspace/invite-modal/index.ts (1 hunks)
  • web/core/components/workspace/send-workspace-invitation-modal.tsx (0 hunks)
  • web/core/hooks/use-workspace-invitation.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • web/core/components/workspace/send-workspace-invitation-modal.tsx
✅ Files skipped from review due to trivial changes (4)
  • web/ce/components/workspace/members/index.ts
  • web/ce/components/workspace/index.ts
  • web/core/components/workspace/invite-modal/index.ts
  • web/ce/components/workspace/billing/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (4)
web/core/components/workspace/index.ts (1)

8-8: LGTM! Export change aligns with modular design.

The change from send-workspace-invitation-modal to invite-modal reflects the refactoring of the invitation system into a more modular structure.

web/core/components/workspace/invite-modal/form.tsx (1)

15-36: LGTM! Well-structured form component.

The component follows React best practices:

  • Uses MobX observer pattern correctly
  • Prevents Enter key submission for better UX
  • Properly structured layout with title and description
  • Well-organized props destructuring
web/ce/components/workspace/members/invite-modal.tsx (2)

17-21: LGTM! Well-defined props interface.

The props interface is comprehensive and properly typed with the correct Promise return type for the onSubmit handler.


35-60: LGTM! Well-structured modal component.

The component follows best practices:

  • Uses MobX observer pattern correctly
  • Proper integration with i18n
  • Good separation of concerns with custom hook
  • Clean component composition

@sriramveeraghanta sriramveeraghanta merged commit cc9b448 into preview Feb 12, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the improvement-workspace-invite branch February 12, 2025 11:35
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