Scope manual sync buttons to current view dates only
Sync rota and pull timesheets now operate on the 7-day view window rather than rolling default windows — reduces API calls and allows backdating. Cron job still uses rolling defaults via runRotaSync()/runTimesheetSync(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9bfd14a082
commit
ffefa1914f
9 changed files with 81 additions and 60 deletions
|
|
@ -83,11 +83,11 @@ export function putWorkforceDepartments(dept_ids) {
|
|||
body: JSON.stringify({ dept_ids }),
|
||||
});
|
||||
}
|
||||
export function syncWorkforce() {
|
||||
return request('/workforce/sync', { method: 'POST' });
|
||||
export function syncWorkforce(start, end) {
|
||||
return request(`/workforce/sync?start=${start}&end=${end}`, { method: 'POST' });
|
||||
}
|
||||
export function syncTimesheets() {
|
||||
return request('/workforce/sync-timesheets', { method: 'POST' });
|
||||
export function syncTimesheets(start, end) {
|
||||
return request(`/workforce/sync-timesheets?start=${start}&end=${end}`, { method: 'POST' });
|
||||
}
|
||||
export function getWorkforceShifts(start, end) {
|
||||
return request(`/workforce/shifts?start=${start}&end=${end}`);
|
||||
|
|
|
|||
|
|
@ -116,12 +116,12 @@ export function putWorkforceDepartments(dept_ids: string[]): Promise<{ ok: boole
|
|||
})
|
||||
}
|
||||
|
||||
export function syncWorkforce(): Promise<{ ok: boolean; from: string; to: string; dates_synced: number }> {
|
||||
return request('/workforce/sync', { method: 'POST' })
|
||||
export function syncWorkforce(start: string, end: string): Promise<{ ok: boolean; from: string; to: string; dates_synced: number }> {
|
||||
return request(`/workforce/sync?start=${start}&end=${end}`, { method: 'POST' })
|
||||
}
|
||||
|
||||
export function syncTimesheets(): Promise<{ ok: boolean; from: string; to: string; dates_synced: number }> {
|
||||
return request('/workforce/sync-timesheets', { method: 'POST' })
|
||||
export function syncTimesheets(start: string, end: string): Promise<{ ok: boolean; from: string; to: string; dates_synced: number }> {
|
||||
return request(`/workforce/sync-timesheets?start=${start}&end=${end}`, { method: 'POST' })
|
||||
}
|
||||
|
||||
export function getWorkforceShifts(start: string, end: string): Promise<Record<string, WfDayData>> {
|
||||
|
|
|
|||
|
|
@ -250,13 +250,15 @@ export function Planner() {
|
|||
}
|
||||
// ── Workforce sync ───────────────────────────────────────────────────────────
|
||||
async function syncRota() {
|
||||
if (!bookings)
|
||||
return;
|
||||
const start = bookings.dates[0];
|
||||
const end = bookings.dates[bookings.dates.length - 1];
|
||||
setSyncing(true);
|
||||
try {
|
||||
await syncWorkforce();
|
||||
if (bookings) {
|
||||
const shifts = await getWorkforceShifts(bookings.dates[0], bookings.dates[bookings.dates.length - 1]);
|
||||
setWfShifts(shifts);
|
||||
}
|
||||
await syncWorkforce(start, end);
|
||||
const shifts = await getWorkforceShifts(start, end);
|
||||
setWfShifts(shifts);
|
||||
flash('Rota synced from Workforce');
|
||||
}
|
||||
catch (e) {
|
||||
|
|
@ -267,13 +269,15 @@ export function Planner() {
|
|||
}
|
||||
}
|
||||
async function syncTimesheetData() {
|
||||
if (!bookings)
|
||||
return;
|
||||
const start = bookings.dates[0];
|
||||
const end = bookings.dates[bookings.dates.length - 1];
|
||||
setTimesheetSyncing(true);
|
||||
try {
|
||||
await syncTimesheets();
|
||||
if (bookings) {
|
||||
const shifts = await getWorkforceShifts(bookings.dates[0], bookings.dates[bookings.dates.length - 1]);
|
||||
setWfShifts(shifts);
|
||||
}
|
||||
await syncTimesheets(start, end);
|
||||
const shifts = await getWorkforceShifts(start, end);
|
||||
setWfShifts(shifts);
|
||||
flash('Timesheets pulled from Workforce');
|
||||
}
|
||||
catch (e) {
|
||||
|
|
|
|||
|
|
@ -298,13 +298,14 @@ export function Planner() {
|
|||
// ── Workforce sync ───────────────────────────────────────────────────────────
|
||||
|
||||
async function syncRota() {
|
||||
if (!bookings) return
|
||||
const start = bookings.dates[0]
|
||||
const end = bookings.dates[bookings.dates.length - 1]
|
||||
setSyncing(true)
|
||||
try {
|
||||
await syncWorkforce()
|
||||
if (bookings) {
|
||||
const shifts = await getWorkforceShifts(bookings.dates[0], bookings.dates[bookings.dates.length - 1])
|
||||
setWfShifts(shifts)
|
||||
}
|
||||
await syncWorkforce(start, end)
|
||||
const shifts = await getWorkforceShifts(start, end)
|
||||
setWfShifts(shifts)
|
||||
flash('Rota synced from Workforce')
|
||||
} catch (e) {
|
||||
flash(e instanceof Error ? e.message : 'Sync failed', true)
|
||||
|
|
@ -314,13 +315,14 @@ export function Planner() {
|
|||
}
|
||||
|
||||
async function syncTimesheetData() {
|
||||
if (!bookings) return
|
||||
const start = bookings.dates[0]
|
||||
const end = bookings.dates[bookings.dates.length - 1]
|
||||
setTimesheetSyncing(true)
|
||||
try {
|
||||
await syncTimesheets()
|
||||
if (bookings) {
|
||||
const shifts = await getWorkforceShifts(bookings.dates[0], bookings.dates[bookings.dates.length - 1])
|
||||
setWfShifts(shifts)
|
||||
}
|
||||
await syncTimesheets(start, end)
|
||||
const shifts = await getWorkforceShifts(start, end)
|
||||
setWfShifts(shifts)
|
||||
flash('Timesheets pulled from Workforce')
|
||||
} catch (e) {
|
||||
flash(e instanceof Error ? e.message : 'Timesheet sync failed', true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue