Skip to content

Scheduling infrastructure for absolutely everyone.

feat: when creating workflow from within event-type, preselect it (#14774)

Amit Sharma8b28a6f5dfdd
diff --git a/packages/features/ee/workflows/components/EventWorkflowsTab.tsx b/packages/features/ee/workflows/components/EventWorkflowsTab.tsx
index f45ec61ed7f..bf42cfb6900 100644
--- a/packages/features/ee/workflows/components/EventWorkflowsTab.tsx
+++ b/packages/features/ee/workflows/components/EventWorkflowsTab.tsx
@@ -233,7 +233,7 @@ function EventWorkflowsTab(props: Props) {
const createMutation = trpc.viewer.workflows.create.useMutation({
onSuccess: async ({ workflow }) => {
- await router.replace(`/workflows/${workflow.id}`);
+ await router.replace(`/workflows/${workflow.id}?eventTypeId=${eventType.id}`);
},
onError: (err) => {
if (err instanceof HttpError) {
diff --git a/packages/features/ee/workflows/components/WorkflowDetailsPage.tsx b/packages/features/ee/workflows/components/WorkflowDetailsPage.tsx
index 3e3a78f7c08..3de697e02ad 100644
--- a/packages/features/ee/workflows/components/WorkflowDetailsPage.tsx
+++ b/packages/features/ee/workflows/components/WorkflowDetailsPage.tsx
@@ -1,6 +1,6 @@
-import { useRouter } from "next/navigation";
+import { useRouter, useSearchParams } from "next/navigation";
import type { Dispatch, SetStateAction } from "react";
-import { useMemo, useState } from "react";
+import { useMemo, useState, useEffect } from "react";
import type { UseFormReturn } from "react-hook-form";
import { Controller } from "react-hook-form";
@@ -44,6 +44,9 @@ export default function WorkflowDetailsPage(props: Props) {
const { data, isPending } = trpc.viewer.eventTypes.getByViewer.useQuery();
+ const searchParams = useSearchParams();
+ const eventTypeId = searchParams.get("eventTypeId");
+
const eventTypeOptions = useMemo(
() =>
data?.eventTypeGroups.reduce((options, group) => {
@@ -83,6 +86,16 @@ export default function WorkflowDetailsPage(props: Props) {
});
}
+ useEffect(() => {
+ const matchingOption = allEventTypeOptions.find((option) => option.value === eventTypeId);
+ if (matchingOption && !selectedEventTypes.find((option) => option.value === eventTypeId)) {
+ const newOptions = [...selectedEventTypes, matchingOption];
+ setSelectedEventTypes(newOptions);
+ form.setValue("activeOn", newOptions);
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [eventTypeId, allEventTypeOptions]);
+
const addAction = (
action: WorkflowActions,
sendTo?: string,