Skip to content

Commit

Permalink
refactoring types
Browse files Browse the repository at this point in the history
  • Loading branch information
athens-server committed Jan 28, 2025
1 parent a4d2ed8 commit 87fdd41
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useDialogHandlers } from '@/views/user-management/components/dialogs/hooks'
import { DialogLabels } from '@/views/user-management/types'
import { IDialogsProps } from '@views/user-management/components/dialogs/types'
import { DialogLabels, IDialogsProps } from '@/views/user-management/components/dialogs/types'
import { useDialogs } from '@views/user-management/providers/DialogsProvider'

import { CreateUserDialog } from './components/create-user'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DialogLabels, IDialogHandlers } from '@/views/user-management/types'
import { DialogLabels, IDialogHandlers } from '@/views/user-management/components/dialogs'
import { useDialogs } from '@views/user-management/providers/DialogsProvider'

export const useDialogHandlers = (handlers: IDialogHandlers) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './dialogs'
export * from './types'
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
import { IDialogErrorStates, IDialogHandlers, IDialogLoadingStates } from '@views/user-management/types'
export interface IDialogHandlers {
handleUpdateUser: (data: { email: string; displayName: string; userID: string }) => void
handleDeleteUser: (userUid: string) => void
handleUpdateUserAdmin: (userUid: string, isAdmin: boolean) => void
handleUpdatePassword: (userId: string) => void
handleCreateUser: (data: { uid: string; email: string; display_name: string }) => void
}

export interface IDialogLoadingStates {
isUpdatingUser: boolean
isDeletingUser: boolean
isUpdatingUserAdmin: boolean
isCreatingUser: boolean
}

export interface IDialogErrorStates {
updateUserError: string
deleteUserError: string
updateUserAdminError: string
createUserError: string
}

export enum DialogLabels {
DELETE_USER = 'deleteUser',
EDIT_USER = 'editUser',
TOGGLE_ADMIN = 'toggleAdmin',
RESET_PASSWORD = 'resetPassword',
CREATE_USER = 'createUser'
}

export interface IDialogsProps {
handlers: IDialogHandlers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Filters, ListActions, SearchBox } from '@/components'
import { DialogLabels } from '@/views/user-management/components/dialogs'
import { ActionsProps } from '@/views/user-management/components/page-components/actions/types'
import { DialogLabels } from '@/views/user-management/types'

