|
3 | 3 | import type {ConnectorConfig} from '@openint/api-v1/trpc/routers/connectorConfig.models'
|
4 | 4 | import type {Id} from '@openint/cdk'
|
5 | 5 |
|
| 6 | +import {SearchIcon} from 'lucide-react' |
| 7 | +import {ReactElement, useState} from 'react' |
6 | 8 | import {type ConnectorName} from '@openint/api-v1/trpc/routers/connector.models'
|
7 |
| -import {Label} from '@openint/shadcn/ui' |
8 |
| -import {ConnectorConfigCard} from '@openint/ui-v1/domain-components/ConnectorConfigCard' |
| 9 | +import {cn} from '@openint/shadcn/lib/utils' |
| 10 | +import { |
| 11 | + Dialog, |
| 12 | + DialogContent, |
| 13 | + DialogHeader, |
| 14 | + DialogTitle, |
| 15 | + Input, |
| 16 | +} from '@openint/shadcn/ui' |
| 17 | +import {ConnectorDisplay} from '@openint/ui-v1/domain-components/ConnectorDisplay' |
| 18 | +import {useMutableSearchParams} from '@openint/ui-v1/hooks/useStateFromSearchParam' |
9 | 19 | import {ConnectorConnectContainer} from './ConnectorConnect.client'
|
10 | 20 |
|
11 | 21 | export type ConnectorConfigForCustomer = Pick<
|
12 | 22 | ConnectorConfig<'connector'>,
|
13 | 23 | 'id' | 'connector_name' | 'connector'
|
14 | 24 | >
|
15 | 25 |
|
| 26 | +export type AddConnectionPrefetchedCard = { |
| 27 | + connectorName: ConnectorName |
| 28 | + connectorDisplayName?: string |
| 29 | + card: ReactElement |
| 30 | +} |
| 31 | + |
| 32 | +export function AddConnectionClient({ |
| 33 | + cards, |
| 34 | + className, |
| 35 | +}: { |
| 36 | + cards: AddConnectionPrefetchedCard[] |
| 37 | + className?: string |
| 38 | +}) { |
| 39 | + const [isOpen, setIsOpen] = useState(true) |
| 40 | + const [_, setSearchParams] = useMutableSearchParams() |
| 41 | + |
| 42 | + const onClose = () => { |
| 43 | + setIsOpen(false) |
| 44 | + setSearchParams({view: 'manage'}, {shallow: false}) |
| 45 | + } |
| 46 | + const [searchQuery, setSearchQuery] = useState('') |
| 47 | + const [isFocused, setIsFocused] = useState(false) |
| 48 | + |
| 49 | + const filteredCards = cards.filter((card) => { |
| 50 | + const searchLower = searchQuery.toLowerCase() |
| 51 | + return ( |
| 52 | + card.connectorName.toLowerCase().includes(searchLower) || |
| 53 | + card.connectorDisplayName?.toLowerCase().includes(searchLower) |
| 54 | + ) |
| 55 | + }) |
| 56 | + |
| 57 | + return ( |
| 58 | + <Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}> |
| 59 | + {/* TODO: consider making full screen horizontal on mobile https://github.com/radix-ui/themes/issues/142 */} |
| 60 | + <DialogContent |
| 61 | + className={cn( |
| 62 | + 'flex h-[85vh] max-h-[600px] max-w-2xl flex-col gap-0 overflow-hidden p-0 shadow-xl', |
| 63 | + className, |
| 64 | + )}> |
| 65 | + <DialogHeader className="bg-foreground/5 flex-shrink-0 border-b px-6 py-4"> |
| 66 | + <DialogTitle className="text-md">Add Integrations</DialogTitle> |
| 67 | + </DialogHeader> |
| 68 | + |
| 69 | + <div className="flex flex-1 flex-col overflow-hidden"> |
| 70 | + <div |
| 71 | + className={cn( |
| 72 | + 'bg-background sticky top-0 z-10 flex-shrink-0 transition-all duration-200', |
| 73 | + 'border-b border-b-transparent', |
| 74 | + isFocused ? 'border-b-gray-100 shadow-sm' : '', |
| 75 | + )}> |
| 76 | + <div className="p-6 pb-3"> |
| 77 | + <div className="relative"> |
| 78 | + <SearchIcon className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 transform text-gray-500" /> |
| 79 | + <Input |
| 80 | + placeholder="Search integrations" |
| 81 | + value={searchQuery} |
| 82 | + onChange={(e) => setSearchQuery(e.target.value)} |
| 83 | + className="border-gray-200 bg-gray-50/50 pl-10 transition-all duration-200 focus:bg-white focus:shadow-sm" |
| 84 | + onFocus={() => setIsFocused(true)} |
| 85 | + onBlur={() => setIsFocused(false)} |
| 86 | + /> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + |
| 91 | + <div |
| 92 | + className="relative flex-1 overflow-y-auto" |
| 93 | + onScroll={(e) => { |
| 94 | + const scrollTop = e.currentTarget.scrollTop |
| 95 | + const shouldBeFocused = scrollTop > 5 |
| 96 | + if (shouldBeFocused !== isFocused) { |
| 97 | + setIsFocused(shouldBeFocused) |
| 98 | + } |
| 99 | + }}> |
| 100 | + {/* Mobile view */} |
| 101 | + <div className="p-6 pt-3 md:hidden"> |
| 102 | + {filteredCards.map((card, index) => ( |
| 103 | + <div key={`${card.connectorName}-${index}`}> |
| 104 | + {card.card} |
| 105 | + {index < filteredCards.length - 1 && ( |
| 106 | + <div className="my-1 h-px bg-gray-100" /> |
| 107 | + )} |
| 108 | + </div> |
| 109 | + ))} |
| 110 | + </div> |
| 111 | + |
| 112 | + {/* Desktop view: Grid layout */} |
| 113 | + <div className="hidden p-6 pt-3 md:grid md:grid-cols-2 md:gap-4"> |
| 114 | + {filteredCards.map((card, index) => ( |
| 115 | + <div |
| 116 | + key={`${card.connectorName}-${index}`} |
| 117 | + className="transition-transform duration-100 hover:scale-[1.01]"> |
| 118 | + {card.card} |
| 119 | + </div> |
| 120 | + ))} |
| 121 | + </div> |
| 122 | + |
| 123 | + {filteredCards.length === 0 && ( |
| 124 | + <div className="col-span-2 py-16 text-center text-gray-500"> |
| 125 | + No integrations found matching{' '} |
| 126 | + {searchQuery ? `"${searchQuery}"` : 'your search'} |
| 127 | + </div> |
| 128 | + )} |
| 129 | + </div> |
| 130 | + </div> |
| 131 | + </DialogContent> |
| 132 | + </Dialog> |
| 133 | + ) |
| 134 | +} |
| 135 | + |
16 | 136 | export function AddConnectionCard({
|
17 | 137 | connectorConfig,
|
18 | 138 | }: {
|
19 | 139 | connectorConfig: ConnectorConfigForCustomer
|
20 | 140 | onReady?: (ctx: {state: string}, name: string) => void
|
21 | 141 | }) {
|
| 142 | + const [_, setSearchParams] = useMutableSearchParams() |
| 143 | + |
| 144 | + const handleSelect = () => { |
| 145 | + setSearchParams({view: 'manage'}, {shallow: false}) |
| 146 | + } |
| 147 | + |
22 | 148 | return (
|
23 | 149 | <ConnectorConnectContainer
|
24 | 150 | connectorName={connectorConfig.connector_name as ConnectorName}
|
25 | 151 | connector={connectorConfig.connector!}
|
26 | 152 | connectorConfigId={connectorConfig.id as Id['ccfg']}>
|
27 | 153 | {({isConnecting, handleConnect}) => (
|
28 |
| - <ConnectorConfigCard |
29 |
| - displayNameLocation="right" |
30 |
| - // TODO: fix this |
31 |
| - connectorConfig={connectorConfig as ConnectorConfig<'connector'>} |
32 |
| - onPress={() => { |
33 |
| - if (isConnecting) { |
34 |
| - return |
35 |
| - } |
36 |
| - handleConnect() |
37 |
| - }}> |
38 |
| - <Label className="text-muted-foreground pointer-events-none ml-auto text-sm"> |
39 |
| - {isConnecting ? 'Connecting...' : 'Connect'} |
40 |
| - </Label> |
41 |
| - </ConnectorConfigCard> |
| 154 | + <> |
| 155 | + {/* NOTE/TODO: note sure how to remove duplication, |
| 156 | + its there as we're using tailwind for consistent breakpoints with AddConnectionClient */} |
| 157 | + {/* Mobile view (visible below md breakpoint) */} |
| 158 | + <div className="md:hidden"> |
| 159 | + <ConnectorDisplay |
| 160 | + connector={connectorConfig.connector!} |
| 161 | + className={cn( |
| 162 | + 'transition-transform duration-100', |
| 163 | + !isConnecting && 'hover:scale-[1.01]', |
| 164 | + isConnecting && 'cursor-not-allowed opacity-70', |
| 165 | + )} |
| 166 | + displayBadges={false} |
| 167 | + mode="row" |
| 168 | + onPress={() => { |
| 169 | + if (isConnecting) { |
| 170 | + return |
| 171 | + } |
| 172 | + handleSelect() |
| 173 | + handleConnect() |
| 174 | + }} |
| 175 | + /> |
| 176 | + </div> |
| 177 | + |
| 178 | + {/* Desktop view (visible at md breakpoint and above) */} |
| 179 | + <div className="hidden md:block"> |
| 180 | + <ConnectorDisplay |
| 181 | + connector={connectorConfig.connector!} |
| 182 | + className={cn( |
| 183 | + 'transition-transform duration-100', |
| 184 | + !isConnecting && 'hover:scale-[1.01]', |
| 185 | + isConnecting && 'cursor-not-allowed opacity-70', |
| 186 | + )} |
| 187 | + displayBadges={false} |
| 188 | + mode="card" |
| 189 | + onPress={() => { |
| 190 | + if (isConnecting) { |
| 191 | + return |
| 192 | + } |
| 193 | + handleSelect() |
| 194 | + handleConnect() |
| 195 | + }} |
| 196 | + /> |
| 197 | + </div> |
| 198 | + </> |
42 | 199 | )}
|
43 | 200 | </ConnectorConnectContainer>
|
44 | 201 | )
|
|
0 commit comments