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

refactor: Team Creation Flow [CAL-2751] #12501

Merged
merged 32 commits into from
Nov 29, 2023
Merged

refactor: Team Creation Flow [CAL-2751] #12501

merged 32 commits into from
Nov 29, 2023

Conversation

joeauyeung
Copy link
Contributor

@joeauyeung joeauyeung commented Nov 22, 2023

What does this PR do?

This PR changes the team creation flow. Currently you would have the option to create a team and then go through the Stripe checkout flow to publish the team.

This PR changes the flow so now, to create a team you need an active subscription before continuing.

Fixes # (issue)

https://www.loom.com/share/47e1a588a85d4e6fa47a989dee55282b

Requirement/Documentation

  • If there is a requirement document, please, share it here.
  • If there is ab UI/UX design document, please, share it here.

Type of change

  • Chore (refactoring code, technical debt, workflow improvements)

How should this be tested?

  • Before checking out the branch, create a team but do not publish
  • Now checkout the branch this PR is on
  • Fill in the first step of creating a team
  • You should be brought to the checkout page. Complete this step
  • After you should be brought back to the add members page with the team now created in the DB

Mandatory Tasks

  • Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.

Checklist

  • I haven't added tests that prove my fix is effective or that my feature works
  • I haven't checked if new and existing unit tests pass locally with my changes

Copy link

vercel bot commented Nov 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 29, 2023 4:20pm
dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 29, 2023 4:20pm
5 Ignored Deployments
Name Status Preview Comments Updated (UTC)
ai ⬜️ Ignored (Inspect) Visit Preview Nov 29, 2023 4:20pm
cal ⬜️ Ignored (Inspect) Visit Preview Nov 29, 2023 4:20pm
cal-demo ⬜️ Ignored (Inspect) Visit Preview Nov 29, 2023 4:20pm
qa ⬜️ Ignored (Inspect) Visit Preview Nov 29, 2023 4:20pm
ui ⬜️ Ignored (Inspect) Visit Preview Nov 29, 2023 4:20pm

Copy link
Contributor

github-actions bot commented Nov 22, 2023

Thank you for following the naming conventions! 🙏 Feel free to join our discord and post your PR link to collect XP and win prizes!

@zomars zomars added the core area: core, team members only label Nov 22, 2023
Copy link
Contributor

github-actions bot commented Nov 22, 2023

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

