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