mirror of
https://github.com/R0m1k3/Regisflow.git
synced 2026-10-11 17:29:48 +02:00
Improve data fetching and handling for sales information on the platform
Updates `useQuery` hooks to explicitly parse JSON responses for sales data. 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/ab880d72-1a34-4d36-b5be-9f44df85ed1a.jpg
This commit is contained in:
1 parent
b1835987f9
commit
462ebeb816
3 files changed
+11
-6
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
@@ -57,11 +57,13 @@ export default function NewSaleForm() {
|
||||
const availableCategories = typeArticle ? ARTICLE_CATEGORY_MAPPING[typeArticle as keyof typeof ARTICLE_CATEGORY_MAPPING] || [] : [];
|
||||
|
||||
const createSaleMutation = useMutation({
|
||||
mutationFn: (saleData: any) =>
|
||||
apiRequest('/api/sales', {
|
||||
mutationFn: async (saleData: any) => {
|
||||
const response = await apiRequest('/api/sales', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(saleData),
|
||||
}),
|
||||
});
|
||||
return response.json();
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['/api/sales'] });
|
||||
toast({
|
||||
|
||||
@@ -22,17 +22,20 @@ export default function SalesHistory({ canDelete = false }: SalesHistoryProps) {
|
||||
const [endDate, setEndDate] = useState('');
|
||||
|
||||
// Query for sales
|
||||
const { data: sales = [], isLoading } = useQuery<Sale[]>({
|
||||
const { data: salesData, isLoading } = useQuery<Sale[]>({
|
||||
queryKey: ['/api/sales', startDate, endDate],
|
||||
queryFn: () => {
|
||||
queryFn: async () => {
|
||||
const params = new URLSearchParams();
|
||||
if (startDate) params.append('startDate', startDate);
|
||||
if (endDate) params.append('endDate', endDate);
|
||||
const queryString = params.toString();
|
||||
return apiRequest(`/api/sales${queryString ? `?${queryString}` : ''}`);
|
||||
const response = await apiRequest(`/api/sales${queryString ? `?${queryString}` : ''}`);
|
||||
return response.json();
|
||||
},
|
||||
});
|
||||
|
||||
const sales = Array.isArray(salesData) ? salesData : [];
|
||||
|
||||
// Delete mutation
|
||||
const deleteSaleMutation = useMutation({
|
||||
mutationFn: (saleId: number) =>
|
||||
|
||||
Reference in new issue
Block a user