Fifty-one Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load % of Budget (350 KB)
/apps 266.92 KB 430.38 KB 122.97% (🟢 -3.10%)
/apps/[slug] 285.04 KB 448.5 KB 128.14% (🟢 -2.97%)
/apps/[slug]/[...pages] 542.07 KB 705.53 KB 201.58% (🟢 -3.09%)
/apps/categories 244.79 KB 408.25 KB 116.64% (🟢 -3.11%)
/apps/categories/[category] 249.46 KB 412.92 KB 117.98% (🟢 -2.99%)
/apps/installed/[category] 268.77 KB 432.23 KB 123.49% (🟢 -2.89%)
/availability 382.51 KB 545.97 KB 155.99% (🟢 -3.09%)
/availability/[schedule] 348.42 KB 511.88 KB 146.25% (🟢 -3.09%)
/availability/troubleshoot 270.08 KB 433.54 KB 123.87% (🟢 -3.09%)
/bookings/[status] 314.45 KB 477.91 KB 136.54% (🟢 -3.10%)
/enterprise 245.25 KB 408.71 KB 116.78% (🟢 -3.12%)
/event-types 540.55 KB 704.01 KB 201.15% (🟢 -3.07%)
/event-types/[type] 417.37 KB 580.83 KB 165.95% (🟢 -2.87%)
/getting-started/[[...step]] 400.94 KB 564.4 KB 161.26% (🟡 +0.30%)
/insights 470.85 KB 634.31 KB 181.23% (🟢 -3.09%)
/more 244.42 KB 407.89 KB 116.54% (🟢 -3.12%)
/settings/admin 251.07 KB 414.54 KB 118.44% (🟢 -3.12%)
/settings/admin/apps 264.18 KB 427.64 KB 122.18% (🟢 -3.09%)
/settings/admin/apps/[category] 264.17 KB 427.63 KB 122.18% (🟢 -3.09%)
/settings/admin/flags 254.83 KB 418.29 KB 119.51% (🟢 -3.09%)
/settings/admin/impersonation 251.34 KB 414.8 KB 118.51% (🟢 -3.11%)
/settings/admin/organizations 252.37 KB 415.83 KB 118.81% (🟢 -3.12%)
/settings/admin/users 253.29 KB 416.75 KB 119.07% (🟢 -3.12%)
/settings/billing 251.29 KB 414.75 KB 118.50% (🟢 -3.12%)
/settings/developer/api-keys 255.69 KB 419.15 KB 119.76% (🟢 -3.09%)
/settings/developer/webhooks 255.61 KB 419.07 KB 119.74% (🟢 -3.09%)
/settings/developer/webhooks/[id] 256.99 KB 420.45 KB 120.13% (🟢 -2.93%)
/settings/developer/webhooks/new 257.05 KB 420.51 KB 120.15% (🟢 -2.93%)
/settings/my-account/appearance 274.67 KB 438.13 KB 125.18% (🟢 -3.09%)
/settings/my-account/calendars 258.81 KB 422.27 KB 120.65% (🟢 -3.98%)
/settings/my-account/conferencing 262.94 KB 426.4 KB 121.83% (🟢 -3.05%)
/settings/my-account/general 339.48 KB 502.95 KB 143.70% (🟢 -3.06%)
/settings/organizations/appearance 263.68 KB 427.14 KB 122.04% (🟢 -3.09%)
/settings/organizations/billing 251.32 KB 414.78 KB 118.51% (🟢 -3.12%)
/settings/organizations/general 331.99 KB 495.45 KB 141.56% (🟢 -3.12%)
/settings/organizations/teams/other 252.15 KB 415.61 KB 118.75% (🟢 -3.12%)
/settings/organizations/teams/other/[id]/appearance 263.77 KB 427.23 KB 122.07% (🟢 -3.09%)
/settings/organizations/teams/other/[id]/members 258.15 KB 421.61 KB 120.46% (🟢 -3.09%)
/settings/security/impersonation 256.37 KB 419.83 KB 119.95% (🟢 -3.09%)
/settings/security/password 265.15 KB 428.61 KB 122.46% (🟢 -3.09%)
/settings/security/sso 260.32 KB 423.78 KB 121.08% (🟢 -3.12%)
/settings/security/two-factor-auth 260.21 KB 423.67 KB 121.05% (🟢 -3.09%)
/settings/teams 250.82 KB 414.28 KB 118.37% (🟢 -3.12%)
/settings/teams/[id]/appearance 263.76 KB 427.22 KB 122.06% (🟢 -3.09%)
/settings/teams/[id]/billing 251.32 KB 414.78 KB 118.51% (🟢 -3.12%)
/settings/teams/[id]/members 377.06 KB 540.52 KB 154.43% (🟢 -3.08%)
/settings/teams/[id]/sso 260.84 KB 424.3 KB 121.23% (🟢 -3.12%)
/settings/teams/new 181.38 KB 344.84 KB 98.53% (🟢 -3.12%)
/teams 244.7 KB 408.16 KB 116.62% (🟢 -3.12%)
/workflows 282.73 KB 446.19 KB 127.48% (🟢 -3.12%)
/workflows/[workflow] 396.19 KB 559.65 KB 159.90% (🟢 -3.09%)
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/- <0.01%" it means that there was a change in bundle size, but it is a trivial enough amount that it can be ignored.

Copy link

deploysentinel bot commented Nov 22, 2023

Current Playwright Test Results Summary

✅ 347 Passing - ⚠️ 6 Flaky

Run may still be in progress, this comment will be updated as current testing workflow or job completes...

