Przeglądaj źródła

refactor: reorganize utility files into `lib/` folder (#209)

* refactor: reorganize utility files into lib/ folder

* chore: add ESLint rule to prevent duplicate imports
Sat Naing 10 miesięcy temu
rodzic
commit
2faffb43bc
27 zmienionych plików z 30 dodań i 33 usunięć
  1. 2 0
      eslint.config.js
  2. 3 1
      src/components/layout/data/sidebar-data.ts
  3. 1 2
      src/features/auth/forgot-password/components/forgot-password-form.tsx
  4. 1 1
      src/features/auth/otp/components/otp-form.tsx
  5. 1 2
      src/features/auth/sign-in/components/user-auth-form.tsx
  6. 1 1
      src/features/chats/components/new-chat.tsx
  7. 1 1
      src/features/settings/account/account-form.tsx
  8. 1 1
      src/features/settings/appearance/appearance-form.tsx
  9. 1 2
      src/features/settings/components/sidebar-nav.tsx
  10. 1 1
      src/features/settings/display/display-form.tsx
  11. 1 1
      src/features/settings/notifications/notifications-form.tsx
  12. 1 1
      src/features/settings/profile/profile-form.tsx
  13. 1 1
      src/features/tasks/components/data-table-bulk-actions.tsx
  14. 1 1
      src/features/tasks/components/tasks-dialogs.tsx
  15. 1 1
      src/features/tasks/components/tasks-import-dialog.tsx
  16. 1 1
      src/features/tasks/components/tasks-multi-delete-dialog.tsx
  17. 1 1
      src/features/tasks/components/tasks-mutate-drawer.tsx
  18. 1 1
      src/features/users/components/data-table-bulk-actions.tsx
  19. 1 1
      src/features/users/components/users-action-dialog.tsx
  20. 1 1
      src/features/users/components/users-delete-dialog.tsx
  21. 1 1
      src/features/users/components/users-invite-dialog.tsx
  22. 1 1
      src/features/users/components/users-multi-delete-dialog.tsx
  23. 0 0
      src/lib/handle-server-error.ts
  24. 0 0
      src/lib/show-submitted-data.tsx
  25. 4 0
      src/lib/utils.ts
  26. 1 1
      src/main.tsx
  27. 0 8
      src/utils/sleep.ts

+ 2 - 0
eslint.config.js

@@ -51,6 +51,8 @@ export default tseslint.config(
           disallowTypeAnnotations: false,
         },
       ],
+      // Prevent duplicate imports from the same module
+      'no-duplicate-imports': 'error',
     },
   }
 )

+ 3 - 1
src/components/layout/data/sidebar-data.ts

@@ -18,8 +18,10 @@ import {
   Users,
   MessagesSquare,
   ShieldCheck,
+  AudioWaveform,
+  Command,
+  GalleryVerticalEnd,
 } from 'lucide-react'
-import { AudioWaveform, Command, GalleryVerticalEnd } from 'lucide-react'
 import { ClerkLogo } from '@/assets/clerk-logo'
 import { type SidebarData } from '../types'
 

+ 1 - 2
src/features/auth/forgot-password/components/forgot-password-form.tsx

@@ -5,8 +5,7 @@ import { zodResolver } from '@hookform/resolvers/zod'
 import { useNavigate } from '@tanstack/react-router'
 import { ArrowRight, Loader2 } from 'lucide-react'
 import { toast } from 'sonner'
