base con autenticacion, registro, modulo encuestas
This commit is contained in:
46
apps/web/hooks/use-breadcrumbs.tsx
Normal file
46
apps/web/hooks/use-breadcrumbs.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
'use client';
|
||||
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
type BreadcrumbItem = {
|
||||
title: string;
|
||||
link: string;
|
||||
};
|
||||
|
||||
// This allows to add custom title as well
|
||||
const routeMapping: Record<string, BreadcrumbItem[]> = {
|
||||
'/dashboard': [{ title: 'Dashboard', link: '/dashboard' }],
|
||||
'/dashboard/employee': [
|
||||
{ title: 'Dashboard', link: '/dashboard' },
|
||||
{ title: 'Employee', link: '/dashboard/employee' }
|
||||
],
|
||||
'/dashboard/product': [
|
||||
{ title: 'Dashboard', link: '/dashboard' },
|
||||
{ title: 'Product', link: '/dashboard/product' }
|
||||
]
|
||||
// Add more custom mappings as needed
|
||||
};
|
||||
|
||||
export function useBreadcrumbs() {
|
||||
const pathname = usePathname();
|
||||
|
||||
const breadcrumbs = useMemo(() => {
|
||||
// Check if we have a custom mapping for this exact path
|
||||
if (routeMapping[pathname]) {
|
||||
return routeMapping[pathname];
|
||||
}
|
||||
|
||||
// If no exact match, fall back to generating breadcrumbs from the path
|
||||
const segments = pathname.split('/').filter(Boolean);
|
||||
return segments.map((segment, index) => {
|
||||
const path = `/${segments.slice(0, index + 1).join('/')}`;
|
||||
return {
|
||||
title: segment.charAt(0).toUpperCase() + segment.slice(1),
|
||||
link: path
|
||||
};
|
||||
});
|
||||
}, [pathname]);
|
||||
|
||||
return breadcrumbs;
|
||||
}
|
||||
19
apps/web/hooks/use-mobile.ts
Normal file
19
apps/web/hooks/use-mobile.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from "react"
|
||||
|
||||
const MOBILE_BREAKPOINT = 768
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [])
|
||||
|
||||
return !!isMobile
|
||||
}
|
||||
13
apps/web/hooks/use-safe-query.ts
Normal file
13
apps/web/hooks/use-safe-query.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { UseQueryOptions, useQuery } from '@tanstack/react-query'
|
||||
|
||||
export function useSafeQuery<T, K = unknown>(
|
||||
queryKey: [string, K?],
|
||||
queryFn: () => Promise<T>,
|
||||
options?: Omit<UseQueryOptions<T>, 'queryKey' | 'queryFn'>
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey,
|
||||
queryFn,
|
||||
...options,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user