feat: added workflows to all actions (#16691)

* feat: added workflows

* moved the condition from Editor to excludedToolbarItems

* revert editor changes

* Update WorkflowStepContainer.tsx

* update

---------

Co-authored-by: Anik Dhabal Babu <[email protected]>
Co-authored-by: unknown <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-10-01 18:50:17 +05:30
1 parent a95729f4a1
commit 706e8e4c1f
4 files changed
+44 -70

No files matched your search

@@ -161,14 +161,8 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
? form.register(`steps.${step.stepNumber - 1}.emailSubject`)
: { ref: null, name: "" };
const { ref: reminderBodyFormRef, ...restReminderBodyForm } = step
? form.register(`steps.${step.stepNumber - 1}.reminderBody`)
: { ref: null, name: "" };
const refEmailSubject = useRef<HTMLTextAreaElement | null>(null);
const refReminderBody = useRef<HTMLTextAreaElement | null>(null);
const getNumberVerificationStatus = () =>
!!step &&
!!verifiedNumbers.find(
@@ -185,17 +179,6 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
useEffect(() => setNumberVerified(getNumberVerificationStatus()), [verifiedNumbers.length]);
useEffect(() => setEmailVerified(getEmailVerificationStatus()), [verifiedEmails.length]);
const addVariableBody = (variable: string) => {
if (step) {
const currentMessageBody = refReminderBody?.current?.value || "";
const cursorPosition = refReminderBody?.current?.selectionStart || currentMessageBody.length;
const messageWithAddedVariable = `${currentMessageBody.substring(0, cursorPosition)}{${variable
.toUpperCase()
.replace(/ /g, "_")}}${currentMessageBody.substring(cursorPosition)}`;
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, messageWithAddedVariable);
}
};
const addVariableEmailSubject = (variable: string) => {
if (step) {
const currentEmailSubject = refEmailSubject?.current?.value || "";
@@ -920,57 +903,35 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
</div>
)}
{step.action !== WorkflowActions.SMS_ATTENDEE &&
step.action !== WorkflowActions.SMS_NUMBER ? (
<>
<div className="mb-2 flex items-center pb-[1.5px]">
<Label className="mb-0 flex-none ">
{isEmailSubjectNeeded ? t("email_body") : t("text_message")}
</Label>
</div>
<Editor
getText={() => {
return props.form.getValues(`steps.${step.stepNumber - 1}.reminderBody`) || "";
}}
setText={(text: string) => {
props.form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, text);
props.form.clearErrors();
}}
variables={DYNAMIC_TEXT_VARIABLES}
height="200px"
updateTemplate={updateTemplate}
firstRender={firstRender}
setFirstRender={setFirstRender}
editable={!props.readOnly && !isWhatsappAction(step.action)}
/>
</>
) : (
<>
<div className="flex items-center">
<Label className={classNames("flex-none", props.readOnly ? "mb-2" : "mb-0")}>
{isEmailSubjectNeeded ? t("email_body") : t("text_message")}
</Label>
{!props.readOnly && (
<div className="flex-grow text-right">
<AddVariablesDropdown
addVariable={addVariableBody}
variables={DYNAMIC_TEXT_VARIABLES}
/>
</div>
)}
</div>
<TextArea
ref={(e) => {
reminderBodyFormRef?.(e);
refReminderBody.current = e;
}}
className="my-0 h-24"
disabled={props.readOnly}
required
{...restReminderBodyForm}
/>
</>
)}
<div className="mb-2 flex items-center pb-1">
<Label className="mb-0 flex-none ">
{isEmailSubjectNeeded ? t("email_body") : t("text_message")}
</Label>
</div>
<Editor
getText={() => {
return props.form.getValues(`steps.${step.stepNumber - 1}.reminderBody`) || "";
}}
setText={(text: string) => {
props.form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, text);
props.form.clearErrors();
}}
variables={DYNAMIC_TEXT_VARIABLES}
addVariableButtonTop={
step.action === WorkflowActions.SMS_ATTENDEE || step.action === WorkflowActions.SMS_NUMBER
}
height="200px"
updateTemplate={updateTemplate}
firstRender={firstRender}
setFirstRender={setFirstRender}
editable={!props.readOnly && !isWhatsappAction(step.action)}
excludedToolbarItems={
step.action !== WorkflowActions.SMS_ATTENDEE && step.action !== WorkflowActions.SMS_NUMBER
? []
: ["blockType", "bold", "italic", "link"]
}
/>
{form.formState.errors.steps &&
form.formState?.errors?.steps[step.stepNumber - 1]?.reminderBody && (
<p className="mt-1 text-sm text-red-500">
+2
View File
@@ -36,6 +36,7 @@ export type TextEditorProps = {
setText: (text: string) => void;
excludedToolbarItems?: string[];
variables?: string[];
addVariableButtonTop?: boolean;
height?: string;
maxHeight?: string;
placeholder?: string;
@@ -80,6 +81,7 @@ export const Editor = (props: TextEditorProps) => {
editable={editable}
excludedToolbarItems={props.excludedToolbarItems}
variables={props.variables}
addVariableButtonTop={props.addVariableButtonTop}
updateTemplate={props.updateTemplate}
firstRender={props.firstRender}
setFirstRender={props.setFirstRender}
@@ -7,6 +7,7 @@ interface IAddVariablesDropdown {
addVariable: (variable: string) => void;
isTextEditor?: boolean;
variables: string[];
addVariableButtonTop?: boolean;
}
export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
@@ -22,7 +23,16 @@ export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
{t("add_variable")}
<Icon name="chevron-down" className="ml-1 mt-[2px] h-4 w-4" />
</div>
<div className="block sm:hidden">+</div>
<div className="block sm:hidden">
{props.addVariableButtonTop ? (
<div className="flex">
{t("add_variable")}
<Icon name="chevron-down" className="ml-1 mt-[2px] h-4 w-4" />
</div>
) : (
"+"
)}
</div>
</>
) : (
<div className="flex">
@@ -507,11 +507,12 @@ export default function ToolbarPlugin(props: TextEditorProps) {
)}
</>
{props.variables && (
<div className="ml-auto">
<div className={`${props.addVariableButtonTop ? "-mt-10" : ""} ml-auto`}>
<AddVariablesDropdown
addVariable={addVariable}
isTextEditor={true}
variables={props.variables || []}
addVariableButtonTop={props.addVariableButtonTop}
/>
</div>
)}