-import { cn } from '@/lib/utils'
-import { sleep } from '@/utils/sleep'
+import { sleep, cn } from '@/lib/utils'
 import { Button } from '@/components/ui/button'
 import {
   Form,

+ 1 - 1
src/features/auth/otp/components/otp-form.tsx

@@ -3,8 +3,8 @@ import { z } from 'zod'
 import { useForm } from 'react-hook-form'
 import { zodResolver } from '@hookform/resolvers/zod'
 import { useNavigate } from '@tanstack/react-router'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { cn } from '@/lib/utils'
-import { showSubmittedData } from '@/utils/show-submitted-data'
 import { Button } from '@/components/ui/button'
 import {
   Form,

+ 1 - 2
src/features/auth/sign-in/components/user-auth-form.tsx

@@ -7,8 +7,7 @@ import { Loader2, LogIn } from 'lucide-react'
 import { toast } from 'sonner'
 import { IconFacebook, IconGithub } from '@/assets/brand-icons'
 import { useAuthStore } from '@/stores/auth-store'
-import { cn } from '@/lib/utils'
-import { sleep } from '@/utils/sleep'
+import { sleep, cn } from '@/lib/utils'
 import { Button } from '@/components/ui/button'
 import {
   Form,

+ 1 - 1
src/features/chats/components/new-chat.tsx

@@ -1,6 +1,6 @@
 import { useEffect, useState } from 'react'
 import { Check, X } from 'lucide-react'
-import { showSubmittedData } from '@/utils/show-submitted-data'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { Badge } from '@/components/ui/badge'
 import { Button } from '@/components/ui/button'
 import {

+ 1 - 1
src/features/settings/account/account-form.tsx

@@ -2,8 +2,8 @@ import { z } from 'zod'
 import { useForm } from 'react-hook-form'
 import { CaretSortIcon, CheckIcon } from '@radix-ui/react-icons'
 import { zodResolver } from '@hookform/resolvers/zod'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { cn } from '@/lib/utils'
-import { showSubmittedData } from '@/utils/show-submitted-data'
 import { Button } from '@/components/ui/button'
 import {
   Command,

+ 1 - 1
src/features/settings/appearance/appearance-form.tsx

@@ -3,8 +3,8 @@ import { useForm } from 'react-hook-form'
 import { ChevronDownIcon } from '@radix-ui/react-icons'
 import { zodResolver } from '@hookform/resolvers/zod'
 import { fonts } from '@/config/fonts'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { cn } from '@/lib/utils'
-import { showSubmittedData } from '@/utils/show-submitted-data'
 import { useFont } from '@/context/font-provider'
 import { useTheme } from '@/context/theme-provider'
 import { Button, buttonVariants } from '@/components/ui/button'

+ 1 - 2
src/features/settings/components/sidebar-nav.tsx

@@ -1,6 +1,5 @@
 import { useState, type JSX } from 'react'
-import { useLocation, useNavigate } from '@tanstack/react-router'
-import { Link } from '@tanstack/react-router'
+import { useLocation, useNavigate, Link } from '@tanstack/react-router'
 import { cn } from '@/lib/utils'
 import { buttonVariants } from '@/components/ui/button'
 import { ScrollArea } from '@/components/ui/scroll-area'

+ 1 - 1
src/features/settings/display/display-form.tsx

@@ -1,7 +1,7 @@
 import { z } from 'zod'
 import { useForm } from 'react-hook-form'
 import { zodResolver } from '@hookform/resolvers/zod'
-import { showSubmittedData } from '@/utils/show-submitted-data'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { Button } from '@/components/ui/button'
 import { Checkbox } from '@/components/ui/checkbox'
 import {

+ 1 - 1
src/features/settings/notifications/notifications-form.tsx

@@ -2,7 +2,7 @@ import { z } from 'zod'
 import { useForm } from 'react-hook-form'
 import { zodResolver } from '@hookform/resolvers/zod'
 import { Link } from '@tanstack/react-router'
-import { showSubmittedData } from '@/utils/show-submitted-data'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { Button } from '@/components/ui/button'
 import { Checkbox } from '@/components/ui/checkbox'
 import {

+ 1 - 1
src/features/settings/profile/profile-form.tsx

@@ -2,8 +2,8 @@ import { z } from 'zod'
 import { useFieldArray, useForm } from 'react-hook-form'
 import { zodResolver } from '@hookform/resolvers/zod'
 import { Link } from '@tanstack/react-router'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { cn } from '@/lib/utils'
-import { showSubmittedData } from '@/utils/show-submitted-data'
 import { Button } from '@/components/ui/button'
 import {
   Form,

+ 1 - 1
src/features/tasks/components/data-table-bulk-actions.tsx

@@ -2,7 +2,7 @@ import { useState } from 'react'
 import { type Table } from '@tanstack/react-table'
 import { Trash2, CircleArrowUp, ArrowUpDown, Download } from 'lucide-react'
 import { toast } from 'sonner'
-import { sleep } from '@/utils/sleep'
+import { sleep } from '@/lib/utils'
 import { Button } from '@/components/ui/button'
 import {
   DropdownMenu,

+ 1 - 1
src/features/tasks/components/tasks-dialogs.tsx

@@ -1,4 +1,4 @@
-import { showSubmittedData } from '@/utils/show-submitted-data'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { ConfirmDialog } from '@/components/confirm-dialog'
 import { TasksImportDialog } from './tasks-import-dialog'
 import { TasksMutateDrawer } from './tasks-mutate-drawer'

+ 1 - 1
src/features/tasks/components/tasks-import-dialog.tsx

@@ -1,7 +1,7 @@
 import { z } from 'zod'
 import { useForm } from 'react-hook-form'
 import { zodResolver } from '@hookform/resolvers/zod'
-import { showSubmittedData } from '@/utils/show-submitted-data'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { Button } from '@/components/ui/button'
 import {
   Dialog,

+ 1 - 1
src/features/tasks/components/tasks-multi-delete-dialog.tsx

@@ -4,7 +4,7 @@ import { useState } from 'react'
 import { type Table } from '@tanstack/react-table'
 import { AlertTriangle } from 'lucide-react'
 import { toast } from 'sonner'
-import { sleep } from '@/utils/sleep'
+import { sleep } from '@/lib/utils'
 import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
 import { Input } from '@/components/ui/input'
 import { Label } from '@/components/ui/label'

+ 1 - 1
src/features/tasks/components/tasks-mutate-drawer.tsx

@@ -1,7 +1,7 @@
 import { z } from 'zod'
 import { useForm } from 'react-hook-form'
 import { zodResolver } from '@hookform/resolvers/zod'
-import { showSubmittedData } from '@/utils/show-submitted-data'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { Button } from '@/components/ui/button'
 import {
   Form,

+ 1 - 1
src/features/users/components/data-table-bulk-actions.tsx

@@ -2,7 +2,7 @@ import { useState } from 'react'
 import { type Table } from '@tanstack/react-table'
 import { Trash2, UserX, UserCheck, Mail } from 'lucide-react'
 import { toast } from 'sonner'
-import { sleep } from '@/utils/sleep'
+import { sleep } from '@/lib/utils'
 import { Button } from '@/components/ui/button'
 import {
   Tooltip,

+ 1 - 1
src/features/users/components/users-action-dialog.tsx

@@ -3,7 +3,7 @@
 import { z } from 'zod'
 import { useForm } from 'react-hook-form'
 import { zodResolver } from '@hookform/resolvers/zod'
-import { showSubmittedData } from '@/utils/show-submitted-data'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { Button } from '@/components/ui/button'
 import {
   Dialog,

+ 1 - 1
src/features/users/components/users-delete-dialog.tsx

@@ -2,7 +2,7 @@
 
 import { useState } from 'react'
 import { AlertTriangle } from 'lucide-react'
-import { showSubmittedData } from '@/utils/show-submitted-data'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
 import { Input } from '@/components/ui/input'
 import { Label } from '@/components/ui/label'

+ 1 - 1
src/features/users/components/users-invite-dialog.tsx

@@ -2,7 +2,7 @@ import { z } from 'zod'
 import { useForm } from 'react-hook-form'
 import { zodResolver } from '@hookform/resolvers/zod'
 import { MailPlus, Send } from 'lucide-react'
-import { showSubmittedData } from '@/utils/show-submitted-data'
+import { showSubmittedData } from '@/lib/show-submitted-data'
 import { Button } from '@/components/ui/button'
 import {
   Dialog,

+ 1 - 1
src/features/users/components/users-multi-delete-dialog.tsx

@@ -4,7 +4,7 @@ import { useState } from 'react'
 import { type Table } from '@tanstack/react-table'
 import { AlertTriangle } from 'lucide-react'
 import { toast } from 'sonner'
-import { sleep } from '@/utils/sleep'
+import { sleep } from '@/lib/utils'
 import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
 import { Input } from '@/components/ui/input'
 import { Label } from '@/components/ui/label'

+ 0 - 0
src/utils/handle-server-error.ts → src/lib/handle-server-error.ts


+ 0 - 0
src/utils/show-submitted-data.tsx → src/lib/show-submitted-data.tsx


+ 4 - 0
src/lib/utils.ts

@@ -5,6 +5,10 @@ export function cn(...inputs: ClassValue[]) {
   return twMerge(clsx(inputs))
 }
 
+export function sleep(ms: number = 1000) {
+  return new Promise((resolve) => setTimeout(resolve, ms))
+}
+
 /**
  * Generates page numbers for pagination with ellipsis
  * @param currentPage - Current page number (1-based)

+ 1 - 1
src/main.tsx

@@ -9,7 +9,7 @@ import {
 import { RouterProvider, createRouter } from '@tanstack/react-router'
 import { toast } from 'sonner'
 import { useAuthStore } from '@/stores/auth-store'
-import { handleServerError } from '@/utils/handle-server-error'
+import { handleServerError } from '@/lib/handle-server-error'
 import { DirectionProvider } from './context/direction-provider'
 import { FontProvider } from './context/font-provider'
 import { ThemeProvider } from './context/theme-provider'

+ 0 - 8
src/utils/sleep.ts

@@ -1,8 +0,0 @@
-/**
- * A simple promise that resolves after a given delay.
- * @param {number} ms The delay in milliseconds.
- * @returns {Promise<void>} A promise that resolves after the delay.
- */
-export const sleep = (ms: number = 1000): Promise<void> => {
-  return new Promise((resolve) => setTimeout(resolve, ms))
-}