Skip to content

Commit

Permalink
[front] 🐛 fix: stocks page responsive
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnPetros committed Dec 1, 2024
1 parent 7064877 commit 8ca81f1
Show file tree
Hide file tree
Showing 35 changed files with 191 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { productsRepository } from '@/database'
export class RegisterProductController {
async handle(http: IHttp) {
const productDto = http.getBody<ProductDto>()
console.log(productDto)
const useCase = new RegisterProductUseCase(productsRepository)
const productId = await useCase.execute({ productDto })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export class ListSuppliersController {
const { page, name } = http.getQueryParams<RouteParams>()
const pageNumber = parseInt(page || '1', 10)

console.log({ name })

const useCase = new ListSuplliersUseCase(suppliersRepository)
const response = await useCase.execute({
page: pageNumber,
Expand Down
2 changes: 0 additions & 2 deletions apps/server/src/app/fastify/fastify-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export class FastifyHttp implements IHttp {
): unknown {
this.reply.header('Content-Type', HTTP_CONTENT_TYPE[contentType])
this.reply.header('Content-Disposition', `attachment; filename="${filename}"`)

console.log('que?')
return this.reply.status(statusCode).send(file)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export class PrismaLocationsRepository implements ILocationsRepository {
},
orderBy: { registered_at: 'desc' },
})
console.log(prismaLocations)
const count = await prisma.location.count({
where: {
...(name && { name: { contains: name, mode: 'insensitive' } }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,17 @@ export class PrismaProductsRepository implements IProductsRepository {
companyId,
categoryId,
locationId,
name,
productName,
supplierId,
stockLevel,
}: ProducsStocksListParams) {
try {
console.log(name)
const prismaProducts = await prisma.product.findMany({
take: PAGINATION.itemsPerPage,
skip: page > 0 ? (page - 1) * PAGINATION.itemsPerPage : 1,
where: {
company_id: companyId,
...(name && { name: { contains: name, mode: 'insensitive' } }),
...(productName && { name: { contains: productName, mode: 'insensitive' } }),
...(categoryId && { category_id: categoryId }),
...(locationId && { location_id: locationId }),
...(supplierId && { supplier_id: supplierId }),
Expand All @@ -240,7 +239,7 @@ export class PrismaProductsRepository implements IProductsRepository {
const count = await prisma.product.count({
where: {
company_id: companyId,
...(name && { name: { contains: name, mode: 'insensitive' } }),
...(productName && { name: { contains: productName, mode: 'insensitive' } }),
...(categoryId && { category_id: categoryId }),
...(locationId && { location_id: locationId }),
...(supplierId && { supplier_id: supplierId }),
Expand All @@ -262,7 +261,7 @@ export class PrismaProductsRepository implements IProductsRepository {
async findManyWithInventoryMovementsCount({
page,
companyId,
name,
productName,
categoryId,
stockLevel,
}: ProducsStocksListParams): Promise<{
Expand All @@ -280,8 +279,8 @@ export class PrismaProductsRepository implements IProductsRepository {

let whereSql = Prisma.sql`P.is_active = true AND P.company_id = ${companyId}`

if (name) {
whereSql = Prisma.sql`${whereSql} AND P.name ILIKE ${`%${name}%`}`
if (productName) {
whereSql = Prisma.sql`${whereSql} AND P.name ILIKE ${`%${productName}%`}`
}

if (categoryId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Supplier } from '@stocker/core/entities'
import type { ISuppliersRepository } from '@stocker/core/interfaces'
import type { PaginationResponse } from '@stocker/core/responses'
import type { SuppliersListParams } from '@stocker/core/types'
import { PrismaSuppliersMapper } from '../mappers'
import { prisma } from '../prisma-client'
Expand Down Expand Up @@ -139,8 +138,6 @@ export class PrismaSuppliersRepository implements ISuppliersRepository {
},
})

console.log({ page, name, companyId })

const suppliers = prismaSuppliers.map(this.mapper.toDomain)

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class GoogleAiProvider implements IAiProvider {

for await (const chunk of result.stream) {
const chunkText = chunk.text()
console.log(chunkText)
onGenerateChunk(chunkText)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class SupabaseFileStorageProvider implements IFileStorageProvider {
}

async delete(fileId: string): Promise<void> {
console.log({ fileId })
const filePath = fileId.split('stocker/')[1]
if (!filePath) {
throw new ValidationError('Storaged file not found')
Expand Down
16 changes: 13 additions & 3 deletions apps/web/src/api/services/reports-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,20 @@ export const ReportsService = (apiClient: IApiClient): IReportsService => {
return await apiClient.fetchBuffer('/reports/most-trending-products/csv')
},

async reportInventory({page,stockLevel,name}) {
async reportInventory({
page,
stockLevel,
productName,
categoryId,
locationId,
supplierId,
}) {
apiClient.setParam('page', String(page))
apiClient.setParam('stockLevel',String(stockLevel))
apiClient.setParam('name',String(name))
if (stockLevel) apiClient.setParam('stockLevel', stockLevel)
if (productName) apiClient.setParam('productName', productName)
if (categoryId) apiClient.setParam('categoryId', categoryId)
if (locationId) apiClient.setParam('locationId', locationId)
if (supplierId) apiClient.setParam('supplierId', supplierId)
return await apiClient.get<PaginationResponse<ProductDto>>('/reports/inventory')
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type PageProps = {

const Page = async ({ params }: PageProps) => {
const cookie = await getCookieAction(COOKIES.passwordResetToken.key)
console.log(cookie)
if (!cookie) return redirect(ROUTES.login)

const [token, email] = cookie.split('|')
Expand All @@ -21,8 +20,6 @@ const Page = async ({ params }: PageProps) => {
return redirect(ROUTES.login)
}

console.log(email)

return <ResetPasswordPage email={email} />
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
import { CACHE } from '@/constants'
import { useApi, useCache, useToast, useUrlParamNumber } from '@/ui/hooks'
import { useApi, useCache, useToast } from '@/ui/hooks'
import { Category } from '@stocker/core/entities'
import { useState } from 'react'
import { useAuthContext } from '../../contexts/auth-context'

export function useCategorySelect(
onSelectChange: (categoryId: string) => void,
defeaultSelectedCategoryId?: string,
) {
const [categoryId, setCategoryId] = useState(defeaultSelectedCategoryId)
const { categoriesService } = useApi()
const { company } = useAuthContext()
const { showError } = useToast()
const [page, setPage] = useState(1)
const [expandedItems, setExpandedItems] = useState<{ [key: string]: boolean }>({})
const { showError } = useToast()

function handleCategoryIdChange(categoryId: string) {
setCategoryId(categoryId)
onSelectChange(categoryId)
}

async function fetchCategories() {
if (!company) return

const response = await categoriesService.listCategories({
page,
companyId: company.id,
})
if (response.isFailure) {
showError(response.errorMessage)
Expand Down Expand Up @@ -53,6 +48,9 @@ export function useCategorySelect(

const categories = categoriesData ? categoriesData.items.map(Category.create) : []
const itemsCount = categoriesData ? categoriesData.itemsCount : 0

console.log(categoriesData)

return {
isFetching,
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { User } from '@stocker/core/entities'

export function useEmployeeSelect(onSelectChange: (employeeId: string) => void) {
const [employeeId, setEmployeeId] = useState<string>()
const [selectedEmployeeName,setSelectedEmployeeName] = useState<string>()
const [selectedEmployeeName, setSelectedEmployeeName] = useState<string>()
const { usersService } = useApi()
const { company } = useAuthContext()
const { showError } = useToast()
Expand All @@ -15,7 +15,7 @@ export function useEmployeeSelect(onSelectChange: (employeeId: string) => void)
setEmployeeId(employeeId)
onSelectChange(employeeId)
}
function handleEmployeeNamechange(name:string){
function handleEmployeeNamechange(name: string) {
setSelectedEmployeeName(name)
}
async function fetchEmployees() {
Expand All @@ -30,15 +30,14 @@ export function useEmployeeSelect(onSelectChange: (employeeId: string) => void)
}
return response.body
}
const { data, refetch, isFetching } = useCache({
const { data, isFetching } = useCache({
fetcher: fetchEmployees,
key: CACHE.users.key,
dependencies: [page],
})
function handlePagechange(page:number){
function handlePagechange(page: number) {
setPage(page)
}
console.log(data)
const employees = data ? data.items : []
const itemsCount = data ? data.itemsCount : 0
return {
Expand All @@ -49,6 +48,6 @@ export function useEmployeeSelect(onSelectChange: (employeeId: string) => void)
handleEmployeeIdchange,
handleEmployeePageChange: handlePagechange,
handleEmployeeNamechange,
selectedEmployeeName
selectedEmployeeName,
}
}
4 changes: 2 additions & 2 deletions apps/web/src/ui/components/commons/location-select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const LocationSelect = ({
) : (
<div className='space-y-2 flex gap-4 items-center'>
<Dialog
title='Selecione uma categoria ou subcategoria'
title='Selecione um local ou setor'
size='2xl'
trigger={
<Select className={className}>
Expand All @@ -48,7 +48,7 @@ export const LocationSelect = ({
<div className='flex flex-col h-[28rem] pb-6'>
{locations.length === 0 && (
<p className='text-center text-bg-zinc-600 font-semibold my-12'>
Nenhum setor cadastrado.
Nenhum local cadastrado.
</p>
)}
{locations.length > 0 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { useState } from 'react'
import { Location } from '@stocker/core/entities'

import { useApi, useCache, useToast } from '@/ui/hooks'
import { useAuthContext } from '../../contexts/auth-context'
import { CACHE } from '@/constants'

export function useLocationSelect(
onSelectChange: (locationId: string) => void,
defaultSelectedLocationId: string | undefined,
) {
const { locationsService } = useApi()
const { company } = useAuthContext()
const { showError } = useToast()
const [page, setPage] = useState(1)
const [locationId, setLocationId] = useState(defaultSelectedLocationId)
Expand All @@ -23,7 +21,6 @@ export function useLocationSelect(
}

async function fetchLocations() {
if (!company) return
const response = await locationsService.listLocations({
page,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { CACHE } from '@/constants'
import { useApi, useCache, useToast } from '@/ui/hooks'
import { Supplier } from '@stocker/core/entities'
import { useEffect, useState } from 'react'
import { useAuthContext } from '../../contexts/auth-context'
import { useState } from 'react'
import { PAGINATION } from '@stocker/core/constants'

export function useSupplierSelect(
onSelectChange: (supplierId: string) => void,
defaultSelectedSupplierId?: string,
) {
const { suppliersService } = useApi()
const { company } = useAuthContext()
const { showError } = useToast()
const [page, setPage] = useState(1)
const [supplierId, setSupplierId] = useState(defaultSelectedSupplierId)

async function fetchSuppliers() {
if (!company) return

const response = await suppliersService.listSuppliers({
page,
})
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/ui/components/layouts/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const DashboardLayout = ({ children }: DashboardLayoutProps) => {
return (
<>
<div>
<div className='p-3 md:hidden'>
<div className='p-3 lg:hidden'>
<Drawer
ref={drawerRef}
trigger={<IconButton name='menu-hamburguer' />}
Expand All @@ -31,12 +31,12 @@ export const DashboardLayout = ({ children }: DashboardLayoutProps) => {
{() => <Navbar />}
</Drawer>
</div>
<aside className='hidden md:block fixed w-52 left-0 top-0 bottom-0 h-screen px-3 py-6 border-r border-zinc-200'>
<aside className='hidden lg:block fixed w-52 left-0 top-0 bottom-0 h-screen px-3 py-6 border-r border-zinc-200'>
<Navbar />
</aside>
</div>

<main className='pl-6 md:pl-60 py-6 pr-6'>{children}</main>
<main className='pl-6 lg:pl-60 py-6 pr-6'>{children}</main>
{user?.hasFirstPasswordReset && <FirstEntryPasswordModal />}
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export function useAiReport(userId?: string) {
userId,
onGenerate: (chunk) => {
setIsAnalysing(false)
console.log(chunk)
setReport((report) => report.concat(chunk))
},
})
Expand Down
9 changes: 5 additions & 4 deletions apps/web/src/ui/components/pages/employees/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export const EmployeesPage = () => {
users,
selectedEmployeesIds,
isLoading,
nameSearchValue,
roleSearchValue,
handleRegisterEmployeeFormSubmit,
handleUpdateEmployee,
handleEmployeesSelectionChange,
handlePageChange,
handleDeleteEmployeesAlertDialogConfirm,
handleNameSearchChange,
nameSearchValue,
roleSearchValue,
handleRoleSearchChange,
} = useEmployeesPage()
return (
Expand All @@ -36,9 +36,10 @@ export const EmployeesPage = () => {
<div className=' flex md:items-center flex-col md:flex-row gap-4 w-full'>
<Search value={nameSearchValue} onSearchChange={handleNameSearchChange} />
<Select
className='max-w-96 '
className='max-w-96'
color='default'
size='lg'
size='md'
label='Cargo'
defaultSelectedKeys={['']}
value={roleSearchValue}
onChange={(e) => handleRoleSearchChange(e.target.value)}
Expand Down
Loading

0 comments on commit 8ca81f1

Please sign in to comment.