* fix * move event types components to web * update import paths * mv apps components * migrate form builder * fix * mv sso * fix * mv * update import paths * update import paths * mv * mv * mv * fix * update Booker * fix * fix * fix * fix * mv video * mv embed components to web * update import paths * mv calendar weekly view components * update import paths * fix * fixp * fix * fix * fix * fix: update FormBuilder imports to use @calcom/features/form-builder Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: update broken import paths after file migrations Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: correct import paths for platform atoms and moved components Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: apply CSS type fixes and add missing atoms exports Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: resolve type errors in test files after component migrations Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: resolve remaining type errors in test files Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix * migrate * fix: resolve type errors in test and mock files - Add missing bookingForm, bookerFormErrorRef, instantConnectCooldownMs to Booker.test.tsx bookings prop - Add all required BookerEvent properties to event.mock.ts - Add vi import from vitest to all mock files - Fix date parameter types in packages/dayjs/__mocks__/index.ts - Add verificationCode and setVerificationCode to test-utils.tsx mock store - Remove children.type access in Section.tsx mock to fix type error - Fix lint issues: remove unused React imports, use import type where needed, add return types - Add biome-ignore comments for pre-existing lint warnings in test files Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * migrate * migrate * migrate * update import paths * update import paths * update import paths * fix * migrate data table * migrate data table * fix * fix * fix * migrate insights components * migrate insights components * fix * mv * update import paths * fix * fix * fix * fix * fix * fix: resolve type errors in test mocks - Booker.test.tsx: Add all required UseFormReturn methods to bookingForm mock - event.mock.ts: Fix entity, subsetOfHosts, instantMeetingParameters, fieldTranslations, image types - dayjs/__mocks__/index.ts: Use Object.assign for proper typing of mock properties - Section.tsx: Change 'class' to 'className' in JSX with biome-ignore comment Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: add missing hasDataErrors and dataErrors to bookings.errors mock Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: add missing loadingStates properties to bookings mock Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: add missing slots properties (setTentativeSelectedTimeslots, tentativeSelectedTimeslots, slotReservationId) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: update quickAvailabilityChecks to include utcEndIso and use valid status type Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: add missing bookerForm properties (formName, beforeVerifyEmail, formErrors) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: add missing UseFormReturn properties to bookerForm.bookingForm mock Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: add hasFormErrors and formErrors to bookerForm.formErrors mock Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: add hasFormErrors and formErrors to bookerForm.errors mock Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: add missing isError property to mockEvent Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: use complete BookerEvent mock in Booker.test.tsx Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: use branded bookingFields type in event mock Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: add missing schedule mock properties (isError, isSuccess, isLoading, dataUpdatedAt) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * revert * fix * fix * fix * fix build * fix * fix * fix * fix: correct AddMembersWithSwitch test wrapper to use initial assignAllTeamMembers value - Fixed test wrapper to initialize useState with componentProps.assignAllTeamMembers instead of hardcoded false, allowing tests to properly test different states - Updated test expectations for ALL_TEAM_MEMBERS_ENABLED_AND_SEGMENT_NOT_APPLICABLE state to match actual component behavior (toggle should be present and checked) - Fixed 'should show Segment when toggled on' test to start with assignAllTeamMembers: false to properly test the flow of enabling it - Added explicit types to satisfy biome lint requirements Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: use JSX.Element instead of React.JSX.Element for type compatibility Co-Authored-By: benny@cal.com <sldisek783@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
293 lines
10 KiB
TypeScript
293 lines
10 KiB
TypeScript
"use client";
|
|
|
|
import { useRouter } from "next/navigation";
|
|
import { useEffect, useState } from "react";
|
|
import posthog from "posthog-js";
|
|
|
|
import { InstallAppButton } from "@calcom/app-store/InstallAppButton";
|
|
import { isRedirectApp } from "@calcom/app-store/_utils/redirectApps";
|
|
import useAddAppMutation from "@calcom/app-store/_utils/useAddAppMutation";
|
|
import { doesAppSupportTeamInstall, isConferencing } from "@calcom/app-store/utils";
|
|
import type { UserAdminTeams } from "@calcom/features/users/repositories/UserRepository";
|
|
import { AppOnboardingSteps } from "@calcom/lib/apps/appOnboardingSteps";
|
|
import { getAppOnboardingUrl } from "@calcom/lib/apps/getAppOnboardingUrl";
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
|
|
import type { AppFrontendPayload as App } from "@calcom/types/App";
|
|
import type { CredentialFrontendPayload as Credential } from "@calcom/types/Credential";
|
|
import classNames from "@calcom/ui/classNames";
|
|
import { Badge } from "@calcom/ui/components/badge";
|
|
import { Button } from "@calcom/ui/components/button";
|
|
import type { ButtonProps } from "@calcom/ui/components/button";
|
|
import { showToast } from "@calcom/ui/components/toast";
|
|
|
|
interface AppCardProps {
|
|
app: App;
|
|
credentials?: Credential[];
|
|
searchText?: string;
|
|
userAdminTeams?: UserAdminTeams;
|
|
}
|
|
|
|
export function AppCard({ app, credentials, searchText, userAdminTeams }: AppCardProps) {
|
|
const { t } = useLocale();
|
|
const router = useRouter();
|
|
const allowedMultipleInstalls = app.categories && app.categories.indexOf("calendar") > -1;
|
|
const appAdded = (credentials && credentials.length) || 0;
|
|
const enabledOnTeams = doesAppSupportTeamInstall({
|
|
appCategories: app.categories,
|
|
concurrentMeetings: app.concurrentMeetings,
|
|
isPaid: !!app.paid,
|
|
});
|
|
|
|
const appInstalled = enabledOnTeams && userAdminTeams ? userAdminTeams.length < appAdded : appAdded > 0;
|
|
|
|
const mutation = useAddAppMutation(null, {
|
|
onSuccess: (data) => {
|
|
if (data?.setupPending) return;
|
|
showToast(t("app_successfully_installed"), "success");
|
|
},
|
|
onError: (error) => {
|
|
if (error instanceof Error) showToast(error.message || t("app_could_not_be_installed"), "error");
|
|
},
|
|
});
|
|
|
|
const [searchTextIndex, setSearchTextIndex] = useState<number | undefined>(undefined);
|
|
|
|
useEffect(() => {
|
|
setSearchTextIndex(searchText ? app.name.toLowerCase().indexOf(searchText.toLowerCase()) : undefined);
|
|
}, [app.name, searchText]);
|
|
|
|
const handleAppInstall = () => {
|
|
posthog.capture("app_install_button_clicked", {
|
|
slug: app.slug,
|
|
app_type: app.type,
|
|
is_redirect: isRedirectApp(app.slug),
|
|
is_conferencing: isConferencing(app.categories || []),
|
|
});
|
|
|
|
if (isRedirectApp(app.slug)) {
|
|
// For redirect apps, open the external URL directly
|
|
if (app.url) window.open(app.url, "_blank", "noopener,noreferrer");
|
|
return;
|
|
}
|
|
if (isConferencing(app.categories) && !app.concurrentMeetings) {
|
|
mutation.mutate({
|
|
type: app.type,
|
|
variant: app.variant,
|
|
slug: app.slug,
|
|
returnTo:
|
|
WEBAPP_URL +
|
|
getAppOnboardingUrl({
|
|
slug: app.slug,
|
|
step: AppOnboardingSteps.EVENT_TYPES_STEP,
|
|
}),
|
|
});
|
|
} else if (
|
|
!doesAppSupportTeamInstall({
|
|
appCategories: app.categories,
|
|
concurrentMeetings: app.concurrentMeetings,
|
|
isPaid: !!app.paid,
|
|
})
|
|
) {
|
|
mutation.mutate({ type: app.type });
|
|
} else {
|
|
router.push(getAppOnboardingUrl({ slug: app.slug, step: AppOnboardingSteps.ACCOUNTS_STEP }));
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="border-subtle relative flex h-64 flex-col rounded-md border p-5">
|
|
<div className="flex">
|
|
<img
|
|
src={app.logo}
|
|
alt={`${app.name} Logo`}
|
|
className={classNames(
|
|
app.logo.includes("-dark") && "dark:invert",
|
|
"mb-4 h-12 w-12 rounded-sm" // TODO: Maybe find a better way to handle this @Hariom?
|
|
)}
|
|
/>
|
|
</div>
|
|
<div className="flex items-center">
|
|
<h3 className="text-emphasis font-medium">
|
|
{searchTextIndex != undefined && searchText ? (
|
|
<>
|
|
{app.name.substring(0, searchTextIndex)}
|
|
<span className="bg-yellow-300" data-testid="highlighted-text">
|
|
{app.name.substring(searchTextIndex, searchTextIndex + searchText.length)}
|
|
</span>
|
|
{app.name.substring(searchTextIndex + searchText.length)}
|
|
</>
|
|
) : (
|
|
app.name
|
|
)}
|
|
</h3>
|
|
</div>
|
|
{/* TODO: add reviews <div className="flex text-sm text-default">
|
|
<span>{props.rating} stars</span> <Icon name="star" className="ml-1 mt-0.5 h-4 w-4 text-yellow-600" />
|
|
<span className="pl-1 text-subtle">{props.reviews} reviews</span>
|
|
</div> */}
|
|
<p
|
|
className="text-default mt-2 grow text-sm"
|
|
dangerouslySetInnerHTML={{ __html: markdownToSafeHTML(app.description) }}
|
|
style={{
|
|
overflow: "hidden",
|
|
display: "-webkit-box",
|
|
WebkitBoxOrient: "vertical",
|
|
WebkitLineClamp: "3",
|
|
}}
|
|
/>
|
|
|
|
<div className="mt-5 flex max-w-full flex-row justify-between gap-2">
|
|
<Button
|
|
color="secondary"
|
|
className="flex w-32 grow justify-center"
|
|
href={`/apps/${app.slug}`}
|
|
onClick={() => { posthog.capture("app_card_details_clicked", { slug: app.slug }) }}
|
|
data-testid={`app-store-app-card-${app.slug}`}>
|
|
{t("details")}
|
|
</Button>
|
|
{app.isGlobal ||
|
|
(credentials && credentials.length > 0 && allowedMultipleInstalls) ||
|
|
(credentials && credentials.length > 0 && isRedirectApp(app.slug))
|
|
? !app.isGlobal && (
|
|
<InstallAppButton
|
|
type={app.type}
|
|
teamsPlanRequired={app.teamsPlanRequired}
|
|
disableInstall={!!app.dependencies && !app.dependencyData?.some((data) => !data.installed)}
|
|
wrapperClassName="[@media(max-width:260px)]:w-full"
|
|
render={({ useDefaultComponent, ...props }) => {
|
|
if (useDefaultComponent) {
|
|
props = {
|
|
...props,
|
|
onClick: () => {
|
|
handleAppInstall();
|
|
},
|
|
loading: mutation.isPending,
|
|
};
|
|
} else {
|
|
const originalOnClick = props.onClick;
|
|
props = {
|
|
...props,
|
|
onClick: (e) => {
|
|
posthog.capture("app_install_button_clicked", {
|
|
slug: app.slug,
|
|
app_type: app.type,
|
|
is_redirect: isRedirectApp(app.slug),
|
|
is_conferencing: isConferencing(app.categories || []),
|
|
});
|
|
originalOnClick?.(e);
|
|
},
|
|
};
|
|
}
|
|
return (
|
|
<InstallAppButtonChild paid={app.paid} isRedirect={isRedirectApp(app.slug)} {...props} />
|
|
);
|
|
}}
|
|
/>
|
|
)
|
|
: credentials &&
|
|
!appInstalled && (
|
|
<InstallAppButton
|
|
type={app.type}
|
|
wrapperClassName="[@media(max-width:260px)]:w-full"
|
|
disableInstall={!!app.dependencies && app.dependencyData?.some((data) => !data.installed)}
|
|
teamsPlanRequired={app.teamsPlanRequired}
|
|
render={({ useDefaultComponent, ...props }) => {
|
|
if (useDefaultComponent) {
|
|
props = {
|
|
...props,
|
|
disabled: !!props.disabled,
|
|
onClick: () => {
|
|
handleAppInstall();
|
|
},
|
|
loading: mutation.isPending,
|
|
};
|
|
} else {
|
|
const originalOnClick = props.onClick;
|
|
props = {
|
|
...props,
|
|
onClick: (e) => {
|
|
posthog.capture("app_install_button_clicked", {
|
|
slug: app.slug,
|
|
app_type: app.type,
|
|
is_redirect: isRedirectApp(app.slug),
|
|
is_conferencing: isConferencing(app.categories || []),
|
|
});
|
|
originalOnClick?.(e);
|
|
},
|
|
};
|
|
}
|
|
return (
|
|
<InstallAppButtonChild paid={app.paid} isRedirect={isRedirectApp(app.slug)} {...props} />
|
|
);
|
|
}}
|
|
/>
|
|
)}
|
|
</div>
|
|
<div className="max-w-44 absolute right-0 mr-4 flex flex-wrap justify-end gap-1">
|
|
{appAdded > 0 && !isRedirectApp(app.slug) ? (
|
|
<Badge variant="green">{t("installed", { count: appAdded })}</Badge>
|
|
) : null}
|
|
{app.isTemplate && (
|
|
<span className="bg-error rounded-md px-2 py-1 text-sm font-normal text-red-800">Template</span>
|
|
)}
|
|
{(app.isDefault || (!app.isDefault && app.isGlobal)) && (
|
|
<span className="bg-subtle text-emphasis flex items-center rounded-md px-2 py-1 text-sm font-normal">
|
|
{t("default")}
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const InstallAppButtonChild = ({
|
|
paid,
|
|
isRedirect = false,
|
|
...props
|
|
}: {
|
|
paid: App["paid"];
|
|
isRedirect?: boolean;
|
|
} & ButtonProps) => {
|
|
const { t } = useLocale();
|
|
if (isRedirect) {
|
|
return (
|
|
<Button
|
|
color="secondary"
|
|
className="[@media(max-width:260px)]:w-full [@media(max-width:260px)]:justify-center"
|
|
StartIcon="external-link"
|
|
{...props}
|
|
size="base">
|
|
{t("visit")}
|
|
</Button>
|
|
);
|
|
}
|
|
// Paid apps don't support team installs at the moment
|
|
// Also, cal.ai(the only paid app at the moment) doesn't support team install either
|
|
if (paid) {
|
|
return (
|
|
<Button
|
|
color="secondary"
|
|
className="[@media(max-width:260px)]:w-full [@media(max-width:260px)]:justify-center"
|
|
StartIcon="plus"
|
|
data-testid="install-app-button"
|
|
{...props}>
|
|
{paid.trial ? t("start_paid_trial") : t("subscribe")}
|
|
</Button>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Button
|
|
color="secondary"
|
|
className="[@media(max-width:260px)]:w-full [@media(max-width:260px)]:justify-center"
|
|
StartIcon="plus"
|
|
data-testid="install-app-button"
|
|
{...props}
|
|
size="base">
|
|
{t("install")}
|
|
</Button>
|
|
);
|
|
};
|