* added api/v2 for zoom connect * Update conferencing.controller.ts * fix: added api for ConferencingAppsViewPlatformWrapper * type fixes * added getBulkEventTypes api for bulk-update default location * added bulk-update-to-default-location * fix:bulk-update-to-default-location * invalidated * fixed returnTo and onErrorReturnTo * make logos work for conferencing atoms * smalll improvements * fixup * share common types * type fix, and fixed a typo * fix: type-error * fix: json.parse(json.parse()) * fix: invalidate query * fix: removing app throws error in the main app * undo platform-libraries-1.2.3 * update platform-libraries version --------- Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
83 lines
2.6 KiB
TypeScript
83 lines
2.6 KiB
TypeScript
"use client";
|
|
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import type { ReactNode } from "react";
|
|
import { useEffect, useRef, useState } from "react";
|
|
import { z } from "zod";
|
|
|
|
import type { CredentialOwner } from "@calcom/app-store/types";
|
|
import { useIsPlatform } from "@calcom/atoms/monorepo";
|
|
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
|
import { useTypedQuery } from "@calcom/lib/hooks/useTypedQuery";
|
|
import { AppListCard as AppListCardComponent } from "@calcom/ui";
|
|
|
|
type ShouldHighlight =
|
|
| {
|
|
slug: string;
|
|
shouldHighlight: true;
|
|
}
|
|
| {
|
|
shouldHighlight?: never;
|
|
slug?: never;
|
|
};
|
|
|
|
export type AppListCardProps = {
|
|
logo?: string;
|
|
title: string;
|
|
description: string;
|
|
actions?: ReactNode;
|
|
isDefault?: boolean;
|
|
isTemplate?: boolean;
|
|
invalidCredential?: boolean;
|
|
children?: ReactNode;
|
|
credentialOwner?: CredentialOwner;
|
|
className?: string;
|
|
} & ShouldHighlight;
|
|
|
|
const schema = z.object({ hl: z.string().optional() });
|
|
|
|
function AppListCardPlatformWrapper(props: AppListCardProps) {
|
|
const logo = `https://app.cal.com${props.logo}`;
|
|
return <AppListCardComponent {...props} logo={logo} />;
|
|
}
|
|
function AppListCardWebWrapper(props: AppListCardProps) {
|
|
const { slug, shouldHighlight } = props;
|
|
const {
|
|
data: { hl },
|
|
} = useTypedQuery(schema);
|
|
const router = useRouter();
|
|
const [highlight, setHighlight] = useState(shouldHighlight && hl === slug);
|
|
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
const searchParams = useCompatSearchParams();
|
|
const pathname = usePathname();
|
|
|
|
useEffect(() => {
|
|
if (shouldHighlight && highlight && searchParams !== null && pathname !== null) {
|
|
timeoutRef.current = setTimeout(() => {
|
|
const _searchParams = new URLSearchParams(searchParams);
|
|
_searchParams.delete("hl");
|
|
_searchParams.delete("category"); // this comes from params, not from search params
|
|
|
|
setHighlight(false);
|
|
|
|
const stringifiedSearchParams = _searchParams.toString();
|
|
|
|
router.replace(`${pathname}${stringifiedSearchParams !== "" ? `?${stringifiedSearchParams}` : ""}`);
|
|
}, 3000);
|
|
}
|
|
return () => {
|
|
if (timeoutRef.current) {
|
|
clearTimeout(timeoutRef.current);
|
|
timeoutRef.current = null;
|
|
}
|
|
};
|
|
}, [highlight, pathname, router, searchParams, shouldHighlight]);
|
|
|
|
return <AppListCardComponent {...props} />;
|
|
}
|
|
|
|
export default function AppListCard(props: AppListCardProps) {
|
|
const isPlatform = useIsPlatform();
|
|
return isPlatform ? <AppListCardPlatformWrapper {...props} /> : <AppListCardWebWrapper {...props} />;
|
|
}
|