Skip to content

Commit

Permalink
Wrap into input + use context + add email field
Browse files Browse the repository at this point in the history
  • Loading branch information
thomtrp committed Oct 15, 2024
1 parent 1492340 commit 1330a1c
Show file tree
Hide file tree
Showing 17 changed files with 213 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { GMAIL_SEND_SCOPE } from '@/accounts/constants/GmailSendScope';
import { ConnectedAccount } from '@/accounts/types/ConnectedAccount';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { useTriggerGoogleApisOAuth } from '@/settings/accounts/hooks/useTriggerGoogleApisOAuth';
import { Select, SelectOption } from '@/ui/input/components/Select';
import { TextArea } from '@/ui/input/components/TextArea';
import { TextInput } from '@/ui/input/components/TextInput';
import { WorkflowEditActionFormBase } from '@/workflow/components/WorkflowEditActionFormBase';
import { workflowIdState } from '@/workflow/states/workflowIdState';
import { WorkflowSendEmailStep } from '@/workflow/types/Workflow';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import React, { useEffect } from 'react';
import { useEffect } from 'react';
import { Controller, useForm } from 'react-hook-form';
import { useRecoilValue } from 'recoil';
import { IconMail, IconPlus, isDefined } from 'twenty-ui';
import { useDebouncedCallback } from 'use-debounce';
import { Select, SelectOption } from '@/ui/input/components/Select';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { ConnectedAccount } from '@/accounts/types/ConnectedAccount';
import { useRecoilValue } from 'recoil';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useTriggerGoogleApisOAuth } from '@/settings/accounts/hooks/useTriggerGoogleApisOAuth';
import { workflowIdState } from '@/workflow/states/workflowIdState';
import { GMAIL_SEND_SCOPE } from '@/accounts/constants/GmailSendScope';

