2022-02-07 23:35:26 +00:00
|
|
|
import { PlusIcon, UserGroupIcon } from "@heroicons/react/solid";
|
2021-12-17 00:16:59 +00:00
|
|
|
import classNames from "classnames";
|
2022-01-07 20:23:37 +00:00
|
|
|
import { useSession } from "next-auth/react";
|
2022-01-29 00:46:35 +00:00
|
|
|
import { Trans } from "next-i18next";
|
2021-12-09 23:51:30 +00:00
|
|
|
import { useState } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-03-16 23:36:43 +00:00
|
|
|
import { Alert } from "@calcom/ui/Alert";
|
|
|
|
import Button from "@calcom/ui/Button";
|
|
|
|
|
2021-10-13 09:34:55 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
2021-12-09 23:51:30 +00:00
|
|
|
import { trpc } from "@lib/trpc";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-02-07 23:35:26 +00:00
|
|
|
import EmptyScreen from "@components/EmptyScreen";
|
2021-09-22 19:52:38 +00:00
|
|
|
import Loader from "@components/Loader";
|
2021-09-29 21:33:18 +00:00
|
|
|
import SettingsShell from "@components/SettingsShell";
|
2021-12-17 00:16:59 +00:00
|
|
|
import Shell, { useMeQuery } from "@components/Shell";
|
2021-12-09 23:51:30 +00:00
|
|
|
import TeamCreateModal from "@components/team/TeamCreateModal";
|
2021-09-22 19:52:38 +00:00
|
|
|
import TeamList from "@components/team/TeamList";
|
2021-06-03 20:55:34 +00:00
|
|
|
|
2021-10-12 13:11:33 +00:00
|
|
|
export default function Teams() {
|
2021-10-13 09:34:55 +00:00
|
|
|
const { t } = useLocale();
|
2022-01-07 20:23:37 +00:00
|
|
|
const { status } = useSession();
|
|
|
|
const loading = status === "loading";
|
2021-06-08 16:00:06 +00:00
|
|
|
const [showCreateTeamModal, setShowCreateTeamModal] = useState(false);
|
2021-12-07 15:04:34 +00:00
|
|
|
const [errorMessage, setErrorMessage] = useState("");
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2021-12-17 00:16:59 +00:00
|
|
|
const me = useMeQuery();
|
|
|
|
|
2022-02-07 23:35:26 +00:00
|
|
|
const { data, isLoading } = trpc.useQuery(["viewer.teams.list"], {
|
2021-12-09 23:51:30 +00:00
|
|
|
onError: (e) => {
|
|
|
|
setErrorMessage(e.message);
|
|
|
|
},
|
|
|
|
});
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
if (loading) return <Loader />;
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
const teams = data?.filter((m) => m.accepted) || [];
|
|
|
|
const invites = data?.filter((m) => !m.accepted) || [];
|
2021-12-17 00:16:59 +00:00
|
|
|
const isFreePlan = me.data?.plan === "FREE";
|
Cal 262 refactor edit teams according to the design reference (#516)
* refactored settings/team landing page
* changed team edit flow, WIP
* merge conflict fix for teams.tsx
* minor fixes to edit team, WIP
* invite-member and disband team APIs attached inside edit-team page
* added remove-member API in edit-team page, minor fixes
* minor code fix, WIP
* WIP
* add logo, bio, branding to team schema
* bio, logo, branding, slug patch API and minor code fix-- WIP
* fn to Disband team directly from the dropdown menu in settings/teams page, removed debug remnants --WIP
* Pull latest data after an action in settings/teams-edit page
* added slug conflict check at Patch time
* code clean-up
* initial change request fixes --WIP
* prop type fix and add warn button color theme --WIP
* added warn Button to Dialog
* remaining change request fixes
* added noop from react-query
* updated invited team-list design
* prettier fix for api/teams/profile
* removed noop import and added custom noop
* minor Button fix
* requested changes addressed
2021-09-06 13:22:22 +00:00
|
|
|
|
2021-06-08 16:00:06 +00:00
|
|
|
return (
|
2021-10-13 09:34:55 +00:00
|
|
|
<Shell heading={t("teams")} subtitle={t("create_manage_teams_collaborative")}>
|
2021-06-03 20:55:34 +00:00
|
|
|
<SettingsShell>
|
2021-12-09 23:51:30 +00:00
|
|
|
{!!errorMessage && <Alert severity="error" title={errorMessage} />}
|
2021-12-17 00:16:59 +00:00
|
|
|
{isFreePlan && (
|
|
|
|
<Alert
|
|
|
|
severity="warning"
|
|
|
|
title={<>{t("plan_upgrade_teams")}</>}
|
|
|
|
message={
|
2022-01-29 00:46:35 +00:00
|
|
|
<Trans i18nKey="plan_upgrade_instructions">
|
|
|
|
You can
|
|
|
|
<a href="/api/upgrade" className="underline">
|
|
|
|
upgrade here
|
2021-12-17 00:16:59 +00:00
|
|
|
</a>
|
2022-01-29 00:46:35 +00:00
|
|
|
.
|
|
|
|
</Trans>
|
2021-12-17 00:16:59 +00:00
|
|
|
}
|
|
|
|
className="my-4"
|
|
|
|
/>
|
|
|
|
)}
|
2022-03-17 13:20:49 +00:00
|
|
|
{showCreateTeamModal && (
|
|
|
|
<TeamCreateModal isOpen={showCreateTeamModal} onClose={() => setShowCreateTeamModal(false)} />
|
|
|
|
)}
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className={classNames("my-4 flex justify-end", isFreePlan && "opacity-50")}>
|
2021-12-17 00:16:59 +00:00
|
|
|
<Button
|
|
|
|
disabled={isFreePlan}
|
|
|
|
type="button"
|
|
|
|
className="btn btn-white"
|
|
|
|
onClick={() => setShowCreateTeamModal(true)}>
|
2022-02-09 00:05:13 +00:00
|
|
|
<PlusIcon className="inline-block h-3.5 w-3.5 text-gray-700 group-hover:text-black ltr:mr-2 rtl:ml-2" />
|
2021-12-09 23:51:30 +00:00
|
|
|
{t("new_team")}
|
|
|
|
</Button>
|
|
|
|
</div>
|
2022-02-07 23:35:26 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
{invites.length > 0 && (
|
|
|
|
<div className="mb-4">
|
|
|
|
<h1 className="mb-2 text-lg font-medium">{t("open_invitations")}</h1>
|
|
|
|
<TeamList teams={invites}></TeamList>
|
2021-06-05 22:53:33 +00:00
|
|
|
</div>
|
2021-07-07 10:43:13 +00:00
|
|
|
)}
|
2022-02-07 23:35:26 +00:00
|
|
|
{!isLoading && !teams.length && (
|
|
|
|
<EmptyScreen
|
|
|
|
Icon={UserGroupIcon}
|
|
|
|
headline={t("no_teams")}
|
|
|
|
description={t("no_teams_description")}
|
|
|
|
/>
|
|
|
|
)}
|
2021-12-09 23:51:30 +00:00
|
|
|
{teams.length > 0 && <TeamList teams={teams}></TeamList>}
|
2021-06-03 20:55:34 +00:00
|
|
|
</SettingsShell>
|
|
|
|
</Shell>
|
|
|
|
);
|
2021-06-30 13:48:34 +00:00
|
|
|
}
|