2023-06-15 08:58:07 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
|
|
|
|
|
|
|
import type { CreateBtnProps } from "./CreateButton";
|
|
|
|
import { CreateButton } from "./CreateButton";
|
|
|
|
|
2023-06-26 10:37:59 +00:00
|
|
|
export function CreateButtonWithTeamsList(
|
|
|
|
props: Omit<CreateBtnProps, "options"> & { onlyShowWithTeams?: boolean; onlyShowWithNoTeams?: boolean }
|
|
|
|
) {
|
2023-06-15 08:58:07 +00:00
|
|
|
const query = trpc.viewer.teamsAndUserProfilesQuery.useQuery();
|
|
|
|
if (!query.data) return null;
|
|
|
|
|
|
|
|
const teamsAndUserProfiles = query.data
|
|
|
|
.filter((profile) => !profile.readOnly)
|
|
|
|
.map((profile) => {
|
|
|
|
return {
|
|
|
|
teamId: profile.teamId,
|
|
|
|
label: profile.name || profile.slug,
|
|
|
|
image: profile.image,
|
|
|
|
slug: profile.slug,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2023-06-26 10:37:59 +00:00
|
|
|
if (props.onlyShowWithTeams && teamsAndUserProfiles.length < 2) return null;
|
|
|
|
|
|
|
|
if (props.onlyShowWithNoTeams && teamsAndUserProfiles.length > 1) return null;
|
|
|
|
|
2023-06-15 08:58:07 +00:00
|
|
|
return <CreateButton {...props} options={teamsAndUserProfiles} />;
|
|
|
|
}
|