calcom/components/team/TeamSettingsRightSidebar.tsx
Jamie Pine 5567721431
Team Billing (#1552)
* added base logic for team billing

- moved Stripe customer related logic to customer.ts
- implemented unstable logic for team owner upgrading, downgrading and adding/removing seats

* logic improvements

* - improved Alert style
- hide free team members on public team page
- upgraded textarea to ui component TextArea in SAML setup
- added Alert on team settings for hidden members
- hide CreateEventTypeButton if not admin
- fixed missing locale strings in team settings

* remove random import

* - show hidden status on team list
- refactor team pill

* - improved logic (mostly functional)
- added Alerts for members & owners
- added local strings
- created upgrade modal
- added info notice on invite member modal
- fixed router redirect after leaving team

* - improved logic in team-billing
- error display on upgrade modal
- added better launch.json for VSCode debugger
- fixed bug with missing inviteeUserId

* code cleanup

* nit pick fixes i should sleep now

* fixed leave team bug
- quantity would not decrease upon leave or removal

* added stripe billing callback handler

* - better launch.json
- teams empty component

* - fixed error not removing after successful pro upgrade
- fixed silent fail on team create name conflict
- fixed input border radius on member invite modal

* updated local strings

* improved logic for edge cases, such as:
- team owned by member sponsored by another team can smoothly upgrade to pro if kicked from sponsored team
- logic to calculate if owner is specifically missing pro subscription (ownerIsMissingSeat)
- corrected calculation of members missing seats, shouldn't care for proPaidForByTeamId as that only matters for removing member and preserving pro if they pay for it themselves
- added react query devtools
- added missing locale string

* - allow type override for LinkIconButton
- consolidate filter logic for getMembersMissingSeats

* - only activate team billing for hosted cal
- fix prod price keys

* fix requiresUpgrade when not hosted by cal

* added HOSTED_CAL_FEATURES

* fixed failing build

- fixed broken import path
- added support for premium price plan. (will consider premium as a valid seat)
- remove rouge console log

* fix customer id type error

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-02-07 23:35:26 +00:00

130 lines
4.4 KiB
TypeScript

import { ClockIcon, ExternalLinkIcon, LinkIcon, LogoutIcon, TrashIcon } from "@heroicons/react/solid";
import Link from "next/link";
import { useRouter } from "next/router";
import React from "react";
import { useLocale } from "@lib/hooks/useLocale";
import showToast from "@lib/notification";
import { TeamWithMembers } from "@lib/queries/teams";
import { trpc } from "@lib/trpc";
import { Dialog, DialogTrigger } from "@components/Dialog";
import ConfirmationDialogContent from "@components/dialog/ConfirmationDialogContent";
import CreateEventTypeButton from "@components/eventtype/CreateEventType";
import LinkIconButton from "@components/ui/LinkIconButton";
import { MembershipRole } from ".prisma/client";
export default function TeamSettingsRightSidebar(props: { team: TeamWithMembers; role: MembershipRole }) {
const { t } = useLocale();
const utils = trpc.useContext();
const router = useRouter();
const permalink = `${process.env.NEXT_PUBLIC_APP_URL}/team/${props.team?.slug}`;
const deleteTeamMutation = trpc.useMutation("viewer.teams.delete", {
async onSuccess() {
await utils.invalidateQueries(["viewer.teams.get"]);
router.push(`/settings/teams`);
showToast(t("your_team_updated_successfully"), "success");
},
});
const acceptOrLeaveMutation = trpc.useMutation("viewer.teams.acceptOrLeave", {
onSuccess: () => {
utils.invalidateQueries(["viewer.teams.list"]);
router.push(`/settings/teams`);
},
});
function deleteTeam() {
if (props.team?.id) deleteTeamMutation.mutate({ teamId: props.team.id });
}
function leaveTeam() {
if (props.team?.id)
acceptOrLeaveMutation.mutate({
teamId: props.team.id,
accept: false,
});
}
return (
<div className="px-2 space-y-6">
{(props.role === MembershipRole.OWNER || props.role === MembershipRole.ADMIN) && (
<CreateEventTypeButton
isIndividualTeam
canAddEvents={true}
options={[
{
teamId: props.team?.id,
name: props.team?.name,
slug: props.team?.slug,
image: props.team?.logo,
},
]}
/>
)}
<div className="space-y-1">
<Link href={permalink} passHref={true}>
<a target="_blank">
<LinkIconButton Icon={ExternalLinkIcon}>{t("preview")}</LinkIconButton>
</a>
</Link>
<LinkIconButton
Icon={LinkIcon}
onClick={() => {
navigator.clipboard.writeText(permalink);
showToast("Copied to clipboard", "success");
}}>
{t("copy_link_team")}
</LinkIconButton>
{props.role === "OWNER" ? (
<Dialog>
<DialogTrigger asChild>
<LinkIconButton
onClick={(e) => {
e.stopPropagation();
}}
Icon={TrashIcon}>
{t("disband_team")}
</LinkIconButton>
</DialogTrigger>
<ConfirmationDialogContent
variety="danger"
title={t("disband_team")}
confirmBtnText={t("confirm_disband_team")}
onConfirm={deleteTeam}>
{t("disband_team_confirmation_message")}
</ConfirmationDialogContent>
</Dialog>
) : (
<Dialog>
<DialogTrigger asChild>
<LinkIconButton
Icon={LogoutIcon}
onClick={(e) => {
e.stopPropagation();
}}>
{t("leave_team")}
</LinkIconButton>
</DialogTrigger>
<ConfirmationDialogContent
variety="danger"
title={t("leave_team")}
confirmBtnText={t("confirm_leave_team")}
onConfirm={leaveTeam}>
{t("leave_team_confirmation_message")}
</ConfirmationDialogContent>
</Dialog>
)}
</div>
{props.team?.id && props.role !== MembershipRole.MEMBER && (
<Link href={`/settings/teams/${props.team.id}/availability`}>
<div className="hidden mt-5 space-y-1 sm:block">
<LinkIconButton Icon={ClockIcon}>{"View Availability"}</LinkIconButton>
<p className="mt-2 text-sm text-gray-500">See your team members availability at a glance.</p>
</div>
</Link>
)}
</div>
);
}