mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 12:45:24 +02:00
fix(bc): sync all pending queue items
This commit is contained in:
+8
-4
@@ -792,22 +792,26 @@ export default function App() {
|
||||
};
|
||||
|
||||
const handleSyncSelectedBcSync = async () => {
|
||||
if (selectedBcQueueEntries.length === 0) return;
|
||||
if (bcQueueEntries.length === 0) return;
|
||||
setIsSyncingBC(true);
|
||||
try {
|
||||
const selectedArticles = new Set(selectedBcQueueEntries.map(([articleNo]) => articleNo));
|
||||
const entriesToSync = [...bcQueueEntries].sort((a, b) => {
|
||||
const rowDelta = a[1].rowIndex - b[1].rowIndex;
|
||||
if (rowDelta !== 0) return rowDelta;
|
||||
return a[0].localeCompare(b[0]);
|
||||
});
|
||||
|
||||
setBcSyncQueue(prev => {
|
||||
const next: BcSyncQueue = { ...prev };
|
||||
(Object.entries(next) as Array<[string, BcSyncQueueEntry]>).forEach(([articleNo, item]) => {
|
||||
if (selectedArticles.has(articleNo)) {
|
||||
if (next[articleNo]) {
|
||||
next[articleNo] = { ...item, status: 'syncing', error: undefined };
|
||||
}
|
||||
});
|
||||
return next;
|
||||
});
|
||||
|
||||
for (const [articleNo, item] of selectedBcQueueEntries) {
|
||||
for (const [articleNo, item] of entriesToSync) {
|
||||
const preview = await previewBusinessCentralSync(appState.headers, item.newData);
|
||||
if (!preview.success) {
|
||||
setBcSyncQueue(prev => ({
|
||||
|
||||
@@ -196,10 +196,10 @@ export function TopBar({ stats, activeModule, onRefresh, userEmail, onSignOut, c
|
||||
)}>
|
||||
<button
|
||||
onClick={onSyncSelectedBcSync}
|
||||
disabled={isSyncingBC || selectedBcQueueCount === 0}
|
||||
disabled={isSyncingBC || bcQueueCount === 0}
|
||||
className={cn(
|
||||
"flex items-center gap-2 px-4 py-2 text-sm font-bold transition-all text-white",
|
||||
selectedBcQueueCount > 0
|
||||
bcQueueCount > 0
|
||||
? "bg-blue-600 hover:bg-blue-500 disabled:opacity-60"
|
||||
: "bg-slate-700 cursor-not-allowed"
|
||||
)}
|
||||
@@ -207,10 +207,8 @@ export function TopBar({ stats, activeModule, onRefresh, userEmail, onSignOut, c
|
||||
{isSyncingBC ? <Loader2 className="w-4 h-4 animate-spin" /> : <CloudUpload className="w-4 h-4" />}
|
||||
{isSyncingBC
|
||||
? 'Syncing...'
|
||||
: selectedBcQueueCount > 0
|
||||
? `Sync ${selectedBcQueueCount} to BC`
|
||||
: bcQueueCount > 0
|
||||
? 'No selected items'
|
||||
? `Sync all ${bcQueueCount} to BC`
|
||||
: 'No BC queue'}
|
||||
</button>
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user