| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							|  |  |  | import { Fragment, useState } from 'react' | 
					
						
							|  |  |  | import { ChevronDownIcon, PlusIcon } from '@heroicons/react/24/solid' | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  | import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import { useRouter } from 'next/navigation' | 
					
						
							|  |  |  | import Indicator from '../indicator' | 
					
						
							|  |  |  | import type { AppDetailResponse } from '@/models/app' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import CreateAppDialog from '@/app/components/app/create-app-dialog' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import AppIcon from '@/app/components/base/app-icon' | 
					
						
							| 
									
										
										
										
											2023-08-15 13:35:47 +08:00
										 |  |  | import { useAppContext } from '@/context/app-context' | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  | import { noop } from 'lodash-es' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type IAppSelectorProps = { | 
					
						
							|  |  |  |   appItems: AppDetailResponse[] | 
					
						
							|  |  |  |   curApp: AppDetailResponse | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default function AppSelector({ appItems, curApp }: IAppSelectorProps) { | 
					
						
							|  |  |  |   const router = useRouter() | 
					
						
							| 
									
										
										
										
											2024-06-14 07:34:25 -05:00
										 |  |  |   const { isCurrentWorkspaceEditor } = useAppContext() | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   const [showNewAppDialog, setShowNewAppDialog] = useState(false) | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const itemClassName = `
 | 
					
						
							|  |  |  |     flex items-center w-full h-10 px-3 text-gray-700 text-[14px] | 
					
						
							|  |  |  |     rounded-lg font-normal hover:bg-gray-100 cursor-pointer | 
					
						
							|  |  |  |   `
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div className=""> | 
					
						
							|  |  |  |       <Menu as="div" className="relative inline-block text-left"> | 
					
						
							|  |  |  |         <div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <MenuButton | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |             className=" | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               inline-flex h-7 w-full items-center justify-center | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |               rounded-[10px] pl-2 pr-2.5 text-[14px] font-semibold | 
					
						
							|  |  |  |               text-[#1C64F2] hover:bg-[#EBF5FF] | 
					
						
							|  |  |  |             " | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             {curApp?.name} | 
					
						
							|  |  |  |             <ChevronDownIcon | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               className="ml-1 h-3 w-3" | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |               aria-hidden="true" | 
					
						
							|  |  |  |             /> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           </MenuButton> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         </div> | 
					
						
							|  |  |  |         <Transition | 
					
						
							|  |  |  |           as={Fragment} | 
					
						
							|  |  |  |           enter="transition ease-out duration-100" | 
					
						
							|  |  |  |           enterFrom="transform opacity-0 scale-95" | 
					
						
							|  |  |  |           enterTo="transform opacity-100 scale-100" | 
					
						
							|  |  |  |           leave="transition ease-in duration-75" | 
					
						
							|  |  |  |           leaveFrom="transform opacity-100 scale-100" | 
					
						
							|  |  |  |           leaveTo="transform opacity-0 scale-95" | 
					
						
							|  |  |  |         > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <MenuItems | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |             className=" | 
					
						
							|  |  |  |               absolute -left-11 right-0 mt-1.5 w-60 max-w-80 | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               origin-top-right divide-y divide-gray-100 rounded-lg bg-white | 
					
						
							| 
									
										
										
										
											2023-08-12 00:57:13 +08:00
										 |  |  |               shadow-lg | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |             " | 
					
						
							|  |  |  |           > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             {!!appItems.length && (<div className="overflow-auto px-1 py-1" style={{ maxHeight: '50vh' }}> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |               { | 
					
						
							|  |  |  |                 appItems.map((app: AppDetailResponse) => ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                   <MenuItem key={app.id}> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |                     <div className={itemClassName} onClick={() => | 
					
						
							| 
									
										
										
										
											2024-06-14 07:34:25 -05:00
										 |  |  |                       router.push(`/app/${app.id}/${isCurrentWorkspaceEditor ? 'configuration' : 'overview'}`) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |                     }> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                       <div className='relative mr-2 h-6 w-6 rounded-[6px] bg-[#D5F5F6]'> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |                         <AppIcon size='tiny' /> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                         <div className='absolute -bottom-0.5 -right-0.5 flex h-2.5 w-2.5 items-center justify-center rounded bg-white'> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |                           <Indicator /> | 
					
						
							|  |  |  |                         </div> | 
					
						
							|  |  |  |                       </div> | 
					
						
							|  |  |  |                       {app.name} | 
					
						
							|  |  |  |                     </div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                   </MenuItem> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |                 )) | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             </div>)} | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             {isCurrentWorkspaceEditor && <MenuItem> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |               <div className='p-1' onClick={() => setShowNewAppDialog(true)}> | 
					
						
							|  |  |  |                 <div | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                   className='flex h-12 cursor-pointer items-center rounded-lg hover:bg-gray-100' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |                 > | 
					
						
							|  |  |  |                   <div | 
					
						
							|  |  |  |                     className=' | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                       ml-4 mr-2 flex | 
					
						
							|  |  |  |                       h-6 w-6 items-center justify-center rounded-[6px] border-[0.5px] | 
					
						
							|  |  |  |                       border-dashed border-gray-200 bg-gray-100 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |                     ' | 
					
						
							|  |  |  |                   > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                     <PlusIcon className='h-4 w-4 text-gray-500' /> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |                   </div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                   <div className='text-[14px] font-normal text-gray-700'>{t('common.menus.newApp')}</div> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |                 </div> | 
					
						
							|  |  |  |               </div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             </MenuItem> | 
					
						
							| 
									
										
										
										
											2023-08-15 13:35:47 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           </MenuItems> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         </Transition> | 
					
						
							|  |  |  |       </Menu> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |       <CreateAppDialog | 
					
						
							|  |  |  |         show={showNewAppDialog} | 
					
						
							|  |  |  |         onClose={() => setShowNewAppDialog(false)} | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  |         onSuccess={noop} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |       /> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } |