Enable store selection for admins and associate sales with specific stores

Implements store selection and association functionality using useStoreContext hook and updates sale creation and retrieval APIs.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 91318273-c764-4fd4-be04-bdc12c38af32
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/d304bad8-e4eb-4558-b9d6-38704ba052e8.jpg
This commit is contained in:
michaelschal committed 2025-07-09 19:04:37 +00:00
1 parent a5336a5919
commit 4384818f63
5 files changed
+216 -7

No files matched your search

+11 -1
View File
@@ -8,6 +8,8 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { useToast } from '@/hooks/use-toast';
import { useAuth } from '@/hooks/useAuth';
import { useStoreContext } from '@/hooks/useStoreContext';
import { apiRequest } from '@/lib/queryClient';
import { validateRequiredFields, validateEAN13, ARTICLE_CATEGORY_MAPPING, IDENTITY_TYPES } from '@/lib/validation';
import { Package, User, Users, Save, X } from 'lucide-react';
@@ -32,6 +34,8 @@ interface FormData {
export default function NewSaleForm() {
const { toast } = useToast();
const queryClient = useQueryClient();
const { user } = useAuth();
const { selectedStoreId } = useStoreContext();
const [isSubmitting, setIsSubmitting] = useState(false);
const form = useForm<FormData>({
@@ -58,9 +62,15 @@ export default function NewSaleForm() {
const createSaleMutation = useMutation({
mutationFn: async (saleData: any) => {
const dataToSend = {
...saleData,
// Include storeId for admin users
...(user?.role === 'admin' && selectedStoreId && { storeId: selectedStoreId })
};
const response = await apiRequest('/api/sales', {
method: 'POST',
body: JSON.stringify(saleData),
body: JSON.stringify(dataToSend),
});
return response.json();
},