import { UsersIcon, XIcon } from "lucide-react"; import type { PropsWithChildren } from "react"; import { useState } from "react"; import { useFlagMap } from "@calcom/features/flags/context/provider"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback"; import { trpc } from "@calcom/trpc"; import { Button, showToast, Tooltip } from "@calcom/ui"; const GoogleIcon = () => ( ); function gotoUrl(url: string, newTab?: boolean) { if (newTab) { window.open(url, "_blank"); return; } window.location.href = url; } export function GoogleWorkspaceInviteButton( props: PropsWithChildren<{ onSuccess: (data: string[]) => void }> ) { const featureFlags = useFlagMap(); const utils = trpc.useContext(); const { t } = useLocale(); const params = useParamsWithFallback(); const teamId = Number(params.id); const [googleWorkspaceLoading, setGoogleWorkspaceLoading] = useState(false); const { data: credential } = trpc.viewer.googleWorkspace.checkForGWorkspace.useQuery(); const { data: hasGcalInstalled } = trpc.viewer.appsRouter.checkGlobalKeys.useQuery({ slug: "google-calendar", }); const mutation = trpc.viewer.googleWorkspace.getUsersFromGWorkspace.useMutation({ onSuccess: (data) => { if (Array.isArray(data) && data.length !== 0) { props.onSuccess(data); } }, }); const removeConnectionMutation = trpc.viewer.googleWorkspace.removeCurrentGoogleWorkspaceConnection.useMutation({ onSuccess: () => { showToast(t("app_removed_successfully"), "success"); }, }); if (featureFlags["google-workspace-directory"] == false || !hasGcalInstalled) { return null; } // Show populate input button if they do if (credential && credential?.id) { return (