2021-09-22 19:52:38 +00:00
|
|
|
import { PlusIcon } 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";
|
2021-12-09 23:51:30 +00:00
|
|
|
import { useState } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
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-12-07 15:04:34 +00:00
|
|
|
import { Alert } from "@components/ui/Alert";
|
2021-09-22 19:52:38 +00:00
|
|
|
import Button from "@components/ui/Button";
|
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();
|
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
const { data } = trpc.useQuery(["viewer.teams.list"], {
|
|
|
|
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={
|
|
|
|
<>
|
|
|
|
{t("to_upgrade_go_to")}{" "}
|
|
|
|
<a href={"https://cal.com/upgrade"} className="underline">
|
|
|
|
{"https://cal.com/upgrade"}
|
|
|
|
</a>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
className="my-4"
|
|
|
|
/>
|
|
|
|
)}
|
2021-12-09 23:51:30 +00:00
|
|
|
{showCreateTeamModal && <TeamCreateModal onClose={() => setShowCreateTeamModal(false)} />}
|
2021-12-17 00:16:59 +00:00
|
|
|
<div className={classNames("flex justify-end my-4", isFreePlan && "opacity-50")}>
|
|
|
|
<Button
|
|
|
|
disabled={isFreePlan}
|
|
|
|
type="button"
|
|
|
|
className="btn btn-white"
|
|
|
|
onClick={() => setShowCreateTeamModal(true)}>
|
2021-12-09 23:51:30 +00:00
|
|
|
<PlusIcon className="group-hover:text-black text-gray-700 w-3.5 h-3.5 mr-2 inline-block" />
|
|
|
|
{t("new_team")}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
{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
|
|
|
)}
|
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
|
|
|
}
|