(Last updated on 11/29/2023 04:25:13pm UTC)

Run Details

Running Workflow PR Update on Github Actions

Commit: 792d6a0

Started: 11/29/2023 04:16:49pm UTC

⚠️ Flakes

📄   apps/web/playwright/booking/checkboxGroupQuestion.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Booking With Checkbox Group Question and Each Other Question Booking With Checkbox Group Question and Address Question Booking With Checkbox Group Question and Multi email Question Checkbox Group and Multi email not required
Retry 1Initial Attempt
0% (0) 0 / 292 runs
failed over last 7 days
1.03% (3) 3 / 292 runs
flaked over last 7 days

📄   apps/web/playwright/event-types.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Event Types tests user -- future can add multiple organizer address
Retry 1Initial Attempt
0% (0) 0 / 249 runs
failed over last 7 days
14.86% (37) 37 / 249 runs
flaked over last 7 days

📄   packages/embeds/embed-core/playwright/tests/action-based.e2e.ts • 2 Flakes

Top 1 Common Error Messages

null

2 Test Cases Affected

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Popup Tests should be able to reschedule
Retry 1Initial Attempt
6.03% (19) 19 / 315 runs
failed over last 7 days
90.79% (286) 286 / 315 runs
flaked over last 7 days
Popup Tests Floating Button Popup Pro User - Configured in App with default setting of system theme should open embed iframe according to system theme when no theme is configured through Embed API
Retry 1Initial Attempt
0.95% (3) 3 / 317 runs
failed over last 7 days
74.13% (235) 235 / 317 runs
flaked over last 7 days

📄   apps/web/playwright/organization/organization-creation.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Organization should be able to create an organization and complete onboarding
Retry 2Retry 1Initial Attempt
2.68% (8) 8 / 299 runs
failed over last 7 days
94.65% (283) 283 / 299 runs
flaked over last 7 days

📄   apps/web/playwright/teams.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Teams - NonOrg Can create a private team
Retry 1Initial Attempt
0% (0) 0 / 317 runs
failed over last 7 days
23.97% (76) 76 / 317 runs
flaked over last 7 days

View Detailed Build Results


Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we're now creating a team after the checkout session. I think this should belong in it's own endpoint.

Comment on lines 38 to 60
// Let's query to ensure that the team metadata carried over from the checkout session.
const parseCheckoutSessionMetadata = checkoutSessionMetadataSchema.safeParse(checkoutSession.metadata);

if (!parseCheckoutSessionMetadata.success) {
console.error(
"Team metadata not found in checkout session",
parseCheckoutSessionMetadata.error,
checkoutSession.id
);

if (!checkoutSession.metadata.userId) {
throw new HttpError({
statusCode: 400,
message: "Can't publish team/org without userId",
});
}
}

