maintenance-notice.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { useState } from 'react'
  2. import { useContext } from 'use-context-selector'
  3. import I18n from '@/context/i18n'
  4. import { X } from '@/app/components/base/icons/src/vender/line/general'
  5. import { NOTICE_I18N } from '@/i18n/language'
  6. const MaintenanceNotice = () => {
  7. const { locale } = useContext(I18n)
  8. const [showNotice, setShowNotice] = useState(localStorage.getItem('hide-maintenance-notice') !== '1')
  9. const handleJumpNotice = () => {
  10. window.open(NOTICE_I18N.href, '_blank')
  11. }
  12. const handleCloseNotice = () => {
  13. localStorage.setItem('hide-maintenance-notice', '1')
  14. setShowNotice(false)
  15. }
  16. const titleByLocale: { [key: string]: string } = NOTICE_I18N.title
  17. const descByLocale: { [key: string]: string } = NOTICE_I18N.desc
  18. if (!showNotice)
  19. return null
  20. return (
  21. <div className='shrink-0 flex items-center px-4 h-[38px] bg-[#FFFAEB] border-b border-[0.5px] border-b-[#FEF0C7] z-20'>
  22. <div className='shrink-0 flex items-center mr-2 px-2 h-[22px] bg-[#F79009] text-white text-[11px] font-medium rounded-xl'>{titleByLocale[locale]}</div>
  23. {
  24. (NOTICE_I18N.href && NOTICE_I18N.href !== '#')
  25. ? <div className='grow text-xs font-medium text-gray-700 cursor-pointer' onClick={handleJumpNotice}>{descByLocale[locale]}</div>
  26. : <div className='grow text-xs font-medium text-gray-700'>{descByLocale[locale]}</div>
  27. }
  28. <X className='shrink-0 w-4 h-4 text-gray-500 cursor-pointer' onClick={handleCloseNotice} />
  29. </div>
  30. )
  31. }
  32. export default MaintenanceNotice