refactor: move feature-flags, calendars, and schedules components from packages/features to apps/web/modules (#27222)
* refactor: move feature-flags, calendars, and schedules components from packages/features to apps/web/modules Co-Authored-By: [email protected] <[email protected]> * fix * fix * fix * fix: move DatePicker and DateOverrideInputDialog to apps/web/modules and update imports Co-Authored-By: [email protected] <[email protected]> * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * rename * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * wip * wip * wip * fix unit tests --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
18049bc1d6
commit
c7ee3984ef
36 files changed
+134
-53
No files matched your search
@@ -0,0 +1,208 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
import { useDebounce } from "@calcom/lib/hooks/useDebounce";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
import { Avatar } from "@calcom/ui/components/avatar";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { Checkbox, TextField } from "@calcom/ui/components/form";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
SheetBody,
|
||||
SheetFooter,
|
||||
} from "@calcom/ui/components/sheet";
|
||||
import { SkeletonContainer, SkeletonText } from "@calcom/ui/components/skeleton";
|
||||
import { showToast } from "@calcom/ui/components/toast";
|
||||
|
||||
type Flag = RouterOutputs["viewer"]["features"]["list"][number];
|
||||
|
||||
interface AssignFeatureSheetProps {
|
||||
flag: Flag;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}
|
||||
|
||||
export function AssignFeatureSheet({ flag, open, onOpenChange }: AssignFeatureSheetProps) {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useUtils();
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const debouncedSearchTerm = useDebounce(searchTerm, 300);
|
||||
|
||||
const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isPending } =
|
||||
trpc.viewer.admin.getTeamsForFeature.useInfiniteQuery(
|
||||
{
|
||||
featureId: flag.slug,
|
||||
limit: 20,
|
||||
searchTerm: debouncedSearchTerm || undefined,
|
||||
},
|
||||
{
|
||||
enabled: open,
|
||||
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
||||
}
|
||||
);
|
||||
|
||||
const teams = data?.pages.flatMap((page) => page.teams) ?? [];
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) {
|
||||
setSearchTerm("");
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
const assignMutation = trpc.viewer.admin.assignFeatureToTeam.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.viewer.admin.getTeamsForFeature.invalidate({ featureId: flag.slug });
|
||||
showToast(t("feature_assigned_successfully"), "success");
|
||||
},
|
||||
onError: (err) => {
|
||||
showToast(err.message, "error");
|
||||
},
|
||||
});
|
||||
|
||||
const unassignMutation = trpc.viewer.admin.unassignFeatureFromTeam.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.viewer.admin.getTeamsForFeature.invalidate({ featureId: flag.slug });
|
||||
showToast(t("feature_unassigned_successfully"), "success");
|
||||
},
|
||||
onError: (err) => {
|
||||
showToast(err.message, "error");
|
||||
},
|
||||
});
|
||||
|
||||
const handleToggleTeam = (teamId: number, currentlyHasFeature: boolean) => {
|
||||
if (currentlyHasFeature) {
|
||||
unassignMutation.mutate({
|
||||
teamId,
|
||||
featureId: flag.slug,
|
||||
});
|
||||
} else {
|
||||
assignMutation.mutate({
|
||||
teamId,
|
||||
featureId: flag.slug,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
const isLoading = assignMutation.isPending || unassignMutation.isPending;
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={handleClose}>
|
||||
<SheetContent className="bg-cal-muted">
|
||||
<SheetHeader>
|
||||
<SheetTitle>Assign: {flag.slug}</SheetTitle>
|
||||
</SheetHeader>
|
||||
<SheetBody>
|
||||
<div className="mb-4">
|
||||
<TextField
|
||||
type="text"
|
||||
placeholder={t("search")}
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{isPending ? (
|
||||
<SkeletonContainer>
|
||||
<div className="stack-y-3">
|
||||
{[...Array(5)].map((_, i) => (
|
||||
<SkeletonText key={i} className="h-16 w-full" />
|
||||
))}
|
||||
</div>
|
||||
</SkeletonContainer>
|
||||
) : teams && teams.length > 0 ? (
|
||||
<>
|
||||
<div className="stack-y-2">
|
||||
{teams.map((team) => (
|
||||
<button
|
||||
key={team.id}
|
||||
type="button"
|
||||
onClick={() => handleToggleTeam(team.id, team.hasFeature)}
|
||||
disabled={isLoading}
|
||||
className="bg-default border-subtle hover:bg-cal-muted flex w-full items-center justify-between rounded-lg border p-4 text-left transition-colors disabled:cursor-not-allowed disabled:opacity-50">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="relative">
|
||||
{team.isOrganization ? (
|
||||
<div className="h-8 w-8 overflow-hidden rounded">
|
||||
{team.logoUrl ? (
|
||||
<img
|
||||
src={team.logoUrl}
|
||||
alt={team.name || ""}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="bg-emphasis text-default flex h-full w-full items-center justify-center text-xs font-semibold">
|
||||
{team.name?.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<Avatar size="sm" alt={team.name || ""} imageSrc={team.logoUrl} />
|
||||
)}
|
||||
{team.parent && team.parentId && (
|
||||
<div className="border-emphasis absolute -bottom-1 -right-1 h-4 w-4 overflow-hidden rounded border">
|
||||
{team.parent.logoUrl ? (
|
||||
<img
|
||||
src={team.parent.logoUrl}
|
||||
alt={team.parent.name || ""}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="bg-emphasis text-default flex h-full w-full items-center justify-center text-[8px] font-semibold">
|
||||
{team.parent.name?.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-emphasis text-sm font-medium">{team.name}</p>
|
||||
{team.slug && <p className="text-subtle text-xs">{team.slug}</p>}
|
||||
{team.parent && (
|
||||
<p className="text-subtle text-xs">
|
||||
{t("organization")}: {team.parent.name}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<Checkbox
|
||||
checked={team.hasFeature}
|
||||
disabled={isLoading}
|
||||
onCheckedChange={() => {}}
|
||||
/>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{hasNextPage && (
|
||||
<div className="mt-4 flex justify-center">
|
||||
<Button
|
||||
color="secondary"
|
||||
onClick={() => fetchNextPage()}
|
||||
loading={isFetchingNextPage}
|
||||
disabled={isFetchingNextPage}>
|
||||
{t("load_more")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<p className="text-subtle text-center text-sm">{t("no_teams_found")}</p>
|
||||
)}
|
||||
</SheetBody>
|
||||
<SheetFooter>
|
||||
<Button color="secondary" onClick={handleClose}>
|
||||
{t("close")}
|
||||
</Button>
|
||||
</SheetFooter>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
import { Badge } from "@calcom/ui/components/badge";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { PanelCard } from "@calcom/ui/components/card";
|
||||
import { Switch } from "@calcom/ui/components/form";
|
||||
import { ListItem, ListItemText, ListItemTitle } from "@calcom/ui/components/list";
|
||||
import { List } from "@calcom/ui/components/list";
|
||||
import { showToast } from "@calcom/ui/components/toast";
|
||||
|
||||
import { AssignFeatureSheet } from "./AssignFeatureSheet";
|
||||
|
||||
export const FlagAdminList = () => {
|
||||
const [data] = trpc.viewer.features.list.useSuspenseQuery();
|
||||
const [selectedFlag, setSelectedFlag] = useState<Flag | null>(null);
|
||||
const [sheetOpen, setSheetOpen] = useState(false);
|
||||
|
||||
const groupedFlags = data.reduce((acc, flag) => {
|
||||
const type = flag.type || "OTHER";
|
||||
if (!acc[type]) {
|
||||
acc[type] = [];
|
||||
}
|
||||
acc[type].push(flag);
|
||||
return acc;
|
||||
}, {} as Record<string, typeof data>);
|
||||
|
||||
const sortedTypes = Object.keys(groupedFlags).sort();
|
||||
|
||||
const handleAssignClick = (flag: Flag) => {
|
||||
setSelectedFlag(flag);
|
||||
setSheetOpen(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="stack-y-4">
|
||||
{sortedTypes.map((type) => (
|
||||
<PanelCard key={type} title={type.replace(/_/g, " ")} collapsible defaultCollapsed={false}>
|
||||
<List roundContainer noBorderTreatment>
|
||||
{groupedFlags[type].map((flag: Flag, index: number) => (
|
||||
<ListItem key={flag.slug} rounded={index === 0 || index === groupedFlags[type].length - 1}>
|
||||
<div className="flex flex-1 flex-col">
|
||||
<ListItemTitle component="h3">{flag.slug}</ListItemTitle>
|
||||
<ListItemText component="p">{flag.description}</ListItemText>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 py-2">
|
||||
<FlagToggle flag={flag} />
|
||||
<Button
|
||||
color="secondary"
|
||||
size="sm"
|
||||
variant="icon"
|
||||
onClick={() => handleAssignClick(flag)}
|
||||
StartIcon="users"></Button>
|
||||
</div>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
</PanelCard>
|
||||
))}
|
||||
</div>
|
||||
{selectedFlag && (
|
||||
<AssignFeatureSheet flag={selectedFlag} open={sheetOpen} onOpenChange={setSheetOpen} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
type Flag = RouterOutputs["viewer"]["features"]["list"][number];
|
||||
|
||||
const FlagToggle = (props: { flag: Flag }) => {
|
||||
const {
|
||||
flag: { slug, enabled },
|
||||
} = props;
|
||||
const utils = trpc.useUtils();
|
||||
const mutation = trpc.viewer.admin.toggleFeatureFlag.useMutation({
|
||||
onSuccess: () => {
|
||||
showToast("Flags successfully updated", "success");
|
||||
utils.viewer.features.list.invalidate();
|
||||
utils.viewer.features.map.invalidate();
|
||||
},
|
||||
});
|
||||
return (
|
||||
<Switch
|
||||
defaultChecked={enabled}
|
||||
onCheckedChange={(checked) => {
|
||||
mutation.mutate({ slug, enabled: checked });
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
import type { AppFlags } from "@calcom/features/flags/config";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
const initialData: AppFlags = {
|
||||
organizations: false,
|
||||
teams: false,
|
||||
"calendar-cache": false,
|
||||
"calendar-cache-serve": false,
|
||||
emails: false,
|
||||
insights: false,
|
||||
webhooks: false,
|
||||
workflows: false,
|
||||
"email-verification": false,
|
||||
"google-workspace-directory": false,
|
||||
"disable-signup": false,
|
||||
attributes: false,
|
||||
"organizer-request-email-v2": false,
|
||||
"delegation-credential": false,
|
||||
"salesforce-crm-tasker": false,
|
||||
"workflow-smtp-emails": false,
|
||||
"cal-video-log-in-overlay": false,
|
||||
"use-api-v2-for-team-slots": false,
|
||||
pbac: false,
|
||||
"restriction-schedule": false,
|
||||
"team-booking-page-cache": false,
|
||||
"cal-ai-voice-agents": false,
|
||||
"tiered-support-chat": false,
|
||||
"calendar-subscription-cache": false,
|
||||
"calendar-subscription-sync": false,
|
||||
"onboarding-v3": false,
|
||||
"booker-botid": false,
|
||||
"booking-calendar-view": false,
|
||||
"booking-email-sms-tasker": false,
|
||||
"bookings-v3": false,
|
||||
"booking-audit": false,
|
||||
"monthly-proration": false,
|
||||
"sidebar-tips": false,
|
||||
};
|
||||
|
||||
if (process.env.NEXT_PUBLIC_IS_E2E) {
|
||||
initialData.organizations = true;
|
||||
initialData.teams = true;
|
||||
}
|
||||
|
||||
export function useFlags(): Partial<AppFlags> {
|
||||
const query = trpc.viewer.features.map.useQuery();
|
||||
return query.data ?? initialData;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
"use client";
|
||||
|
||||
import { Suspense } from "react";
|
||||
|
||||
import NoSSR from "@calcom/lib/components/NoSSR";
|
||||
import { SkeletonText, SkeletonContainer } from "@calcom/ui/components/skeleton";
|
||||
|
||||
import { FlagAdminList } from "../components/FlagAdminList";
|
||||
|
||||
const SkeletonLoader = () => {
|
||||
return (
|
||||
<SkeletonContainer>
|
||||
<div className="divide-subtle mb-8 mt-6 stack-y-6">
|
||||
<SkeletonText className="h-8 w-full" />
|
||||
<SkeletonText className="h-8 w-full" />
|
||||
</div>
|
||||
</SkeletonContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export const FlagListingView = () => {
|
||||
return (
|
||||
<NoSSR>
|
||||
<Suspense fallback={<SkeletonLoader />}>
|
||||
<FlagAdminList />
|
||||
</Suspense>
|
||||
</NoSSR>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user