const StyledTriggerSettings = styled.div`
padding: ${({ theme }) => theme.spacing(6)};
Expand All @@ -37,6 +37,7 @@ type WorkflowEditActionFormSendEmailProps =

type SendEmailFormData = {
connectedAccountId: string;
email: string;
subject: string;
body: string;
};
Expand All @@ -53,6 +54,7 @@ export const WorkflowEditActionFormSendEmail = (
const form = useForm<SendEmailFormData>({
defaultValues: {
connectedAccountId: '',
email: '',
subject: '',
body: '',
},
Expand Down Expand Up @@ -83,10 +85,11 @@ export const WorkflowEditActionFormSendEmail = (
useEffect(() => {
form.setValue(
'connectedAccountId',
props.action.settings.connectedAccountId ?? '',
props.action.settings.input.connectedAccountId ?? '',
);
form.setValue('subject', props.action.settings.subject ?? '');
form.setValue('body', props.action.settings.body ?? '');
form.setValue('email', props.action.settings.input.email ?? '');
form.setValue('subject', props.action.settings.input.subject ?? '');
form.setValue('body', props.action.settings.input.body ?? '');
}, [props.action.settings, form]);

const saveAction = useDebouncedCallback(
Expand All @@ -99,9 +102,12 @@ export const WorkflowEditActionFormSendEmail = (
...props.action,
settings: {
...props.action.settings,
connectedAccountId: formData.connectedAccountId,
subject: formData.subject,
body: formData.body,
input: {
connectedAccountId: formData.connectedAccountId,
email: formData.email,
subject: formData.subject,
body: formData.body,
},
},
});

Expand Down Expand Up @@ -134,12 +140,12 @@ export const WorkflowEditActionFormSendEmail = (
};

if (
isDefined(props.action.settings.connectedAccountId) &&
props.action.settings.connectedAccountId !== ''
isDefined(props.action.settings.input.connectedAccountId) &&
props.action.settings.input.connectedAccountId !== ''
) {
filter.or.push({
id: {
eq: props.action.settings.connectedAccountId,
eq: props.action.settings.input.connectedAccountId,
},
});
}
Expand Down Expand Up @@ -198,6 +204,21 @@ export const WorkflowEditActionFormSendEmail = (
/>
)}
/>
<Controller
name="email"
control={form.control}
render={({ field }) => (
<TextInput
label="Email"
placeholder="Enter receiver email (use {{variable}} for dynamic content)"
value={field.value}
onChange={(email) => {
field.onChange(email);
handleSave();
}}
/>
)}
/>
<Controller
name="subject"
control={form.control}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const WorkflowEditActionFormServerlessFunction = (
dropdownId="workflow-edit-action-function"
label="Function"
fullWidth
value={props.action.settings.serverlessFunctionId}
value={props.action.settings.input.serverlessFunctionId}
options={availableFunctions}
disabled={props.readonly}
onChange={(updatedFunction) => {
Expand All @@ -66,7 +66,9 @@ export const WorkflowEditActionFormServerlessFunction = (
...props.action,
settings: {
...props.action.settings,
serverlessFunctionId: updatedFunction,
input: {
serverlessFunctionId: updatedFunction,
},
},
});
}}
Expand Down
13 changes: 9 additions & 4 deletions packages/twenty-front/src/modules/workflow/types/Workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ type BaseWorkflowStepSettings = {
};

export type WorkflowCodeStepSettings = BaseWorkflowStepSettings & {
serverlessFunctionId: string;
input: {
serverlessFunctionId: string;
};
};

export type WorkflowSendEmailStepSettings = BaseWorkflowStepSettings & {
connectedAccountId: string;
subject?: string;
body?: string;
input: {
connectedAccountId: string;
email: string;
subject?: string;
body?: string;
};
};

type BaseWorkflowStep = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ describe('addCreateStepNodes', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
},
{
Expand All @@ -34,7 +36,9 @@ describe('addCreateStepNodes', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ describe('generateWorkflowDiagram', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
},
{
Expand All @@ -55,7 +57,9 @@ describe('generateWorkflowDiagram', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
},
];
Expand Down Expand Up @@ -96,7 +100,9 @@ describe('generateWorkflowDiagram', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
},
{
Expand All @@ -109,7 +115,9 @@ describe('generateWorkflowDiagram', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ describe('getWorkflowVersionDiagram', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
type: 'CODE',
valid: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ describe('insertStep', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
type: 'CODE',
valid: true,
Expand Down Expand Up @@ -63,7 +65,9 @@ describe('insertStep', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
type: 'CODE',
valid: true,
Expand Down Expand Up @@ -95,7 +99,9 @@ describe('insertStep', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
type: 'CODE',
valid: true,
Expand All @@ -108,7 +114,9 @@ describe('insertStep', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
type: 'CODE',
valid: true,
Expand All @@ -129,7 +137,9 @@ describe('insertStep', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
type: 'CODE',
valid: true,
Expand Down Expand Up @@ -165,7 +175,9 @@ describe('insertStep', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
type: 'CODE',
valid: true,
Expand All @@ -178,7 +190,9 @@ describe('insertStep', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
type: 'CODE',
valid: true,
Expand All @@ -199,7 +213,9 @@ describe('insertStep', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
type: 'CODE',
valid: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ it('returns a deep copy of the provided steps array instead of mutating it', ()
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'first',
input: {
serverlessFunctionId: 'first',
},
},
type: 'CODE',
valid: true,
Expand Down Expand Up @@ -47,7 +49,9 @@ it('removes a step in a non-empty steps array', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
type: 'CODE',
valid: true,
Expand All @@ -67,7 +71,9 @@ it('removes a step in a non-empty steps array', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
type: 'CODE',
valid: true,
Expand All @@ -81,7 +87,9 @@ it('removes a step in a non-empty steps array', () => {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
},
type: 'CODE',
valid: true,
Expand Down
Loading

0 comments on commit 1330a1c

Please sign in to comment.