-
Notifications
You must be signed in to change notification settings - Fork 0
workflow slice added #41
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix misleading variable naming and return type. The function has several issues:
🔎 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ||
| }); |
| 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
🧰 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
🛠️ 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
🧰 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