import { X } from 'lucide-react' import { useState } from 'react' import { toast } from 'sonner' import { Button, cn, ScrollArea, Sheet, SheetContent, SheetHeader } from 'ui' import { PrivateApp, usePrivateApps } from '../../PrivateAppsContext' import { PERMISSIONS, type Permission } from '../Apps.constants' import { DeleteAppModal } from '../DeleteAppModal' import { ViewAppSheetDangerZone } from './ViewAppSheetDangerZone' import { ViewAppSheetInfo } from './ViewAppSheetInfo' import { ViewAppSheetPermissions } from './ViewAppSheetPermissions' import { usePlatformAppDeleteMutation } from '@/data/platform-apps/platform-app-delete-mutation' import { usePlatformAppQuery } from '@/data/platform-apps/platform-app-query' interface ViewAppSheetProps { app: PrivateApp | null visible: boolean onClose: () => void onDeleted: () => void } export function ViewAppSheet({ app, visible, onClose, onDeleted }: ViewAppSheetProps) { const { slug, installations, removeInstallationsByAppId } = usePrivateApps() const installation = installations.find((i) => i.app_id === app?.id) const isInstalled = installation !== undefined const [showDeleteModal, setShowDeleteModal] = useState(false) const { data: detail, isLoading: isLoadingDetail } = usePlatformAppQuery( { slug, id: app?.id }, { enabled: visible && app !== null } ) const { mutate: deleteApp, isPending: isDeleting } = usePlatformAppDeleteMutation({ onSuccess: (_, vars) => { toast.success(`Deleted "${app?.name}"`) removeInstallationsByAppId(vars.appId) setShowDeleteModal(false) onClose() onDeleted() }, }) function handleDelete() { if (!app || !slug) return deleteApp({ slug, appId: app.id }) } const permissions: Permission[] = detail ? detail.permissions .map((id) => PERMISSIONS.find((p) => p.id === id)) .filter((p): p is Permission => p !== undefined) : [] return ( <> { if (!open) onClose() }} >

{app?.name}