Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions apps/web/app/components/nodes/CreateWorkFlow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import { useState } from "react";
import { useEffect, useState } from "react";
import "@xyflow/react/dist/style.css";
import { ReactFlow } from "@xyflow/react";
import PlaceholderNode from "./PlaceHolder";
Expand All @@ -9,7 +9,10 @@ import { TriggerSideBar } from "./TriggerSidebar";
import ActionSideBar from "../Actions/ActionSidebar";
import ActionNode from "../Actions/ActionNode";
import { GoogleSheetFormClient } from "./GoogleSheetFormClient";
import { useCredentials } from "@/app/hooks/useCredential";
import { getEmptyWorkflow } from "@/app/workflow/lib/dbHandler";
import { useDispatch } from "react-redux";
import { workflowActions, workflowReducer } from "@/store/slices/workflowSlice";


interface NodeType {
id: string;
Expand All @@ -35,6 +38,7 @@ export const CreateWorkFlow = () => {
const [actionSidebarOpen, setActionSidebarOpen] = useState(false);
const [credType, setCredType] = useState<string>("");
const [loadSheet, setLoadSheet] = useState<boolean>(false)
const dispatch = useDispatch();

const [nodes, setNodes] = useState<NodeType[]>([
{
Expand Down Expand Up @@ -107,12 +111,21 @@ export const CreateWorkFlow = () => {
]);
};

function getCredentials(type: string){
// if(credData){
// console.log(creds.nodeId)
// setNodeId(creds.nodeId)
// }
}
useEffect(()=>{
async function getEmptyWorkflowID(){
const workflow = await getEmptyWorkflow()

if(workflow){
const {id, isEmpty} = workflow
dispatch(workflowActions.setWorkflowId(id))
dispatch(workflowActions.setWorkflowStatus(isEmpty))
}
else{
const newWorkflow
}
}
getEmptyWorkflowID()
},[dispatch])
Comment on lines +114 to +128

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix syntax error in incomplete else branch.

The else branch at Line 124 contains an uninitialized const declaration, which is a syntax error. This will prevent the code from compiling.

🔎 Proposed fix

If the else branch is not yet implemented, remove it:

       if(workflow){
         const {id, isEmpty} = workflow
         dispatch(workflowActions.setWorkflowId(id))
         dispatch(workflowActions.setWorkflowStatus(isEmpty))
       }
-      else{
-        const newWorkflow 
-      }
     }

Alternatively, if you intend to create a new workflow when none exists, complete the implementation:

       if(workflow){
         const {id, isEmpty} = workflow
         dispatch(workflowActions.setWorkflowId(id))
         dispatch(workflowActions.setWorkflowStatus(isEmpty))
       }
-      else{
-        const newWorkflow 
-      }
+      else{
+        // TODO: Create a new empty workflow
+      }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(()=>{
async function getEmptyWorkflowID(){
const workflow = await getEmptyWorkflow()
if(workflow){
const {id, isEmpty} = workflow
dispatch(workflowActions.setWorkflowId(id))
dispatch(workflowActions.setWorkflowStatus(isEmpty))
}
else{
const newWorkflow
}
}
getEmptyWorkflowID()
},[dispatch])
useEffect(()=>{
async function getEmptyWorkflowID(){
const workflow = await getEmptyWorkflow()
if(workflow){
const {id, isEmpty} = workflow
dispatch(workflowActions.setWorkflowId(id))
dispatch(workflowActions.setWorkflowStatus(isEmpty))
}
}
getEmptyWorkflowID()
},[dispatch])
🧰 Tools
🪛 Biome (2.1.2)

[error] 124-124: Const declarations must have an initialized value.

This variable needs to be initialized.

(parse)

🤖 Prompt for AI Agents
In apps/web/app/components/nodes/CreateWorkFlow.tsx around lines 114–128 the
else branch contains an incomplete declaration ("const newWorkflow") which is a
syntax error; either remove the empty else block entirely or implement it by
creating a new workflow (await a createNewWorkflow()/getOrCreateEmptyWorkflow()
call), extract its id and isEmpty status, and dispatch
workflowActions.setWorkflowId(id) and
workflowActions.setWorkflowStatus(isEmpty); ensure the function is awaited and
handle errors (try/catch or null checks) before dispatching.

🛠️ Refactor suggestion | 🟠 Major

Add error handling for async workflow fetch.

The async operation lacks error handling. Network failures or database errors could cause unhandled promise rejections.

🔎 Proposed enhancement
   useEffect(()=>{
     async function getEmptyWorkflowID(){
-      const workflow = await getEmptyWorkflow()
-      
-      if(workflow){
-        const {id, isEmpty} = workflow
-        dispatch(workflowActions.setWorkflowId(id))
-        dispatch(workflowActions.setWorkflowStatus(isEmpty))
+      try {
+        const workflow = await getEmptyWorkflow()
+        
+        if(workflow){
+          const {id, isEmpty} = workflow
+          dispatch(workflowActions.setWorkflowId(id))
+          dispatch(workflowActions.setWorkflowStatus(isEmpty))
+        }
+      } catch (error) {
+        console.error('Failed to fetch empty workflow:', error);
       }
-      else{
-        const newWorkflow 
-      }
     }
     getEmptyWorkflowID()
   },[dispatch])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(()=>{
async function getEmptyWorkflowID(){
const workflow = await getEmptyWorkflow()
if(workflow){
const {id, isEmpty} = workflow
dispatch(workflowActions.setWorkflowId(id))
dispatch(workflowActions.setWorkflowStatus(isEmpty))
}
else{
const newWorkflow
}
}
getEmptyWorkflowID()
},[dispatch])
useEffect(()=>{
async function getEmptyWorkflowID(){
try {
const workflow = await getEmptyWorkflow()
if(workflow){
const {id, isEmpty} = workflow
dispatch(workflowActions.setWorkflowId(id))
dispatch(workflowActions.setWorkflowStatus(isEmpty))
}
} catch (error) {
console.error('Failed to fetch empty workflow:', error);
}
}
getEmptyWorkflowID()
},[dispatch])
🧰 Tools
🪛 Biome (2.1.2)

[error] 124-124: Const declarations must have an initialized value.

This variable needs to be initialized.

(parse)

🤖 Prompt for AI Agents
In apps/web/app/components/nodes/CreateWorkFlow.tsx around lines 114-128, the
async getEmptyWorkflow call has no error handling which can cause unhandled
promise rejections; wrap the await getEmptyWorkflow() call in a try/catch, log
the error (console.error or app logger), and handle failure by dispatching an
error or fallback workflow state (e.g., dispatch a workflow error action or
setWorkflowStatus(false)) and optionally show a user-facing notification; ensure
the catch prevents further state updates when the component is unmounted (use a
mounted flag or abort pattern) so no setState on unmounted component.


const handleSelectAction = (action: {
id: string;
Expand Down
15 changes: 15 additions & 0 deletions apps/web/app/workflow/lib/dbHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use server'

import { prismaClient } from "@repo/db";

export const getEmptyWorkflow = async() =>{
const workflow_id = await prismaClient.workflow.findFirst({
where:{
isEmpty: true
},
orderBy:{
createdAt: 'desc'
}
});
return workflow_id || null
}
Comment on lines +5 to +15

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix misleading variable naming and return type.

The function has several issues:

  1. Misleading variable name: workflow_id contains the entire workflow object, not just the ID.
  2. Return type inconsistency: The function returns the full workflow object but the variable name suggests only an ID is returned. This is confirmed by Line 119 in CreateWorkFlow.tsx which destructures {id, isEmpty} from the result.
  3. Missing return type annotation: The function should explicitly declare its return type.
  4. Redundant null coalescing: findFirst already returns null if no record is found, making || null redundant.
🔎 Proposed fix
-export const getEmptyWorkflow = async() =>{
-  const workflow_id = await prismaClient.workflow.findFirst({
+export const getEmptyWorkflow = async(): Promise<{id: string; isEmpty: boolean} | null> => {
+  const workflow = await prismaClient.workflow.findFirst({
     where:{
       isEmpty: true
     },
     orderBy:{
       createdAt: 'desc'
     }
   });
-  return workflow_id || null
+  return workflow
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const getEmptyWorkflow = async() =>{
const workflow_id = await prismaClient.workflow.findFirst({
where:{
isEmpty: true
},
orderBy:{
createdAt: 'desc'
}
});
return workflow_id || null
}
export const getEmptyWorkflow = async(): Promise<{id: string; isEmpty: boolean} | null> => {
const workflow = await prismaClient.workflow.findFirst({
where:{
isEmpty: true
},
orderBy:{
createdAt: 'desc'
}
});
return workflow
}
🤖 Prompt for AI Agents
In apps/web/app/workflow/lib/dbHandler.ts around lines 5 to 15, the function
uses a misleading variable name and lacks a return type: rename workflow_id to
workflow (or workflowRecord) to reflect that it holds the whole Workflow object,
add an explicit return type (Promise<Workflow | null> or the appropriate Prisma
Workflow type) on the function signature, remove the redundant "|| null" since
findFirst already returns null when not found, and return the workflow variable
directly; ensure you import or reference the correct Workflow type from your
Prisma client types if needed.

6 changes: 4 additions & 2 deletions apps/web/store/root-reducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { combineReducers } from "@reduxjs/toolkit";
import { userReducer } from "./slices/userSlice";
import { workflowReducer } from "./slices/workflowSlice";

export const rootReducer = combineReducers({
user: userReducer
})
user: userReducer,
workflow: workflowReducer
});
30 changes: 30 additions & 0 deletions apps/web/store/slices/workflowSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";

export interface WorkflowSlice{
workflow_id: string | null,
empty: boolean | null
}

const initialState: WorkflowSlice = {
workflow_id :null,
empty: true
}

const workflowSlice = createSlice({
name: 'workflow',
initialState,
reducers:{
setWorkflowId(state, action:PayloadAction<string | null>){
state.workflow_id = action.payload
},
setWorkflowStatus(state, action: PayloadAction<boolean | null>){
state.empty = action.payload
},
clearWorkflow(){
return initialState
}
}
})

export const workflowReducer = workflowSlice.reducer;
export const workflowActions = workflowSlice.actions;