index.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. 'use client'
  2. import { useTranslation } from 'react-i18next'
  3. import { useRouter } from 'next/navigation'
  4. import { useCallback } from 'react'
  5. import s from './index.module.css'
  6. import cn from '@/utils/classnames'
  7. import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
  8. type IStepsNavBarProps = {
  9. step: number
  10. datasetId?: string
  11. }
  12. const STEP_T_MAP: Record<number, string> = {
  13. 1: 'datasetCreation.steps.one',
  14. 2: 'datasetCreation.steps.two',
  15. 3: 'datasetCreation.steps.three',
  16. }
  17. const STEP_LIST = [1, 2, 3]
  18. const StepsNavBar = ({
  19. step,
  20. datasetId,
  21. }: IStepsNavBarProps) => {
  22. const { t } = useTranslation()
  23. const router = useRouter()
  24. const media = useBreakpoints()
  25. const isMobile = media === MediaType.mobile
  26. const navBackHandle = useCallback(() => {
  27. if (!datasetId)
  28. router.replace('/datasets')
  29. else
  30. router.replace(`/datasets/${datasetId}/documents`)
  31. }, [router, datasetId])
  32. return (
  33. <div className='w-full pt-4'>
  34. <div className={cn(s.stepsHeader, isMobile && '!px-0 justify-center')}>
  35. <div onClick={navBackHandle} className={cn(s.navBack, isMobile && '!mr-0')} />
  36. {!isMobile && (!datasetId ? t('datasetCreation.steps.header.creation') : t('datasetCreation.steps.header.update'))}
  37. </div>
  38. <div className={cn(s.stepList, isMobile && '!p-0')}>
  39. {STEP_LIST.map(item => (
  40. <div
  41. key={item}
  42. className={cn(s.stepItem, s[`step${item}`], step === item && s.active, step > item && s.done, isMobile && 'px-0')}
  43. >
  44. <div className={cn(s.stepNum)}>{step > item ? '' : item}</div>
  45. <div className={cn(s.stepName)}>{isMobile ? '' : t(STEP_T_MAP[item])}</div>
  46. </div>
  47. ))}
  48. </div>
  49. </div>
  50. )
  51. }
  52. export default StepsNavBar