Ensure all users can view relevant data by filtering it by their selected store

Fix data fetching logic to correctly apply store filtering for all user roles, and add an alert for managers/directors if no store is selected.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 15f19c36-9aac-46a4-a181-3dc5f496fabd
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/15f19c36-9aac-46a4-a181-3dc5f496fabd/H1nJA1b
This commit is contained in:
michaelschal committed 2025-08-20 08:58:29 +00:00
1 parent 46de48f459
commit 20efd9251e
4 files changed
+53 -9

No files matched your search

+2 -1
View File
@@ -71,7 +71,8 @@ export default function Deliveries() {
const [deliveryToDelete, setDeliveryToDelete] = useState<DeliveryWithRelations | null>(null);
// Construire l'URL pour l'historique complet sans filtrage par date
const deliveriesUrl = `/api/deliveries${selectedStoreId && user?.role === 'admin' ? `?storeId=${selectedStoreId}` : ''}`;
// CRITICAL FIX: Appliquer le filtrage par storeId pour TOUS les rôles, pas seulement admin
const deliveriesUrl = `/api/deliveries${selectedStoreId ? `?storeId=${selectedStoreId}` : ''}`;
const { data: deliveriesData = [], isLoading } = useQuery<DeliveryWithRelations[]>({
queryKey: ['/api/deliveries', selectedStoreId, user?.role],
+2 -1
View File
@@ -69,7 +69,8 @@ export default function Orders() {
const [orderToDelete, setOrderToDelete] = useState<OrderWithRelations | null>(null);
// Construire l'URL pour l'historique complet sans filtrage par date
const ordersUrl = `/api/orders${selectedStoreId && user?.role === 'admin' ? `?storeId=${selectedStoreId}` : ''}`;
// CRITICAL FIX: Appliquer le filtrage par storeId pour TOUS les rôles, pas seulement admin
const ordersUrl = `/api/orders${selectedStoreId ? `?storeId=${selectedStoreId}` : ''}`;
const { data: ordersData = [], isLoading } = useQuery<OrderWithRelations[]>({
queryKey: [ordersUrl, selectedStoreId],
+4 -2
View File
@@ -339,14 +339,16 @@ export default function Tasks() {
queryFn: async () => {
try {
const params = new URLSearchParams();
if (selectedStoreId && user?.role === 'admin') {
// CRITICAL FIX: Appliquer le filtrage par storeId pour TOUS les rôles, pas seulement admin
if (selectedStoreId) {
params.append('storeId', selectedStoreId.toString());
}
console.log('📋 TASKS QUERY - Fetching with params:', {
selectedStoreId,
userRole: user?.role,
storeInitialized,
url: `/api/tasks?${params.toString()}`
url: `/api/tasks?${params.toString()}`,
willFilterByStore: !!selectedStoreId
});
const response = await fetch(`/api/tasks?${params.toString()}`, {