Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: org-wide workflows #15083

Draft
wants to merge 152 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 148 commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
8e15673
add org to create workflow button
Apr 25, 2024
03d1aa0
add save button for testing in dev mode
Apr 25, 2024
333f7f6
add select all to multi select dropdown
Apr 25, 2024
35e1bb6
fix select all
Apr 25, 2024
70bd85e
Merge branch 'main' into feat/org-wide-workflows
May 8, 2024
baec108
pass isOrg to WorkflowDetailsPage
May 8, 2024
2a35068
add checkbox to apply to all including future
May 8, 2024
65520de
fix count text on select
May 8, 2024
01484b4
WIP schema
May 9, 2024
4986700
Merge branch 'main' into feat/org-wide-workflows
May 9, 2024
b55440b
shows teams in dropdown
May 9, 2024
9a195c6
add team option to UI
May 9, 2024
a400c2b
[WIP] refactor for update handler
May 9, 2024
f3a1095
Merge branch 'main' into feat/org-wide-workflows
May 10, 2024
8780c4c
filter out "all" from activeOn
May 10, 2024
3716e46
fix type error
May 10, 2024
51f5484
create more helper functions
May 10, 2024
297a76d
create reusable function for scheduling all booking reminders
May 10, 2024
24f1160
finish update workflows for orgs (without testing)
May 10, 2024
04530ac
fix isAuthorized check for orgs
May 10, 2024
515eb2b
fix getting newActiveOn
May 10, 2024
12d4808
move all helper functions to util file
May 13, 2024
91d84c0
more code clean up
May 13, 2024
349f62f
fix deleting reminders for org workflows
May 14, 2024
3de7180
fix adding and editing steps
May 14, 2024
68ab037
update form data when workflow is saved
May 14, 2024
1a384f7
Merge branch 'main' into feat/org-wide-workflows
May 15, 2024
1c68170
code clean up
May 15, 2024
d9594f3
fixing creating/deleting reminders when user is member of several teams
May 15, 2024
fdb796b
fix setting activeOn for teams in useffect
May 15, 2024
399453f
Merge branch 'main' into feat/org-wide-workflows
May 16, 2024
675e2db
add on delete cascade
May 16, 2024
e566617
make multiSelectSchenbox searchable
May 16, 2024
7ec0e8e
set activeOn correctly when checkbox true
May 16, 2024
9a37979
WIP
May 17, 2024
8bcd0c4
Merge branch 'main' into feat/org-wide-workflows
May 17, 2024
f203a59
fix type errors in MultiSelectCheckboxes
May 17, 2024
54101c8
implemented scheduling org-wide workfow notifications (not yet tested)
May 17, 2024
cc0bd36
fix type errors
May 17, 2024
414eff3
type error
May 17, 2024
81d0fcd
Merge branch 'main' into feat/org-wide-workflows
May 20, 2024
b4cbc30
add missing changes from merge conflict
May 20, 2024
7cb6d63
Merge branch 'main' into feat/org-wide-workflows
May 24, 2024
2001aca
remote not needed include statement
May 24, 2024
4b75691
fix type errors
May 24, 2024
3b46270
code clean up + some todo comments
May 24, 2024
7680906
support org workflows for cancelled workflows
May 24, 2024
efaa7fe
delete reminders from removed members
May 24, 2024
6dd74e6
remove reminders if isActiveOnAll is turned off
May 24, 2024
b6c2ca7
Merge branch 'main' into feat/org-wide-workflows
May 27, 2024
7daad6f
fix unti test and type error
May 27, 2024
a0c309e
code clean up
May 27, 2024
f9646d7
create basis for testing to book org team event
May 28, 2024
c43077e
create org workflow with active team
May 28, 2024
ad21de4
fix getting active org workflows on team + test setup
May 28, 2024
07bc432
fix creating workflow step for tests
May 28, 2024
f31dbf6
fix first org test
May 28, 2024
96d9fd6
add test for user event type with org workflow active
May 28, 2024
5fb3e6f
use deleteAllWorkflowReminders everywhere
May 29, 2024
f3327f7
add test for deleteRemindersFromRemovedActiveOn
May 29, 2024
802a43a
Merge branch 'main' into feat/org-wide-workflows
May 30, 2024
9e1a48c
fix type errors
May 30, 2024
7ebda27
make all tests pass
May 30, 2024
38a66ce
fix type error
May 30, 2024
76ba65f
fix getSchedule test
May 30, 2024
43dd3bd
code clean up
May 30, 2024
cfe6d11
add missing import
May 30, 2024
7145de3
fix type error
May 30, 2024
7eb6caa
fix tests
May 30, 2024
4de817d
code clean up
May 30, 2024
3de7157
Merge branch 'main' into feat/org-wide-workflows
May 31, 2024
8c6653c
fix imports
May 31, 2024
8976e94
Merge branch 'main' into feat/org-wide-workflows
May 31, 2024
1b00ff7
update reminders when trigger was changed
May 31, 2024
890d476
check for teamId before userId in reminderScheduler
May 31, 2024
218ed3d
Merge branch 'main' into feat/org-wide-workflows
Jun 3, 2024
af3b9e6
move getOrgIdFromMemberOrTeamId to different folder
Jun 3, 2024
79b2666
code clean up
Jun 3, 2024
87fe6f5
fix tests
Jun 3, 2024
700a5e6
test setup for scheduleBookingReminders
Jun 3, 2024
f512ad5
fix typo
Jun 4, 2024
b5546d6
Merge branch 'main' into feat/org-wide-workflows
CarinaWolli Jun 4, 2024
48ca813
add tests for scheduleBookingReminders
Jun 4, 2024
afd07bc
fix prisma default import
Jun 4, 2024
76ae430
fix workflowStep type
Jun 4, 2024
3fdacd4
add scheduleBookingReminders test for sms
Jun 4, 2024
12072db
return dummy sid for scheduleSMS testMode
Jun 4, 2024
cec11c5
Merge branch 'main' into feat/org-wide-workflows
Jun 4, 2024
c01fa1c
clean up + fixes
Jun 4, 2024
7b489c7
Merge branch 'main' into feat/org-wide-workflows
Jun 5, 2024
4a1a1a3
add lost changes from merge
Jun 5, 2024
74099d5
get teamId and userId from incoming evt object
Jun 5, 2024
b1aa38b
removing not needed select
Jun 5, 2024
8aedb5f
add org support for scheduleMandatory email reminder
Jun 5, 2024
d976d2c
add other teams to dropdown
Jun 5, 2024
894b151
move getAllWorkflows to seperate file and call it in parent function
Jun 5, 2024
5199363
include org wide workflows in createNewSeat
Jun 5, 2024
2720d31
some fixes + code clean up
Jun 6, 2024
8a7c377
add new team to select text count when including future teams is checked
Jun 6, 2024
c26fcb2
fix upsert and remove sms reminder field
Jun 6, 2024
2abe109
correctly update activeOn if 'including future ...' is enabled
Jun 6, 2024
7ae2ee4
list active Org workflows in event workflows settings
Jun 7, 2024
c346e8a
fix sms reminder field in all handlers
Jun 7, 2024
f021aa6
add helper function to check if step was edited
Jun 7, 2024
ff49acc
fix active on badge on workflow
Jun 7, 2024
d64857a
fix type error
Jun 7, 2024
db7eb2f
fix double reminders
Jun 7, 2024
8fa622c
Merge branch 'main' into feat/org-wide-workflows
Jun 7, 2024
cd4f3fc
add teamId: null for userWorkflow query
Jun 10, 2024
74c9809
fix activeOnAll with managed event types
Jun 10, 2024
9d1b3b8
add missing teamId in getAllWorkflows
Jun 10, 2024
1f865e6
add a dafaut to prisma param
Jun 10, 2024
8698d92
fix managed event types on select all user workflows
Jun 10, 2024
7268fef
code clean up
Jun 10, 2024
d8436ea
Merge branch 'main' into feat/org-wide-workflows
Jun 10, 2024
77af1dc
better variable name
Jun 10, 2024
ec27c9c
small fixes in update handler
Jun 11, 2024
f661e6a
Merge branch 'main' into feat/org-wide-workflows
Jun 11, 2024
5c7e7b6
fix test name to match function name
Jun 12, 2024
809313b
add info badge
Jun 12, 2024
303798e
fix workflow count in event type settings
Jun 12, 2024
8a45ef0
fix getting bookings from children manged event types
Jun 12, 2024
db0e126
delete reminders when user is not part of any time no more
Jun 12, 2024
56e7a51
Merge branch 'main' into feat/org-wide-workflows
Jun 13, 2024
24ce376
implement feedback
Jun 13, 2024
a6f2cd4
fix disbale workflow in event type settings
Jun 13, 2024
9b8467d
fix remove member
Jun 13, 2024
6ff11a7
create new function getAllWorkflowsFromEventType
Jun 13, 2024
db73d86
add some removed code
Jun 13, 2024
7bd03da
use promise.allSettled when deleting workflow reminders
Jun 13, 2024
2581f97
create new function deleteWorkflowRemindersOfRemovedMember.ts
Jun 13, 2024
b163a40
fix userId param
Jun 13, 2024
3371a18
delete org worklfows when team is disbanded
Jun 13, 2024
77150ac
don't trigger active on all workflow if not part of any team
Jun 14, 2024
240b21a
fix active on count badge
Jun 14, 2024
2ce9c36
add test for deleteWorkflowRemidnersOfRemovedMember
Jun 17, 2024
11e3313
trigger workflow also if not member of any subteam
Jun 17, 2024
da7f4ce
fix failing test
Jun 17, 2024
a11b491
Merge branch 'main' into feat/org-wide-workflows
hariombalhara Jun 20, 2024
1fee74d
Merge branch 'main' into feat/org-wide-workflows
Jun 20, 2024
b52e568
remove unused code
Jun 20, 2024
a1c607a
use testId for go back button
Jun 20, 2024
43cc771
fixes for managed event types & activateEventTypeHandler
Jun 20, 2024
1f5745e
code clean up
Jun 20, 2024
73e79a4
don't activate workflow on locked managed event type
Jun 20, 2024
787ea5c
fix type error
Jun 20, 2024
5fb8797
type error
Jun 20, 2024
c5b8ad8
more type fixes
Jun 20, 2024
ea0a8d8
feedback
Jun 21, 2024
1e79f55
Merge branch 'main' into feat/org-wide-workflows
CarinaWolli Jun 21, 2024
acf15f3
Merge branch 'main' into feat/org-wide-workflows
keithwillcode Jun 24, 2024
b3cef50
Merge branch 'main' into feat/org-wide-workflows
Udit-takkar Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions apps/web/lib/booking.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
import { bookingResponsesDbSchema } from "@calcom/features/bookings/lib/getBookingResponsesSchema";
import { workflowSelect } from "@calcom/features/ee/workflows/lib/getAllWorkflows";
import prisma from "@calcom/prisma";
import type { Prisma } from "@calcom/prisma/client";
import { BookingStatus } from "@calcom/prisma/enums";
Expand Down Expand Up @@ -61,10 +62,7 @@ export const getEventTypesFromDB = async (id: number) => {
workflows: {
select: {
workflow: {
select: {
id: true,
steps: true,
},
select: workflowSelect,
},
},
},
Expand Down
35 changes: 27 additions & 8 deletions apps/web/modules/event-types/views/event-types-single-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import checkForMultiplePaymentApps from "@calcom/app-store/_utils/payments/checkForMultiplePaymentApps";
import { getEventLocationType } from "@calcom/app-store/locations";
import { validateCustomEventName } from "@calcom/core/event";
import type { Workflow } from "@calcom/features/ee/workflows/lib/types";
import type { ChildrenEventType } from "@calcom/features/eventtypes/components/ChildrenEventTypeSelect";
import type { FormValues } from "@calcom/features/eventtypes/lib/types";
import { validateIntervalLimitOrder } from "@calcom/lib";
Expand Down Expand Up @@ -143,7 +144,7 @@
export type EventTypeSetupProps = RouterOutputs["viewer"]["eventTypes"]["get"];
export type EventTypeSetup = RouterOutputs["viewer"]["eventTypes"]["get"]["eventType"];

const EventTypePage = (props: EventTypeSetupProps) => {
const EventTypePage = (props: EventTypeSetupProps & { allActiveWorkflows?: Workflow[] }) => {
const { t } = useLocale();
const utils = trpc.useUtils();
const telemetry = useTelemetry();
Expand Down Expand Up @@ -227,7 +228,7 @@
return () => {
router.events.off("routeChangeStart", handleRouteChange);
};
}, [router]);

Check warning on line 231 in apps/web/modules/event-types/views/event-types-single-view.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/modules/event-types/views/event-types-single-view.tsx#L231

[react-hooks/exhaustive-deps] React Hook useEffect has missing dependencies: 'eventType.hosts.length' and 'team'. Either include them or remove the dependency array.

const [periodDates] = useState<{ startDate: Date; endDate: Date }>({
startDate: new Date(eventType.periodStartDate || Date.now()),
Expand Down Expand Up @@ -451,11 +452,10 @@
instant: <EventInstantTab eventType={eventType} isTeamEvent={!!team} />,
recurring: <EventRecurringTab eventType={eventType} />,
apps: <EventAppsTab eventType={{ ...eventType, URL: permalink }} />,
workflows: (
<EventWorkflowsTab
eventType={eventType}
workflows={eventType.workflows.map((workflowOnEventType) => workflowOnEventType.workflow)}
/>
workflows: props.allActiveWorkflows ? (
<EventWorkflowsTab eventType={eventType} workflows={props.allActiveWorkflows} />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use all active workflows here, not just eventType.workflows

Before we missed workflows that have isActiveOnAll enabled and weren't in activeOn

) : (
<></>
),
webhooks: <EventWebhooksTab eventType={eventType} />,
ai: <EventAITab eventType={eventType} isTeamEvent={!!team} />,
Expand Down Expand Up @@ -692,7 +692,7 @@
<EventTypeSingleLayout
enabledAppsNumber={numberOfActiveApps}
installedAppsNumber={eventTypeApps?.items.length || 0}
enabledWorkflowsNumber={eventType.workflows.length}
enabledWorkflowsNumber={props.allActiveWorkflows ? props.allActiveWorkflows.length : 0}
eventType={eventType}
activeWebhooksNumber={eventType.webhooks.filter((webhook) => webhook.active).length}
team={team}
Expand Down Expand Up @@ -840,7 +840,26 @@
const { data } = trpc.viewer.eventTypes.get.useQuery({ id: props.type });

if (!data) return null;
return <EventTypePage {...(data as EventTypeSetupProps)} />;

const eventType = data.eventType;

const { data: workflows } = trpc.viewer.workflows.getAllActiveWorkflows.useQuery({
eventType: {
workflows: eventType.workflows,
CarinaWolli marked this conversation as resolved.
Show resolved Hide resolved
teamId: eventType.teamId,
userId: eventType.userId,
parentId: eventType.parentId,
parent: eventType.parent,
CarinaWolli marked this conversation as resolved.
Show resolved Hide resolved
metadata: eventType.metadata,
},
});

const propsData = {
...(data as EventTypeSetupProps),
allActiveWorkflows: workflows,
};

return <EventTypePage {...propsData} />;
};

export default EventTypePageWrapper;
2 changes: 1 addition & 1 deletion apps/web/playwright/availability.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ test.describe("Availablity", () => {
await expect(page.getByTestId("availablity-title")).toHaveValue("More working hours");
});
await test.step("Can delete a schedule", async () => {
await page.getByRole("button", { name: /Go Back/i }).click();
await page.getByTestId("go-back-button").click();
await page.locator('[data-testid="schedules"] > li').nth(1).getByTestId("schedule-more").click();
await page.locator('[data-testid="delete-schedule"]').click();
const toast = await page.waitForSelector('[data-testid="toast-success"]');
Expand Down
3 changes: 2 additions & 1 deletion apps/web/playwright/fixtures/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function createWorkflowPageFixture(page: Page) {
await selectEventType("30 min");
}
await saveWorkflow();
await page.getByTestId("go-back-button").click();
};

const saveWorkflow = async () => {
Expand Down Expand Up @@ -71,7 +72,7 @@ export function createWorkflowPageFixture(page: Page) {
};

const selectEventType = async (name: string) => {
await page.getByText("Select...").click();
await page.getByTestId("multi-select-check-boxes").click();
await page.getByText(name, { exact: true }).click();
};

Expand Down
3 changes: 2 additions & 1 deletion apps/web/playwright/workflow.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ test.describe("Workflow Tab - Event Type", () => {
await assertListCount(3);
});

test("Editing an existing workflow", async ({ workflowPage }) => {
test("Editing an existing workflow", async ({ workflowPage, page }) => {
const { saveWorkflow, fillNameInput, editSelectedWorkflow, hasWorkflowInList } = workflowPage;

await editSelectedWorkflow("Test Workflow");
await fillNameInput("Edited Workflow");
await saveWorkflow();
await page.getByTestId("go-back-button").click();
await hasWorkflowInList("Edited Workflow");
});

Expand Down
11 changes: 11 additions & 0 deletions apps/web/public/static/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,8 @@
"may_require_confirmation": "May require confirmation",
"nr_event_type_one": "{{count}} event type",
"nr_event_type_other": "{{count}} event types",
"count_team_one": "{{count}} team",
"count_team_other": "{{count}} teams",
"add_action": "Add action",
"set_whereby_link": "Set Whereby link",
"invalid_whereby_link": "Please enter a valid Whereby Link",
Expand Down Expand Up @@ -1273,7 +1275,12 @@
"problem_updating_calendar": "There was a problem updating your calendar",
"active_on_event_types_one": "Active on {{count}} event type",
"active_on_event_types_other": "Active on {{count}} event types",
"active_on_teams_one": "Active on {{count}} team",
"active_on_teams_other": "Active on {{count}} teams",
"active_on_all_event_types": "Active on all event types",
"active_on_all_teams": "Active on all teams",
"no_active_event_types": "No active event types",
"no_active_teams": "No active teams",
"new_seat_subject": "New Attendee {{name}} on {{eventType}} at {{date}}",
"new_seat_title": "Someone has added themselves to an event",
"variable": "Variable",
Expand Down Expand Up @@ -1339,6 +1346,9 @@
"2fa_required": "Two factor authentication required",
"incorrect_2fa": "Incorrect two factor authentication code",
"which_event_type_apply": "Which event type will this apply to?",
"apply_to_all_event_types": "Apply to all, including future event types",
"apply_to_all_teams": "Apply to all team and user event types",
"which_team_apply": "Which team will this apply to?",
"no_workflows_description": "Workflows enable simple automation to send notifications & reminders enabling you to build processes around your events.",
"timeformat_profile_hint": "This is an internal setting and will not affect how times are displayed on public booking pages for you or anyone booking you.",
"create_workflow": "Create a workflow",
Expand Down Expand Up @@ -2475,6 +2485,7 @@
"mark_as_no_show_title": "Mark as no show",
"x_marked_as_no_show": "{{x}} marked as no-show",
"x_unmarked_as_no_show": "{{x}} unmarked as no-show",
"team_select_info": "triggers for all team event types and all team members' personal event types",
"no_show_updated": "No-show status updated for attendees",
"email_copied": "Email copied",
"USER_PENDING_MEMBER_OF_THE_ORG": "User is a pending member of the organization",
Expand Down
33 changes: 15 additions & 18 deletions apps/web/test/lib/getSchedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1419,24 +1419,21 @@ describe("getSchedule", () => {
});

const scenario = await createBookingScenario(
getScenarioData(
{
eventTypes: [
{
id: 1,
slotInterval: 45,
length: 45,
users: [
{
id: 101,
},
],
},
],
organizer,
},
{ id: org.id }
)
getScenarioData({
eventTypes: [
{
id: 1,
slotInterval: 45,
length: 45,
users: [
{
id: 101,
},
],
},
],
organizer,
})
);

const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
Expand Down
Loading
Loading