From dcf0344914bd01e2b22ece303c2f6517565458e9 Mon Sep 17 00:00:00 2001 From: BUDUMURU SRINIVAS SAI SARAN TEJA Date: Thu, 25 Dec 2025 14:08:22 +0530 Subject: [PATCH] workflow slice added --- .../app/components/nodes/CreateWorkFlow.tsx | 29 +++++++++++++----- apps/web/app/workflow/lib/dbHandler.ts | 15 ++++++++++ apps/web/store/root-reducer.ts | 6 ++-- apps/web/store/slices/workflowSlice.ts | 30 +++++++++++++++++++ 4 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 apps/web/app/workflow/lib/dbHandler.ts create mode 100644 apps/web/store/slices/workflowSlice.ts diff --git a/apps/web/app/components/nodes/CreateWorkFlow.tsx b/apps/web/app/components/nodes/CreateWorkFlow.tsx index f30b074..60583a3 100644 --- a/apps/web/app/components/nodes/CreateWorkFlow.tsx +++ b/apps/web/app/components/nodes/CreateWorkFlow.tsx @@ -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"; @@ -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; @@ -35,6 +38,7 @@ export const CreateWorkFlow = () => { const [actionSidebarOpen, setActionSidebarOpen] = useState(false); const [credType, setCredType] = useState(""); const [loadSheet, setLoadSheet] = useState(false) + const dispatch = useDispatch(); const [nodes, setNodes] = useState([ { @@ -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]) const handleSelectAction = (action: { id: string; diff --git a/apps/web/app/workflow/lib/dbHandler.ts b/apps/web/app/workflow/lib/dbHandler.ts new file mode 100644 index 0000000..5780b06 --- /dev/null +++ b/apps/web/app/workflow/lib/dbHandler.ts @@ -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 +} diff --git a/apps/web/store/root-reducer.ts b/apps/web/store/root-reducer.ts index 015536a..d25ca57 100644 --- a/apps/web/store/root-reducer.ts +++ b/apps/web/store/root-reducer.ts @@ -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 -}) \ No newline at end of file + user: userReducer, + workflow: workflowReducer +}); \ No newline at end of file diff --git a/apps/web/store/slices/workflowSlice.ts b/apps/web/store/slices/workflowSlice.ts new file mode 100644 index 0000000..a9cbeeb --- /dev/null +++ b/apps/web/store/slices/workflowSlice.ts @@ -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){ + state.workflow_id = action.payload + }, + setWorkflowStatus(state, action: PayloadAction){ + state.empty = action.payload + }, + clearWorkflow(){ + return initialState + } + } +}) + +export const workflowReducer = workflowSlice.reducer; +export const workflowActions = workflowSlice.actions;