export const Actions = ({
searchQuery,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DialogLabels, UsersProps } from '@views/user-management/types'
import { DialogLabels } from '@/views/user-management/components/dialogs'
import { UsersProps } from '@/views/user-management/types'

export interface PageProps {
users: UsersProps[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
Text
} from '@/components'
import { getInitials } from '@/utils/utils'
import { DialogLabels } from '@/views/user-management/components/dialogs'
import { PageProps } from '@/views/user-management/components/page-components/content/components/users-list/types'
import { DialogLabels } from '@/views/user-management/types'

export const UsersList = ({ users, handleDialogOpen }: PageProps) => {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { FiltersBar, PaginationComponent, Spacer } from '@/components'
import { generateAlphaNumericHash } from '@/utils/utils'
import { SandboxLayout } from '@/views'
import { DialogLabels } from '@/views/user-management/components/dialogs'
import { EmptyState } from '@/views/user-management/components/empty-state'
import { Actions } from '@/views/user-management/components/page-components/actions'
import { UsersList } from '@/views/user-management/components/page-components/content/components/users-list'
import { ContentProps } from '@/views/user-management/components/page-components/content/types'
import { Header } from '@/views/user-management/components/page-components/header'
import { DialogLabels, UsersProps } from '@/views/user-management/types'
import { UsersProps } from '@/views/user-management/types'
import { getFilterOptions, getSortDirections, getSortOptions } from '@views/repo/constants/filter-options'
import { useFilters } from '@views/repo/hooks'
import { useDialogs } from '@views/user-management/providers/DialogsProvider'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Tabs, TabsList, TabsTrigger } from '@/components'
import { SandboxLayout } from '@/views'
import { EActiveTab } from '@/views/user-management/types'

import { useUserManagementStore } from '../../providers/StoreProvider'
import { EActiveTab } from '@/views/user-management/components/tabs/types'
import { useUserManagementStore } from '@/views/user-management/providers/StoreProvider'

export const UserManagementTabs = ({
activeTab,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum EActiveTab {
ACTIVE = 'active',
INACTIVE = 'inactive'
}
3 changes: 3 additions & 0 deletions packages/ui/src/views/user-management/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export * from './user-management-page'
export * from './types'
export * from './components/dialogs/types'
export * from './components/tabs/types'
export * from './providers/StoreProvider/types'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext, useState } from 'react'

import { DialogLabels } from '@/views/user-management/types'
import { DialogLabels } from '@/views/user-management/components/dialogs'

import { DialogsContextType, DialogState } from './types'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DialogLabels } from '@/views/user-management/types'
import { DialogLabels } from '@/views/user-management/components/dialogs'

export type DialogState = {
[K in DialogLabels]: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './hooks/useUserManagementStore'
export * from './StoreProvider'
export * from './types'
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import { TranslationStore } from '@/views'
import { IAdminListUsersStore } from '@views/user-management/types'
import { EActiveTab, TranslationStore, UsersProps } from '@/views'

export interface IAdminListUsersStore {
users: UsersProps[]
totalPages: number
page: number
password: string | null
user: UsersProps | null
searchQuery: string
activeTab: EActiveTab
generatePassword: boolean
setSearchQuery: (searchQuery: string) => void
setPassword: (password: string) => void
setUser: (user: UsersProps) => void
setPage: (data: number) => void
setUsers: (data: UsersProps[]) => void
setTotalPages: (data: Headers) => void
setGeteneratePassword: (data: boolean) => void
setActiveTab: (data: EActiveTab) => void
}

export interface StoreProviderProps {
useAdminListUsersStore: () => IAdminListUsersStore
Expand Down
55 changes: 2 additions & 53 deletions packages/ui/src/views/user-management/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { TranslationStore } from '@/views'
import { IDialogErrorStates, IDialogHandlers, IDialogLoadingStates } from '@/views/user-management/components/dialogs'
import { IAdminListUsersStore } from '@/views/user-management/providers/StoreProvider'

export interface UsersProps {
admin?: boolean
Expand All @@ -11,63 +13,10 @@ export interface UsersProps {
blocked?: boolean
}

export interface IDialogHandlers {
handleUpdateUser: (data: { email: string; displayName: string; userID: string }) => void
handleDeleteUser: (userUid: string) => void
handleUpdateUserAdmin: (userUid: string, isAdmin: boolean) => void
handleUpdatePassword: (userId: string) => void
handleCreateUser: (data: { uid: string; email: string; display_name: string }) => void
}

export interface IDialogLoadingStates {
isUpdatingUser: boolean
isDeletingUser: boolean
isUpdatingUserAdmin: boolean
isCreatingUser: boolean
}

export interface IDialogErrorStates {
updateUserError: string
deleteUserError: string
updateUserAdminError: string
createUserError: string
}

export interface IUserManagementPageProps {
useAdminListUsersStore: () => IAdminListUsersStore
useTranslationStore: () => TranslationStore
handlers: IDialogHandlers
loadingStates: IDialogLoadingStates
errorStates: IDialogErrorStates
}
export interface IAdminListUsersStore {
users: UsersProps[]
totalPages: number
page: number
password: string | null
user: UsersProps | null
searchQuery: string
activeTab: EActiveTab
generatePassword: boolean
setSearchQuery: (searchQuery: string) => void
setPassword: (password: string) => void
setUser: (user: UsersProps) => void
setPage: (data: number) => void
setUsers: (data: UsersProps[]) => void
setTotalPages: (data: Headers) => void
setGeteneratePassword: (data: boolean) => void
setActiveTab: (data: EActiveTab) => void
}

export enum DialogLabels {
DELETE_USER = 'deleteUser',
EDIT_USER = 'editUser',
TOGGLE_ADMIN = 'toggleAdmin',
RESET_PASSWORD = 'resetPassword',
CREATE_USER = 'createUser'
}

export enum EActiveTab {
ACTIVE = 'active',
INACTIVE = 'inactive'
}

0 comments on commit 87fdd41

Please sign in to comment.