Connections Screen Refactor
1. Overview
Section titled “1. Overview”The goal of this project is to re-enable the Connections screen in the web application. This involves removing the existing Redux and RTK Query implementation for managing connections and replacing it with @tanstack/react-query for data fetching and state management. This will align the connections feature with the latest development patterns used in other parts of the application, such as for Grids.
2. Project Phases and Tasks
Section titled “2. Project Phases and Tasks”The project is broken down into the following phases and tasks to ensure a smooth transition and incremental development.
Phase 1: Implement React Query Hooks for Connections API
Section titled “Phase 1: Implement React Query Hooks for Connections API”First, we will create a set of reusable React Query hooks to interact with the connections API.
-
Task 1.1: Create
connectionQueries.ts- Create a new file at
apps/web-app/src/queries/connectionQueries.tsto house all connection-related queries and mutations.
- Create a new file at
-
Task 1.2: Implement Query Hooks
useGetConnections: A hook to fetch all connections for a givenworkspaceId. It will call theGET /jwt/connectionsendpoint.useGetConnection: A hook to fetch the details of a single connection by itsconnectionId. It will call theGET /jwt/connections/:idendpoint.
-
Task 1.3: Implement Mutation Hooks
useCreateConnection: A mutation hook for creating new connections viaPOST /jwt/connections. It should invalidate theuseGetConnectionsquery on success.useUpdateConnection: A mutation hook for updating connections viaPUT /jwt/connections/:id. It should invalidate bothuseGetConnectionsand the relevantuseGetConnectionqueries on success.useDeleteConnection: A mutation hook for deleting connections viaDELETE /jwt/connections/:id. It should invalidate theuseGetConnectionsquery on success.
Phase 2: Refactor UI Components
Section titled “Phase 2: Refactor UI Components”With the new data hooks in place, we can update the UI components to use them.
-
Task 2.1: Re-enable and Refactor Connection Routes
- Uncomment the routes in
apps/web-app/src/routes/ConnectionsRoutes.tsx. - Remove the
ConnectionReduxHandlercomponent wrapper.
- Uncomment the routes in
-
Task 2.2: Refactor
ConnectionsLeftNav.tsx- Uncomment the code in
apps/web-app/src/components/ConnectionsLeftNav/ConnectionsLeftNav.tsx. - Replace the
useGetConnectionsQueryfrom RTK Query with our newuseGetConnectionshook. - Update the component to correctly handle
isLoading,isError, anddatastates from the React Query hook.
- Uncomment the code in
-
Task 2.3: Refactor
ConnectionDetails.tsx- Update the
ConnectionDetailscomponent to fetch connection data usinguseGetConnectionwhen aconnectionIdis present in the URL. - For creating new connections, the component should not fetch any initial data.
- Use the
useCreateConnectionanduseUpdateConnectionmutation hooks for handling form submissions. - Manage form state locally within the component using
useStateor a form library likereact-hook-form, replacing the reliance on the old Redux slice.
- Update the
-
Task 2.4: Refactor
ConnectionMainContent.tsx- Review and refactor
apps/web-app/src/components/ConnectionMainContent/ConnectionMainContent.tsx. - Update it to use the new React Query hooks for any data it needs to display or modify, depending on the currently selected connection.
- Review and refactor
Phase 3: UI Migration from Material-UI to shadcn/ui
Section titled “Phase 3: UI Migration from Material-UI to shadcn/ui”After refactoring the component logic to use React Query, the next step is to update the UI from Material-UI to match the application’s design system based on shadcn/ui and Tailwind CSS.
-
Task 3.1: Refactor
ConnectionCard.tsx- Replace the custom MUI-based
Cardwith theCardcomponent from shadcn/ui. - Replace the MUI
Menu,MenuItem,MenuList, andIconButtonwith theDropdownMenuandButtoncomponents from shadcn/ui, following the pattern inGridCard. - Replace MUI icons (e.g.,
EditIcon,DeleteIcon,MoreHorizIcon) with suitable alternatives from thelucide-reactlibrary. - Remove MUI layout components (
Stack,Box) in favor of standarddivelements with Tailwind CSS utility classes for layout. - Replace MUI
Typographywith standardh3,p, orspantags styled with Tailwind’s typography classes.
- Replace the custom MUI-based
-
Task 3.2: Refactor
ConnectionsLeftNav.tsx- Replace the MUI
Stacklayout withdivelements using Tailwind CSS flexbox or grid utilities. - Migrate
CreateConnectionDialogto use theDialogcomponent from shadcn/ui. This includes replacing any MUI form elements within it. - Replace the MUI
GoogleIconwith an appropriate SVG or a similar icon fromlucide-react.
- Replace the MUI
-
Task 3.3: Refactor
ConnectionDetails.tsx- Replace the MUI
SidePanel’s internal layout (Stack) withdivs and Tailwind CSS classes. - Replace the MUI
TextFieldwith the shadcn/uiInputandLabelcomponents. - Replace the MUI
Dividerwith theSeparatorcomponent from shadcn/ui. - Replace all instances of MUI
Typographywith standard text elements styled with Tailwind CSS.
- Replace the MUI
-
Task 3.4: Refactor
ConnectionMainContent.tsx- Replace MUI
BoxandStackwithdivs using Tailwind CSS for layout. - Replace MUI
Typographywith standardh5orptags styled with Tailwind CSS.
- Replace MUI
Phase 4: Implement Tanstack Form for Connection Details
Section titled “Phase 4: Implement Tanstack Form for Connection Details”To handle form state and validation for connection details, we will integrate @tanstack/react-form.
-
Task 4.1: Install Dependencies
- Add
@tanstack/react-formand@tanstack/zod-form-adapterto theweb-app’s dependencies.
- Add
-
Task 4.2: Refactor
GoogleAdsConnectionDetails.tsx- Implement
useFormfrom@tanstack/react-formto manage the form state. - Define a Zod schema for validation, ensuring that
accountIdandaccountNameare provided for Google Ads connections. - Replace the
useState-based form management with the new Tanstack Form instance. - Add inputs for
accountId,accountName,managerAccountId, andmanagerAccountName. - Update the save functionality to work with the form’s submission handlers.
- Implement
Phase 5: Cleanup Existing Redux and RTK Query Implementation
Section titled “Phase 5: Cleanup Existing Redux and RTK Query Implementation”After the new implementation is in place and working, we will remove the code related to the old implementation.
-
Task 5.1: Delete the Redux Connection Slice
- Delete the file
apps/web-app/src/redux/store/slices/connections/connectionsSlice.ts. - Find where
connectionSliceis used in the main store configuration (likelyapps/web-app/src/redux/store/initStore.ts) and remove its reducer.
- Delete the file
-
Task 5.2: Remove Connection Endpoints from RTK Query
- Identify the RTK Query API slice that handles connections (likely in
apps/web-app/src/redux/services/honeyGridService.ts). - Remove the
getConnectionsquery and any other connection-related mutations or queries from the service definition.
- Identify the RTK Query API slice that handles connections (likely in
-
Task 5.3: Delete
ConnectionReduxHandler.tsx- The component at
apps/web-app/src/components/ConnectionDetails/ConnectionReduxHandler.tsxis tied to the old Redux implementation. It should be deleted.
- The component at
Phase 6: Final Integration and Testing
Section titled “Phase 6: Final Integration and Testing”Finally, we need to ensure all the pieces work together correctly.
- Task 6.1: End-to-End Testing
- Manually test the full user flow for connections:
- Viewing the list of connections.
- Viewing the “empty” state when no connections exist.
- Creating a new connection.
- Selecting a connection from the list and viewing its details.
- Editing and saving an existing connection.
- Deleting a connection.
- Verify that loading and error states are handled gracefully throughout the UI.
- Manually test the full user flow for connections: