diff --git a/apps/web/src/api/services/inventory-movements-service.ts b/apps/web/src/api/services/inventory-movements-service.ts index c1ac1d97..5d9d9205 100644 --- a/apps/web/src/api/services/inventory-movements-service.ts +++ b/apps/web/src/api/services/inventory-movements-service.ts @@ -18,10 +18,11 @@ export const InventoryMovementsService = ( return await apiClient.post('/inventory-movements/outbound', movement.dto) }, - async listInventoryMovements({ page, productId,movementType }) { + async listInventoryMovements({ page, productId, movementType, responsibleId }) { apiClient.setParam('page', String(page)) apiClient.setParam('productId', productId || '') - apiClient.setParam('movementType',String(movementType)) + apiClient.setParam('responsibleId', String(responsibleId)) + apiClient.setParam('movementType', String(movementType)) return await apiClient.get>( '/inventory-movements', ) diff --git a/apps/web/src/api/services/users-service.ts b/apps/web/src/api/services/users-service.ts index b79d1bc0..e4ed647d 100644 --- a/apps/web/src/api/services/users-service.ts +++ b/apps/web/src/api/services/users-service.ts @@ -14,7 +14,9 @@ export const UsersService = (apiClient: IApiClient): IUsersService => { }, async listUsers({ page, name, role }) { - apiClient.setParam('name', String(name)) + if (name) { + apiClient.setParam('name', String(name)) + } apiClient.setParam('role', String(role)) apiClient.setParam('page', String(page)) return await apiClient.get>('/users') diff --git a/apps/web/src/ui/components/commons/employee-select/index.tsx b/apps/web/src/ui/components/commons/employee-select/index.tsx new file mode 100644 index 00000000..a9f8a962 --- /dev/null +++ b/apps/web/src/ui/components/commons/employee-select/index.tsx @@ -0,0 +1,91 @@ +import { Button, Pagination, Spinner } from '@nextui-org/react' +import { useEmployeeSelect } from './use-employee-select' +import { Dialog } from '../dialog' +import { Icon } from '../icon' +import { Select } from '../select' + +type EmployeeSelectProps = { + onSelectChange: (employeeId: string) => void +} + +export const EmployeeSelect = ({ onSelectChange }: EmployeeSelectProps) => { + const { + employees, + isFetching, + page, + totalPages, + handleEmployeeIdchange, + handleEmployeePageChange, + selectedEmployeeName, + handleEmployeeNamechange, + } = useEmployeeSelect(onSelectChange) + + return isFetching ? ( + + ) : ( +
+ + {selectedEmployeeName ? selectedEmployeeName : 'Selecione o funcionario'} + + } + > + {(closeDrawer) => + employees.length === 0 ? ( +

+ Nenhum funcionário encontrado +

+ ) : ( + <> +
+ {employees.map((employee) => ( +
+ {employee.name} + +
+ ))} +
+ {totalPages > 1 && ( + + )} + + ) + } +
+ {selectedEmployeeName && ( + + )} +
+ ) +} diff --git a/apps/web/src/ui/components/commons/employee-select/use-employee-select.ts b/apps/web/src/ui/components/commons/employee-select/use-employee-select.ts new file mode 100644 index 00000000..68fad9c6 --- /dev/null +++ b/apps/web/src/ui/components/commons/employee-select/use-employee-select.ts @@ -0,0 +1,54 @@ +import { useApi, useCache, useToast, useUrlParamNumber } from '@/ui/hooks' +import { useState } from 'react' +import { useAuthContext } from '../../contexts/auth-context' +import { CACHE } from '@/constants' +import { User } from '@stocker/core/entities' + +export function useEmployeeSelect(onSelectChange: (employeeId: string) => void) { + const [employeeId, setEmployeeId] = useState() + const [selectedEmployeeName,setSelectedEmployeeName] = useState() + const { usersService } = useApi() + const { company } = useAuthContext() + const { showError } = useToast() + const [page, setPage] = useUrlParamNumber('employeePage', 1) + function handleEmployeeIdchange(employeeId: string) { + setEmployeeId(employeeId) + onSelectChange(employeeId) + } + function handleEmployeeNamechange(name:string){ + setSelectedEmployeeName(name) + } + async function fetchEmployees() { + if (!company) return + const response = await usersService.listUsers({ + page, + companyId: company.id, + }) + if (response.isFailure) { + showError(response.errorMessage) + return + } + return response.body + } + const { data, refetch, isFetching } = useCache({ + fetcher: fetchEmployees, + key: CACHE.users.key, + dependencies: [page], + }) + function handlePagechange(page:number){ + setPage(page) + } + console.log(data) + const employees = data ? data.items : [] + const itemsCount = data ? data.itemsCount : 0 + return { + isFetching, + totalPages: Math.ceil(itemsCount / 10), + page, + employees, + handleEmployeeIdchange, + handleEmployeePageChange: handlePagechange, + handleEmployeeNamechange, + selectedEmployeeName + } +} diff --git a/apps/web/src/ui/components/pages/inventory-movements/index.tsx b/apps/web/src/ui/components/pages/inventory-movements/index.tsx index ef5988d2..33644c9b 100644 --- a/apps/web/src/ui/components/pages/inventory-movements/index.tsx +++ b/apps/web/src/ui/components/pages/inventory-movements/index.tsx @@ -2,28 +2,47 @@ import { Select, SelectItem } from '@nextui-org/react' import { InventoryMovementsTable } from './inventory-movements-table' import { useInventoryMovementPage } from './use-inventory-moviments-page' +import { EmployeeSelect } from '../../commons/employee-select' export const InventoryMovementsPage = () => { - const { isFetching, page, movements, totalPages, handlePageChange,handleMovementTypeSearchChange,movementTypeSearch } = - useInventoryMovementPage() + const { + handleEmployeeIdSerachChange, + employeeIdSearch, + isFetching, + page, + movements, + totalPages, + handlePageChange, + handleMovementTypeSearchChange, + movementTypeSearch, + } = useInventoryMovementPage() return ( <>
-
+

Lançamentos

- +
+ + +