index.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. 'use client'
  2. import { useTranslation } from 'react-i18next'
  3. import { Fragment, useState } from 'react'
  4. import { ChevronDownIcon, PlusIcon } from '@heroicons/react/24/solid'
  5. import { Menu, Transition } from '@headlessui/react'
  6. import { useRouter } from 'next/navigation'
  7. import Indicator from '../indicator'
  8. import type { AppDetailResponse } from '@/models/app'
  9. import NewAppDialog from '@/app/(commonLayout)/apps/NewAppDialog'
  10. import AppIcon from '@/app/components/base/app-icon'
  11. type IAppSelectorProps = {
  12. appItems: AppDetailResponse[]
  13. curApp: AppDetailResponse
  14. }
  15. export default function AppSelector({ appItems, curApp }: IAppSelectorProps) {
  16. const router = useRouter()
  17. const [showNewAppDialog, setShowNewAppDialog] = useState(false)
  18. const { t } = useTranslation()
  19. const itemClassName = `
  20. flex items-center w-full h-10 px-3 text-gray-700 text-[14px]
  21. rounded-lg font-normal hover:bg-gray-100 cursor-pointer
  22. `
  23. return (
  24. <div className="">
  25. <Menu as="div" className="relative inline-block text-left">
  26. <div>
  27. <Menu.Button
  28. className="
  29. inline-flex items-center w-full h-7 justify-center
  30. rounded-[10px] pl-2 pr-2.5 text-[14px] font-semibold
  31. text-[#1C64F2] hover:bg-[#EBF5FF]
  32. "
  33. >
  34. {curApp?.name}
  35. <ChevronDownIcon
  36. className="w-3 h-3 ml-1"
  37. aria-hidden="true"
  38. />
  39. </Menu.Button>
  40. </div>
  41. <Transition
  42. as={Fragment}
  43. enter="transition ease-out duration-100"
  44. enterFrom="transform opacity-0 scale-95"
  45. enterTo="transform opacity-100 scale-100"
  46. leave="transition ease-in duration-75"
  47. leaveFrom="transform opacity-100 scale-100"
  48. leaveTo="transform opacity-0 scale-95"
  49. >
  50. <Menu.Items
  51. className="
  52. absolute -left-11 right-0 mt-1.5 w-60 max-w-80
  53. divide-y divide-gray-100 origin-top-right rounded-lg bg-white
  54. shadow-[0_10px_15px_-3px_rgba(0,0,0,0.1),0_4px_6px_rgba(0,0,0,0.05)]
  55. "
  56. >
  57. {!!appItems.length && (<div className="px-1 py-1 overflow-auto" style={{ maxHeight: '50vh' }}>
  58. {
  59. appItems.map((app: AppDetailResponse) => (
  60. <Menu.Item key={app.id}>
  61. <div className={itemClassName} onClick={() =>
  62. router.push(`/app/${app.id}/overview`)
  63. }>
  64. <div className='relative w-6 h-6 mr-2 bg-[#D5F5F6] rounded-[6px]'>
  65. <AppIcon size='tiny' />
  66. <div className='flex justify-center items-center absolute -right-0.5 -bottom-0.5 w-2.5 h-2.5 bg-white rounded'>
  67. <Indicator />
  68. </div>
  69. </div>
  70. {app.name}
  71. </div>
  72. </Menu.Item>
  73. ))
  74. }
  75. </div>)}
  76. <Menu.Item>
  77. <div className='p-1' onClick={() => setShowNewAppDialog(true)}>
  78. <div
  79. className='flex items-center h-12 rounded-lg cursor-pointer hover:bg-gray-100'
  80. >
  81. <div
  82. className='
  83. flex justify-center items-center
  84. ml-4 mr-2 w-6 h-6 bg-gray-100 rounded-[6px]
  85. border-[0.5px] border-gray-200 border-dashed
  86. '
  87. >
  88. <PlusIcon className='w-4 h-4 text-gray-500' />
  89. </div>
  90. <div className='font-normal text-[14px] text-gray-700'>{t('common.menus.newApp')}</div>
  91. </div>
  92. </div>
  93. </Menu.Item>
  94. </Menu.Items>
  95. </Transition>
  96. </Menu>
  97. <NewAppDialog show={showNewAppDialog} onClose={() => setShowNewAppDialog(false)} />
  98. </div>
  99. )
  100. }