const checkoutSessionMetadata = parseCheckoutSessionMetadata.data ?? {
teamName: checkoutSession?.metadata?.teamName ?? generateRandomString(),
teamSlug: checkoutSession?.metadata?.teamSlug ?? generateRandomString(),
userId: checkoutSession.metadata.userId,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very unlikely that the metadata from creating the checkout session won't be carried over but I wanted to think about this edge case. Do we think this is worth covering?

Copy link
Member

Choose a reason for hiding this comment

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

I'd rather let it fail than generating a random string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about this as well. At this point the team is already paid for. The user is redirected back to the profile page, where they can see if they need to change the team name.

If we fail, then we would have to make another call to Stripe to cancel the subscription. I think that would be more friction than making the user change the team name.

Comment on lines 48 to 53
if (!checkoutSession.metadata.userId) {
throw new HttpError({
statusCode: 400,
message: "Can't publish team/org without userId",
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely need the userId of the owner to create the first member.

} else {
publishTeamMutation.mutate({ teamId });
}
router.push(`/settings/teams/${teamId}/profile`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When finishing on this page, just navigate to the new team's profile page.

Comment on lines -131 to -159
<div className="mb-8">
<Controller
control={newTeamFormMethods.control}
name="logo"
render={({ field: { value } }) => (
<>
<Label>{t("team_logo")}</Label>
<div className="flex items-center">
<Avatar
alt=""
imageSrc={value}
fallback={<Plus className="text-subtle h-6 w-6" />}
size="lg"
/>
<div className="ms-4">
<ImageUploader
target="avatar"
id="avatar-upload"
buttonMsg={t("update")}
handleAvatarChange={(newAvatar: string) => {
newTeamFormMethods.setValue("logo", newAvatar);
createTeamMutation.reset();
}}
imageSrc={value}
/>
</div>
</div>
</>
)}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since users can leave this part of the form without the data being saved, uploading an avatar and losing it might be too much friction. Let's leave this part out until the user has paid for the team and is directed to the profile page.

/**
* Used to generate a checkout session when trying to create a team
*/
export const generateTeamCheckoutSession = async ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a new function to generate a checkout session for this scenario. I want to keep the previous function that was used purchaseTeamSubscription for backwards compatibility for unpublished teams and orgs.

Comment on lines 75 to 84
// If the user is not a part of an org, then make them pay before creating the team
if (!isOrgChildTeam) {
const checkoutSession = await generateCheckoutSession({
teamSlug: slug,
teamName: name,
userId: user.id,
});

return checkoutSession;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this team is not created under an org, then direct user to checkout session.

@joeauyeung joeauyeung changed the title refactor: Team Creation Flow refactor: Team Creation Flow [CAL-2751] Nov 22, 2023
Copy link

linear bot commented Nov 22, 2023

CAL-2751 Team's pay-first invite-later flow

Basically we switch out Step 2 & 3. By step 3 we must already have an active subscription and team will be already published. As the user start adding/removing members we run the updateQuantitySubscriptionFromStripe logic.

Step 1

image.png

Step 2

image.png

Step 3

image.png

zomars
zomars previously approved these changes Nov 29, 2023
Copy link
Member

@zomars zomars left a comment

Choose a reason for hiding this comment

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

New team creation flow broke many e2e tests. Made some fixes to prevent flakyness.

Copy link
Contributor

@Udit-takkar Udit-takkar left a comment

Choose a reason for hiding this comment

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

@zomars some tests are still failing

@zomars
Copy link
Member

zomars commented Nov 29, 2023

@zomars some tests are still failing

One more to go. If no one beats me to it I'll take another stab later today

@zomars zomars merged commit 877cd4c into main Nov 29, 2023
36 checks passed
@zomars zomars deleted the refactor/create-teams branch November 29, 2023 16:39
jakazzy pushed a commit to jakazzy/cal.com that referenced this pull request Dec 5, 2023
* Create new endpoint for creating a team

* Generate a team checkout session

* Create team navigate to checkout

* Clean up

* UI changes

* Add comments

* Fix

* Type fix

* Type fix

* Type fix

* Type fixes

* Set telemetry

* Import fix

* Type fix

* Update tests

* Type fix

* fix: e2e

* fix: e2e

* fix: e2e

* fix: e2e

* Update teams.e2e.ts

* fix: e2e

---------

Co-authored-by: Omar López <zomars@me.com>
hbjORbj pushed a commit to codemod-com/cal.com-demo that referenced this pull request Dec 21, 2023
* Create new endpoint for creating a team

* Generate a team checkout session

* Create team navigate to checkout

* Clean up

* UI changes

* Add comments

* Fix

* Type fix

* Type fix

* Type fix

* Type fixes

* Set telemetry

* Import fix

* Type fix

* Update tests

* Type fix

* fix: e2e

* fix: e2e

* fix: e2e

* fix: e2e

* Update teams.e2e.ts

* fix: e2e

---------

Co-authored-by: Omar López <zomars@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core area: core, team members only High priority Created by Linear-GitHub Sync teams area: teams, round robin, collective, managed event-types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants