From ef91e5027645afbea719c637a32ac5ab63524312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Carvalho?= Date: Mon, 2 Dec 2024 17:31:07 +0000 Subject: [PATCH] =?UTF-8?q?[front]=20=F0=9F=92=84=20styles:=20enchance=20s?= =?UTF-8?q?ite=20responsive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/prisma-locations-repository.ts | 4 ---- .../employee-select/use-employee-select.ts | 11 ++++++++--- .../hooks/use-auth-context-provider.ts | 4 ++-- .../navbar-user/notifications-dialog/index.tsx | 6 ++++-- .../notification-card/index.tsx | 3 +++ .../inventory-movements-table/index.tsx | 8 +++++--- .../ui/components/pages/product-stock/index.tsx | 16 +++++++++++++--- .../inventory-movements-table/index.tsx | 10 +++++++--- .../web/src/ui/components/pages/stocks/index.tsx | 2 +- .../src/ui/components/pages/suppliers/index.tsx | 13 +++++++++---- .../suppliers/register-supplier-form/index.tsx | 8 +------- .../pages/suppliers/suppliers-table/index.tsx | 16 ++++++++++++---- .../pages/suppliers/use-suppliers-page.ts | 6 ++---- apps/web/src/ui/hooks/use-cache.ts | 6 ++++++ 14 files changed, 73 insertions(+), 40 deletions(-) diff --git a/apps/server/src/database/prisma/repositories/prisma-locations-repository.ts b/apps/server/src/database/prisma/repositories/prisma-locations-repository.ts index 5b0d3dec..3e010bf4 100644 --- a/apps/server/src/database/prisma/repositories/prisma-locations-repository.ts +++ b/apps/server/src/database/prisma/repositories/prisma-locations-repository.ts @@ -68,8 +68,6 @@ export class PrismaLocationsRepository implements ILocationsRepository { async findById(locationId: string): Promise { try { - console.log(await prisma.location.findMany()) - console.log('locationId', locationId) const prismaLocation = await prisma.location.findUnique({ where: { id: locationId, @@ -79,8 +77,6 @@ export class PrismaLocationsRepository implements ILocationsRepository { }, }) - console.log({ prismaLocation }) - if (!prismaLocation) return null return this.mapper.toDomain(prismaLocation) } catch (error) { 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 index 859c4d9a..9347be98 100644 --- 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 @@ -2,7 +2,6 @@ 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() @@ -11,44 +10,50 @@ export function useEmployeeSelect(onSelectChange: (employeeId: string) => void) 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, }) - console.log(response) if (response.isFailure) { showError(response.errorMessage) return } return response.body } + const { data, isFetching } = useCache({ fetcher: fetchEmployees, key: CACHE.users.key, dependencies: [page], }) + function handlePagechange(page: number) { setPage(page) } + const employees = data ? data.items : [] const itemsCount = data ? data.itemsCount : 0 + return { isFetching, totalPages: Math.ceil(itemsCount / 10), page, employees, + selectedEmployeeName, handleEmployeeIdchange, handleEmployeePageChange: handlePagechange, handleEmployeeNamechange, - selectedEmployeeName, } } diff --git a/apps/web/src/ui/components/contexts/auth-context/hooks/use-auth-context-provider.ts b/apps/web/src/ui/components/contexts/auth-context/hooks/use-auth-context-provider.ts index 62f3e0b9..1bffc42e 100644 --- a/apps/web/src/ui/components/contexts/auth-context/hooks/use-auth-context-provider.ts +++ b/apps/web/src/ui/components/contexts/auth-context/hooks/use-auth-context-provider.ts @@ -66,7 +66,7 @@ export function useAuthContextProvider({ const company = comapanyDto ? Company.create(comapanyDto) : null - const { data: userRole } = useCache({ + const { data: userRole, clearCache: clearUserRoleCache } = useCache({ fetcher: fetchPermissions, key: CACHE.permissions.key, }) @@ -122,6 +122,7 @@ export function useAuthContextProvider({ async function logout() { setUser(null) navigateTo(ROUTES.login) + clearUserRoleCache() setTimeout(async () => { await deleteCookieAction(COOKIES.jwt.key) }, 2500) @@ -209,7 +210,6 @@ export function useAuthContextProvider({ if (jwt) logoutUnkownAccount(jwt) } - return { user, company, diff --git a/apps/web/src/ui/components/layouts/dashboard/navbar/navbar-user/notifications-dialog/index.tsx b/apps/web/src/ui/components/layouts/dashboard/navbar/navbar-user/notifications-dialog/index.tsx index bb43b73c..94a18cf3 100644 --- a/apps/web/src/ui/components/layouts/dashboard/navbar/navbar-user/notifications-dialog/index.tsx +++ b/apps/web/src/ui/components/layouts/dashboard/navbar/navbar-user/notifications-dialog/index.tsx @@ -59,7 +59,8 @@ export const NotifcationsDialog = ({ companyId }: NotifcationsDialogProps) => { id={stockNotification.id} href={`/inventory/stocks/${stockNotification.product.id}`} icon='product' - title={`${stockNotification.product.name} | estoque atual: ${stockNotification.product.currentStock}`} + title={stockNotification.product.name} + subtitle={`estoque atual: ${stockNotification.product.currentStock} | estoque mínimo: ${stockNotification.product.minimumStock}`} sentAt={stockNotification.sentAt ?? new Date()} onDelete={handleDeleteNotification} /> @@ -95,7 +96,8 @@ export const NotifcationsDialog = ({ companyId }: NotifcationsDialogProps) => { id={expirationDateNotification.id} href={`/inventory/stocks/${expirationDateNotification.id}`} icon='batch' - title={`${expirationDateNotification.batch.code} | dias até expiração: ${expirationDateNotification.batch.daysToExpiration}`} + title={`Código do lote: ${expirationDateNotification.batch.code}`} + subtitle={`dias até expiração: ${expirationDateNotification.batch.daysToExpiration}`} sentAt={expirationDateNotification.sentAt ?? new Date()} onDelete={handleDeleteNotification} /> diff --git a/apps/web/src/ui/components/layouts/dashboard/navbar/navbar-user/notifications-dialog/notification-card/index.tsx b/apps/web/src/ui/components/layouts/dashboard/navbar/navbar-user/notifications-dialog/notification-card/index.tsx index 227f7650..9cf376f0 100644 --- a/apps/web/src/ui/components/layouts/dashboard/navbar/navbar-user/notifications-dialog/notification-card/index.tsx +++ b/apps/web/src/ui/components/layouts/dashboard/navbar/navbar-user/notifications-dialog/notification-card/index.tsx @@ -10,6 +10,7 @@ import Link from 'next/link' type NotificationCardProps = { id: string title: string + subtitle: string href: string icon: IconName sentAt: Date @@ -19,6 +20,7 @@ type NotificationCardProps = { export const NotificationCard = ({ id, title, + subtitle, icon, sentAt, href, @@ -39,6 +41,7 @@ export const NotificationCard = ({ -

{title}

+

{subtitle}

{userRole?.hasPermission('inventory-movements') && ( -
+
}> + } @@ -82,7 +87,12 @@ export const ProductStockPage = ({ productDto }: ProductStockPageProps) => { }> + } diff --git a/apps/web/src/ui/components/pages/product-stock/inventory-movements-table/index.tsx b/apps/web/src/ui/components/pages/product-stock/inventory-movements-table/index.tsx index a8f19cba..27caf33c 100644 --- a/apps/web/src/ui/components/pages/product-stock/inventory-movements-table/index.tsx +++ b/apps/web/src/ui/components/pages/product-stock/inventory-movements-table/index.tsx @@ -70,7 +70,7 @@ export const InventoryMovementsTable = ({ items={inventoryMovements} emptyContent='Nenhum lançamento registrado para esse produto' isLoading={isLoading} - loadingContent={} + loadingContent={} > {(item) => ( @@ -81,8 +81,12 @@ export const InventoryMovementsTable = ({ {item.movementType === 'inbound' ? 'Entrada' : 'Saída'} {item.itemsCount} - {item.responsible.name} - {item.remark ?? 'N/A'} + + {item.responsible?.name} + + + {item.remark ?? 'N/A'} + )} diff --git a/apps/web/src/ui/components/pages/stocks/index.tsx b/apps/web/src/ui/components/pages/stocks/index.tsx index f027c9d3..838ca425 100644 --- a/apps/web/src/ui/components/pages/stocks/index.tsx +++ b/apps/web/src/ui/components/pages/stocks/index.tsx @@ -152,7 +152,7 @@ export const StocksPage = () => { - {product.name} + {product.name} {product.batchesCount} diff --git a/apps/web/src/ui/components/pages/suppliers/index.tsx b/apps/web/src/ui/components/pages/suppliers/index.tsx index a3284d42..969dad44 100644 --- a/apps/web/src/ui/components/pages/suppliers/index.tsx +++ b/apps/web/src/ui/components/pages/suppliers/index.tsx @@ -17,13 +17,13 @@ export const SuppliersPage = () => { isDeleting, selectedSuppliersIds, isLoading, + nameSearchValue, handleRegisterSupplierFormSubmit, handleUpdateSupplier, handleSuppliersSelectionChange, handlePageChange, handleDeleteSuppliersAlertDialogConfirm, - nameSearchValue, - handleNameSearchChange + handleNameSearchChange, } = useSuppliersPage() return ( <> @@ -33,7 +33,7 @@ export const SuppliersPage = () => {

Fornecedores

-
+
{selectedSuppliersIds.length > 0 && ( { )} + } diff --git a/apps/web/src/ui/components/pages/suppliers/register-supplier-form/index.tsx b/apps/web/src/ui/components/pages/suppliers/register-supplier-form/index.tsx index 1611cf77..1a978b67 100644 --- a/apps/web/src/ui/components/pages/suppliers/register-supplier-form/index.tsx +++ b/apps/web/src/ui/components/pages/suppliers/register-supplier-form/index.tsx @@ -36,14 +36,12 @@ export const RegisterSupplierForm = ({ /> Cancelar -
diff --git a/apps/web/src/ui/components/pages/suppliers/suppliers-table/index.tsx b/apps/web/src/ui/components/pages/suppliers/suppliers-table/index.tsx index 38b291c1..87c7960b 100644 --- a/apps/web/src/ui/components/pages/suppliers/suppliers-table/index.tsx +++ b/apps/web/src/ui/components/pages/suppliers/suppliers-table/index.tsx @@ -93,10 +93,18 @@ export const SuppliersTable = ({ > {(supplier) => ( - {supplier.name} - {supplier.email} - {supplier.cnpj} - {supplier.phone} + + {supplier.name} + + + {supplier.email} + + + {supplier.cnpj} + + + {supplier.phone} + = { isRefetching: boolean refetch: () => void mutate: (newCacheData: CacheData | null, consig?: MudateConfig) => void + clearCache: VoidFunction } export function useCache({ @@ -56,6 +57,10 @@ export function useCache({ ) } + function clearCache() { + mutate(undefined) + } + return { data: data ?? null, error, @@ -63,5 +68,6 @@ export function useCache({ isRefetching: isValidating, refetch: () => mutate(), mutate: mutateCache, + clearCache, } }