feat: add Pending Validation tab showing all pending changes

This commit is contained in:
Christian Vidal Wolf
2026-04-09 09:24:17 +02:00
parent a5c8076e18
commit 899016f0a0
5 changed files with 491 additions and 5 deletions
+62
View File
@@ -109,3 +109,65 @@ export async function resetAllPendingRows(): Promise<boolean> {
return false;
}
}
export interface HistoryEntry {
id: string;
product_id: string;
article_name: string;
old_data: ExcelRow;
new_data: ExcelRow;
changed_at: string;
changed_by: string;
}
export async function saveHistoryEntry(
articleNo: string,
articleName: string,
oldData: ExcelRow,
newData: ExcelRow,
userEmail: string
): Promise<boolean> {
try {
const response = await fetch(`${SUPABASE_URL}/rest/v1/products_history`, {
method: 'POST',
headers: {
'apikey': SUPABASE_KEY,
'Authorization': `Bearer ${SUPABASE_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
product_id: articleNo,
article_name: articleName,
old_data: oldData,
new_data: newData,
changed_at: new Date().toISOString(),
changed_by: userEmail
})
});
return response.ok;
} catch (error) {
console.error('Error saving history to Supabase:', error);
return false;
}
}
export async function getHistory(): Promise<HistoryEntry[]> {
try {
const response = await fetch(
`${SUPABASE_URL}/rest/v1/products_history?select=*&order=changed_at.desc&limit=100`,
{
headers: {
'apikey': SUPABASE_KEY,
'Authorization': `Bearer ${SUPABASE_KEY}`
}
}
);
if (!response.ok) return [];
return await response.json();
} catch (error) {
console.error('Error fetching history from Supabase:', error);
return [];
}
}