Skip to content

Commit

Permalink
Added Events
Browse files Browse the repository at this point in the history
  • Loading branch information
anoopkarnik committed Jul 13, 2024
1 parent ed13e6c commit 015c46c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 27 deletions.
5 changes: 5 additions & 0 deletions apps/backend-server/src/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export const scheduleJob = async ()=>{

export const startWorkflows = async () => {
const workflows = await getActiveWorkflows();
if (workflows.length === 0){
logger.info('No active workflows found');
return;
}
logger.info('Found Active workflows',workflows.length);
workflows.forEach(async (workflow:any) => {
logger.info('Starting workflow',workflow.name);
const event = await createEvent(workflow.id, "processing")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState } from 'react';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@repo/ui/molecules/shadcn/Tabs';
import Notion from './action-forms/Notion';
import Webhook from './action-forms/Webhook';
import Schedule from './action-forms/Schedule';

const ActionTabs = ({type,actionType,subActions,node}:any) => {
const [subActionType, setSubActionType] = useState(undefined) as any;
Expand All @@ -26,6 +27,10 @@ const ActionTabs = ({type,actionType,subActions,node}:any) => {
actionType === 'Webhook' &&
<Webhook type={type} actionType={actionType} subActionType={subActionType} node={node}/>
}
{
actionType === 'Schedule' &&
<Schedule type={type} actionType={actionType} subActionType={subActionType} node={node}/>
}
</TabsContent>
</Tabs>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Button } from '@repo/ui/molecules/shadcn/Button';
import { Form, FormControl, FormField, FormItem, FormLabel } from '@repo/ui/molecules/shadcn/Form'
import { Input } from '@repo/ui/molecules/shadcn/Input';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@repo/ui/molecules/shadcn/Select'
import { Textarea } from '@repo/ui/molecules/shadcn/TextArea'
import React, { useContext } from 'react'
import { useForm } from 'react-hook-form';
import { addNodeToWorkflow, editNodeInWorkflow } from '../../../../../../../actions/workflows/workflow';
import { getSession } from 'next-auth/react';
import { useParams } from 'next/navigation';
import { EditorContext } from '../../../../../../../providers/editor-provider';
import { useRouter } from 'next/navigation';

const Schedule = ({type,actionType,subActionType,node}:any) => {
const form = useForm()
const { editorId } = useParams()
const editor = useContext(EditorContext);
const router = useRouter();
if (subActionType == 'Cron'){
const onSubmit = async (data:any) => {
const session = await getSession()
const userId = session?.user?.id
let name = `${type}-${actionType}-${subActionType}`
let description = `${type}-${actionType}-${subActionType}`
let id = node?.id

if (node.length ==0){
const node = await addNodeToWorkflow({name,description,workflowId: editorId,type,userId,actionType,subActionType,actionData:JSON.stringify(data)})
}
else{
const node = await editNodeInWorkflow({id,name,description,workflowId: editorId,type,userId,actionType,subActionType,actionData:JSON.stringify(data)})
}

if (type === 'Trigger') {
editor.setTrigger(node)
}
else {
editor.setActions([...editor.actions,node])
}
router.push(`/workflows/editor/${editorId}`)
}
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<div className='space-y-4 m-4 my-10'>
<FormField key='Cron Expression' control={form.control} name='Cron Expression' render={({field})=>(
<FormItem>
<FormLabel>Cron Expression</FormLabel>
<FormControl>
<Input placeholder='0 0 * * *' {...field} />

</FormControl>
</FormItem>
)}/>
<FormField key='Timezone' control={form.control} name='Timezone' render={({field})=>(
<FormItem>
<FormLabel>Timezone</FormLabel>
<FormControl>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<SelectTrigger>
<SelectValue placeholder='Select Time Zone'/>
</SelectTrigger>
<SelectContent>
<SelectItem value='Asia/Kolkata'>Asia/Kolkata</SelectItem>
<SelectItem value='Asia/Tokyo'>Asia/Tokyo</SelectItem>
</SelectContent>
</Select>
</FormControl>
</FormItem>
)}/>
<FormField key='Start Date' control={form.control} name='Start Date' render={({field})=>(
<FormItem>
<FormLabel>Start Date</FormLabel>
<FormControl>
<Input placeholder='Select Start Date' {...field} />

</FormControl>
</FormItem>
)}/>
<Button className='mt-4 ' variant="default" type="submit" > Add Node</Button>
</div>
</form>
</Form>
)}
}

export default Schedule
30 changes: 3 additions & 27 deletions apps/dashboard-app/lib/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,37 +155,13 @@ export const CONNECTIONS: Connection[] = [
{
actionType: 'Schedule',
icon: ClockIcon,
subActions: [
{
subActionType: 'Cron',
params: [
{name: 'Cron Expression', type: 'text', placeholder: '0 0 * * *'},
{name: 'Timezone', type: 'options', placeholder: 'Asia/Kolkata', options: [
'Asia/Kolkata',
'Asia/Tokyo',
'America/New_York',
'Europe/London'
]},
{name: 'Start Date', type: 'text', placeholder: '2022-01-01'}
]
},
]
subActions: ['Cron' ]
},
{
actionType: 'Webhook',
icon: WebhookIcon,
subActions: [
{
subActionType: 'Internal Webhook',
params: [
{ name:'Request Url', type: 'text', placeholder: 'https://example.com/webhook'},
{ name:'Request Method', type: 'options', placeholder: 'Select Method', options: ['GET', 'POST', 'PUT', 'DELETE','PATCH']},
{ name:'Request Body', type: 'json', placeholder: 'Enter JSON data'},
{ name:'Request Headers', type: 'json', placeholder: 'Enter JSON data'}
]
}
]
}
subActions: ['Internal Webhook']
},
]

export const ACTION_TYPES:any = [
Expand Down

0 comments on commit 015c46c

Please sign in to comment.