@optifye/dashboard-core 6.10.2 → 6.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +140 -325
- package/dist/index.mjs +140 -325
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -49095,43 +49095,6 @@ var calculateShiftHours = (startTime, endTime, breaks = []) => {
|
|
|
49095
49095
|
const hoursDiff = (endMinutes - startMinutes - totalBreakMinutes) / 60;
|
|
49096
49096
|
return Number(hoursDiff.toFixed(1));
|
|
49097
49097
|
};
|
|
49098
|
-
var calculateBreakDuration2 = (startTime, endTime) => {
|
|
49099
|
-
const [startHour, startMinute] = startTime.split(":").map(Number);
|
|
49100
|
-
const [endHour, endMinute] = endTime.split(":").map(Number);
|
|
49101
|
-
let startMinutes = startHour * 60 + startMinute;
|
|
49102
|
-
let endMinutes = endHour * 60 + endMinute;
|
|
49103
|
-
if (endMinutes < startMinutes) {
|
|
49104
|
-
endMinutes += 24 * 60;
|
|
49105
|
-
}
|
|
49106
|
-
return endMinutes - startMinutes;
|
|
49107
|
-
};
|
|
49108
|
-
var parseBreaksFromDB = (dbBreaks) => {
|
|
49109
|
-
if (!dbBreaks) return [];
|
|
49110
|
-
if (Array.isArray(dbBreaks)) {
|
|
49111
|
-
return dbBreaks.map((breakItem) => ({
|
|
49112
|
-
startTime: breakItem.start || breakItem.startTime || "00:00",
|
|
49113
|
-
endTime: breakItem.end || breakItem.endTime || "00:00",
|
|
49114
|
-
duration: calculateBreakDuration2(
|
|
49115
|
-
breakItem.start || breakItem.startTime || "00:00",
|
|
49116
|
-
breakItem.end || breakItem.endTime || "00:00"
|
|
49117
|
-
),
|
|
49118
|
-
remarks: breakItem.remarks || breakItem.name || ""
|
|
49119
|
-
}));
|
|
49120
|
-
} else if (dbBreaks.breaks && Array.isArray(dbBreaks.breaks)) {
|
|
49121
|
-
return dbBreaks.breaks.map((breakItem) => ({
|
|
49122
|
-
startTime: breakItem.start || breakItem.startTime || "00:00",
|
|
49123
|
-
endTime: breakItem.end || breakItem.endTime || "00:00",
|
|
49124
|
-
duration: calculateBreakDuration2(
|
|
49125
|
-
breakItem.start || breakItem.startTime || "00:00",
|
|
49126
|
-
breakItem.end || breakItem.endTime || "00:00"
|
|
49127
|
-
),
|
|
49128
|
-
remarks: breakItem.remarks || breakItem.name || ""
|
|
49129
|
-
}));
|
|
49130
|
-
} else {
|
|
49131
|
-
console.warn("Unexpected breaks format:", dbBreaks);
|
|
49132
|
-
return [];
|
|
49133
|
-
}
|
|
49134
|
-
};
|
|
49135
49098
|
var getStoredLineState = (lineId) => {
|
|
49136
49099
|
try {
|
|
49137
49100
|
return JSON.parse(localStorage.getItem(`line_${lineId}_open`) || "false");
|
|
@@ -49423,16 +49386,9 @@ var ShiftsView = ({
|
|
|
49423
49386
|
() => lineIds.map((id3) => ({
|
|
49424
49387
|
id: id3,
|
|
49425
49388
|
name: lineNames[id3] || `Line ${id3.substring(0, 4)}`,
|
|
49426
|
-
|
|
49427
|
-
|
|
49428
|
-
|
|
49429
|
-
breaks: []
|
|
49430
|
-
},
|
|
49431
|
-
nightShift: {
|
|
49432
|
-
startTime: "20:00",
|
|
49433
|
-
endTime: "04:00",
|
|
49434
|
-
breaks: []
|
|
49435
|
-
},
|
|
49389
|
+
timezone: "Asia/Kolkata",
|
|
49390
|
+
shifts: [],
|
|
49391
|
+
// Will be populated from DB
|
|
49436
49392
|
isOpen: true,
|
|
49437
49393
|
isSaving: false,
|
|
49438
49394
|
saveSuccess: false
|
|
@@ -49470,58 +49426,37 @@ var ShiftsView = ({
|
|
|
49470
49426
|
setLoading(false);
|
|
49471
49427
|
return;
|
|
49472
49428
|
}
|
|
49473
|
-
const { data:
|
|
49474
|
-
if (
|
|
49475
|
-
console.error("Error fetching
|
|
49476
|
-
showToast("error", "Error loading
|
|
49477
|
-
setError("Failed to load
|
|
49478
|
-
return;
|
|
49479
|
-
}
|
|
49480
|
-
const { data: nightShiftOperatingHours, error: nightShiftError } = await supabase.from("line_operating_hours").select("line_id, start_time, end_time, breaks").eq("shift_id", 1).in("line_id", enabledLineIds);
|
|
49481
|
-
if (nightShiftError) {
|
|
49482
|
-
console.error("Error fetching night shift operating hours:", nightShiftError);
|
|
49483
|
-
showToast("error", "Error loading night shift data");
|
|
49484
|
-
setError("Failed to load night shift data");
|
|
49429
|
+
const { data: allShifts, error: shiftsError } = await supabase.from("line_operating_hours").select("line_id, shift_id, shift_name, start_time, end_time, breaks, timezone").in("line_id", enabledLineIds);
|
|
49430
|
+
if (shiftsError) {
|
|
49431
|
+
console.error("Error fetching shifts:", shiftsError);
|
|
49432
|
+
showToast("error", "Error loading shift data");
|
|
49433
|
+
setError("Failed to load shift data");
|
|
49485
49434
|
return;
|
|
49486
49435
|
}
|
|
49487
|
-
const
|
|
49488
|
-
|
|
49489
|
-
|
|
49490
|
-
|
|
49491
|
-
breaks: parseBreaksFromDB(item.breaks)
|
|
49492
|
-
};
|
|
49493
|
-
return map;
|
|
49436
|
+
const shiftsByLine = (allShifts || []).reduce((acc, row) => {
|
|
49437
|
+
if (!acc[row.line_id]) acc[row.line_id] = [];
|
|
49438
|
+
acc[row.line_id].push(row);
|
|
49439
|
+
return acc;
|
|
49494
49440
|
}, {});
|
|
49495
|
-
const
|
|
49496
|
-
|
|
49497
|
-
|
|
49498
|
-
|
|
49499
|
-
breaks: parseBreaksFromDB(item.breaks)
|
|
49500
|
-
};
|
|
49501
|
-
return map;
|
|
49441
|
+
const { data: linesData } = await supabase.from("lines").select("id, line_name").in("id", enabledLineIds);
|
|
49442
|
+
const lineNameMap = (linesData || []).reduce((acc, line) => {
|
|
49443
|
+
if (line.line_name) acc[line.id] = line.line_name;
|
|
49444
|
+
return acc;
|
|
49502
49445
|
}, {});
|
|
49503
49446
|
setLineConfigs((prev) => {
|
|
49504
49447
|
const enabledConfigs = prev.filter((config) => enabledLineIds.includes(config.id));
|
|
49505
49448
|
return enabledConfigs.map((config) => {
|
|
49506
|
-
const
|
|
49507
|
-
const
|
|
49508
|
-
const
|
|
49509
|
-
|
|
49510
|
-
|
|
49511
|
-
|
|
49512
|
-
|
|
49513
|
-
|
|
49514
|
-
|
|
49515
|
-
|
|
49516
|
-
|
|
49517
|
-
...newConfig.nightShift,
|
|
49518
|
-
...nightShiftHoursMap[lineId]
|
|
49519
|
-
};
|
|
49520
|
-
}
|
|
49521
|
-
if (newConfig.isOpen === void 0) {
|
|
49522
|
-
newConfig.isOpen = getStoredLineState(lineId);
|
|
49523
|
-
}
|
|
49524
|
-
return newConfig;
|
|
49449
|
+
const rows = shiftsByLine[config.id] || [];
|
|
49450
|
+
const builtConfig = buildShiftConfigFromOperatingHoursRows(rows);
|
|
49451
|
+
const lineName = lineNameMap[config.id] || lineNames[config.id] || `Line ${config.id.substring(0, 4)}`;
|
|
49452
|
+
const sortedShifts = [...builtConfig.shifts || []].sort((a, b) => a.shiftId - b.shiftId);
|
|
49453
|
+
return {
|
|
49454
|
+
...config,
|
|
49455
|
+
name: lineName,
|
|
49456
|
+
shifts: sortedShifts,
|
|
49457
|
+
timezone: builtConfig.timezone || config.timezone,
|
|
49458
|
+
isOpen: config.isOpen ?? getStoredLineState(config.id)
|
|
49459
|
+
};
|
|
49525
49460
|
});
|
|
49526
49461
|
});
|
|
49527
49462
|
setLoading(false);
|
|
@@ -49544,183 +49479,79 @@ var ShiftsView = ({
|
|
|
49544
49479
|
);
|
|
49545
49480
|
});
|
|
49546
49481
|
}, []);
|
|
49547
|
-
const
|
|
49548
|
-
setLineConfigs((prev) => prev.map((config) => {
|
|
49549
|
-
const typedConfig = config;
|
|
49550
|
-
if (typedConfig.id === lineId) {
|
|
49551
|
-
const updatedDayShift = { ...typedConfig.dayShift, startTime: value };
|
|
49552
|
-
return {
|
|
49553
|
-
...typedConfig,
|
|
49554
|
-
dayShift: updatedDayShift
|
|
49555
|
-
};
|
|
49556
|
-
}
|
|
49557
|
-
return typedConfig;
|
|
49558
|
-
}));
|
|
49559
|
-
}, []);
|
|
49560
|
-
const updateDayShiftEndTime = React24.useCallback((lineId, value) => {
|
|
49561
|
-
setLineConfigs((prev) => prev.map((config) => {
|
|
49562
|
-
const typedConfig = config;
|
|
49563
|
-
if (typedConfig.id === lineId) {
|
|
49564
|
-
const updatedDayShift = { ...typedConfig.dayShift, endTime: value };
|
|
49565
|
-
return {
|
|
49566
|
-
...typedConfig,
|
|
49567
|
-
dayShift: updatedDayShift
|
|
49568
|
-
};
|
|
49569
|
-
}
|
|
49570
|
-
return typedConfig;
|
|
49571
|
-
}));
|
|
49572
|
-
}, []);
|
|
49573
|
-
const updateNightShiftStartTime = React24.useCallback((lineId, value) => {
|
|
49574
|
-
setLineConfigs((prev) => prev.map((config) => {
|
|
49575
|
-
const typedConfig = config;
|
|
49576
|
-
if (typedConfig.id === lineId) {
|
|
49577
|
-
const updatedNightShift = { ...typedConfig.nightShift, startTime: value };
|
|
49578
|
-
return {
|
|
49579
|
-
...typedConfig,
|
|
49580
|
-
nightShift: updatedNightShift
|
|
49581
|
-
};
|
|
49582
|
-
}
|
|
49583
|
-
return typedConfig;
|
|
49584
|
-
}));
|
|
49585
|
-
}, []);
|
|
49586
|
-
const updateNightShiftEndTime = React24.useCallback((lineId, value) => {
|
|
49482
|
+
const updateShiftTime = React24.useCallback((lineId, shiftIndex, field, value) => {
|
|
49587
49483
|
setLineConfigs((prev) => prev.map((config) => {
|
|
49588
|
-
|
|
49589
|
-
|
|
49590
|
-
|
|
49591
|
-
|
|
49592
|
-
...typedConfig,
|
|
49593
|
-
nightShift: updatedNightShift
|
|
49594
|
-
};
|
|
49595
|
-
}
|
|
49596
|
-
return typedConfig;
|
|
49597
|
-
}));
|
|
49598
|
-
}, []);
|
|
49599
|
-
const addDayShiftBreak = React24.useCallback((lineId) => {
|
|
49600
|
-
setLineConfigs((prev) => prev.map((config) => {
|
|
49601
|
-
const typedConfig = config;
|
|
49602
|
-
if (typedConfig.id === lineId) {
|
|
49603
|
-
const dayShift = { ...typedConfig.dayShift };
|
|
49604
|
-
const newBreak = {
|
|
49605
|
-
startTime: dayShift.startTime,
|
|
49606
|
-
endTime: dayShift.startTime,
|
|
49607
|
-
duration: 0,
|
|
49608
|
-
remarks: ""
|
|
49609
|
-
};
|
|
49610
|
-
return {
|
|
49611
|
-
...typedConfig,
|
|
49612
|
-
dayShift: {
|
|
49613
|
-
...dayShift,
|
|
49614
|
-
breaks: [...dayShift.breaks, newBreak]
|
|
49615
|
-
}
|
|
49616
|
-
};
|
|
49617
|
-
}
|
|
49618
|
-
return typedConfig;
|
|
49619
|
-
}));
|
|
49620
|
-
}, []);
|
|
49621
|
-
const addNightShiftBreak = React24.useCallback((lineId) => {
|
|
49622
|
-
setLineConfigs((prev) => prev.map((config) => {
|
|
49623
|
-
const typedConfig = config;
|
|
49624
|
-
if (typedConfig.id === lineId) {
|
|
49625
|
-
const nightShift = { ...typedConfig.nightShift };
|
|
49626
|
-
const newBreak = {
|
|
49627
|
-
startTime: nightShift.startTime,
|
|
49628
|
-
endTime: nightShift.startTime,
|
|
49629
|
-
duration: 0
|
|
49630
|
-
};
|
|
49631
|
-
return {
|
|
49632
|
-
...typedConfig,
|
|
49633
|
-
nightShift: {
|
|
49634
|
-
...nightShift,
|
|
49635
|
-
breaks: [...nightShift.breaks, newBreak]
|
|
49636
|
-
}
|
|
49637
|
-
};
|
|
49638
|
-
}
|
|
49639
|
-
return typedConfig;
|
|
49640
|
-
}));
|
|
49641
|
-
}, []);
|
|
49642
|
-
const updateDayShiftBreak = React24.useCallback((lineId, index, field, value) => {
|
|
49643
|
-
setLineConfigs((prev) => prev.map((config) => {
|
|
49644
|
-
const typedConfig = config;
|
|
49645
|
-
if (typedConfig.id === lineId) {
|
|
49646
|
-
const dayShift = { ...typedConfig.dayShift };
|
|
49647
|
-
const newBreaks = [...dayShift.breaks];
|
|
49648
|
-
newBreaks[index] = { ...newBreaks[index], [field]: value };
|
|
49649
|
-
if (field === "startTime" || field === "endTime") {
|
|
49650
|
-
const startParts = newBreaks[index].startTime.split(":").map(Number);
|
|
49651
|
-
const endParts = newBreaks[index].endTime.split(":").map(Number);
|
|
49652
|
-
let startMinutes = startParts[0] * 60 + startParts[1];
|
|
49653
|
-
let endMinutes = endParts[0] * 60 + endParts[1];
|
|
49654
|
-
if (endMinutes < startMinutes) {
|
|
49655
|
-
endMinutes += 24 * 60;
|
|
49656
|
-
}
|
|
49657
|
-
newBreaks[index].duration = endMinutes - startMinutes;
|
|
49484
|
+
if (config.id === lineId && config.shifts) {
|
|
49485
|
+
const newShifts = [...config.shifts];
|
|
49486
|
+
if (newShifts[shiftIndex]) {
|
|
49487
|
+
newShifts[shiftIndex] = { ...newShifts[shiftIndex], [field]: value };
|
|
49658
49488
|
}
|
|
49659
|
-
return {
|
|
49660
|
-
...typedConfig,
|
|
49661
|
-
dayShift: {
|
|
49662
|
-
...dayShift,
|
|
49663
|
-
breaks: newBreaks
|
|
49664
|
-
}
|
|
49665
|
-
};
|
|
49489
|
+
return { ...config, shifts: newShifts };
|
|
49666
49490
|
}
|
|
49667
|
-
return
|
|
49491
|
+
return config;
|
|
49668
49492
|
}));
|
|
49669
49493
|
}, []);
|
|
49670
|
-
const
|
|
49494
|
+
const addShiftBreak = React24.useCallback((lineId, shiftIndex) => {
|
|
49671
49495
|
setLineConfigs((prev) => prev.map((config) => {
|
|
49672
|
-
|
|
49673
|
-
|
|
49674
|
-
|
|
49675
|
-
|
|
49676
|
-
|
|
49677
|
-
|
|
49678
|
-
|
|
49679
|
-
|
|
49680
|
-
|
|
49681
|
-
|
|
49682
|
-
|
|
49683
|
-
|
|
49684
|
-
|
|
49685
|
-
|
|
49496
|
+
if (config.id === lineId && config.shifts) {
|
|
49497
|
+
const newShifts = [...config.shifts];
|
|
49498
|
+
if (newShifts[shiftIndex]) {
|
|
49499
|
+
const shift = newShifts[shiftIndex];
|
|
49500
|
+
const newBreak = {
|
|
49501
|
+
startTime: shift.startTime,
|
|
49502
|
+
endTime: shift.startTime,
|
|
49503
|
+
duration: 0,
|
|
49504
|
+
remarks: ""
|
|
49505
|
+
};
|
|
49506
|
+
newShifts[shiftIndex] = {
|
|
49507
|
+
...shift,
|
|
49508
|
+
breaks: [...shift.breaks || [], newBreak]
|
|
49509
|
+
};
|
|
49686
49510
|
}
|
|
49687
|
-
return {
|
|
49688
|
-
...typedConfig,
|
|
49689
|
-
nightShift: {
|
|
49690
|
-
...nightShift,
|
|
49691
|
-
breaks: newBreaks
|
|
49692
|
-
}
|
|
49693
|
-
};
|
|
49511
|
+
return { ...config, shifts: newShifts };
|
|
49694
49512
|
}
|
|
49695
|
-
return
|
|
49513
|
+
return config;
|
|
49696
49514
|
}));
|
|
49697
49515
|
}, []);
|
|
49698
|
-
const
|
|
49516
|
+
const updateShiftBreak = React24.useCallback((lineId, shiftIndex, breakIndex, field, value) => {
|
|
49699
49517
|
setLineConfigs((prev) => prev.map((config) => {
|
|
49700
|
-
if (config.id === lineId) {
|
|
49701
|
-
const
|
|
49702
|
-
|
|
49703
|
-
|
|
49704
|
-
|
|
49705
|
-
|
|
49706
|
-
|
|
49518
|
+
if (config.id === lineId && config.shifts) {
|
|
49519
|
+
const newShifts = [...config.shifts];
|
|
49520
|
+
if (newShifts[shiftIndex]) {
|
|
49521
|
+
const shift = newShifts[shiftIndex];
|
|
49522
|
+
const newBreaks = [...shift.breaks || []];
|
|
49523
|
+
if (newBreaks[breakIndex]) {
|
|
49524
|
+
newBreaks[breakIndex] = { ...newBreaks[breakIndex], [field]: value };
|
|
49525
|
+
if (field === "startTime" || field === "endTime") {
|
|
49526
|
+
const startParts = newBreaks[breakIndex].startTime.split(":").map(Number);
|
|
49527
|
+
const endParts = newBreaks[breakIndex].endTime.split(":").map(Number);
|
|
49528
|
+
let startMinutes = startParts[0] * 60 + startParts[1];
|
|
49529
|
+
let endMinutes = endParts[0] * 60 + endParts[1];
|
|
49530
|
+
if (endMinutes < startMinutes) {
|
|
49531
|
+
endMinutes += 24 * 60;
|
|
49532
|
+
}
|
|
49533
|
+
newBreaks[breakIndex].duration = endMinutes - startMinutes;
|
|
49534
|
+
}
|
|
49707
49535
|
}
|
|
49708
|
-
|
|
49536
|
+
newShifts[shiftIndex] = { ...shift, breaks: newBreaks };
|
|
49537
|
+
}
|
|
49538
|
+
return { ...config, shifts: newShifts };
|
|
49709
49539
|
}
|
|
49710
49540
|
return config;
|
|
49711
49541
|
}));
|
|
49712
49542
|
}, []);
|
|
49713
|
-
const
|
|
49543
|
+
const removeShiftBreak = React24.useCallback((lineId, shiftIndex, breakIndex) => {
|
|
49714
49544
|
setLineConfigs((prev) => prev.map((config) => {
|
|
49715
|
-
if (config.id === lineId) {
|
|
49716
|
-
const
|
|
49717
|
-
|
|
49718
|
-
|
|
49719
|
-
|
|
49720
|
-
...
|
|
49721
|
-
breaks:
|
|
49722
|
-
}
|
|
49723
|
-
}
|
|
49545
|
+
if (config.id === lineId && config.shifts) {
|
|
49546
|
+
const newShifts = [...config.shifts];
|
|
49547
|
+
if (newShifts[shiftIndex]) {
|
|
49548
|
+
const shift = newShifts[shiftIndex];
|
|
49549
|
+
newShifts[shiftIndex] = {
|
|
49550
|
+
...shift,
|
|
49551
|
+
breaks: (shift.breaks || []).filter((_, i) => i !== breakIndex)
|
|
49552
|
+
};
|
|
49553
|
+
}
|
|
49554
|
+
return { ...config, shifts: newShifts };
|
|
49724
49555
|
}
|
|
49725
49556
|
return config;
|
|
49726
49557
|
}));
|
|
@@ -49734,36 +49565,26 @@ var ShiftsView = ({
|
|
|
49734
49565
|
if (!lineConfig) {
|
|
49735
49566
|
throw new Error("Line configuration not found");
|
|
49736
49567
|
}
|
|
49737
|
-
const
|
|
49738
|
-
|
|
49739
|
-
|
|
49740
|
-
|
|
49741
|
-
|
|
49742
|
-
|
|
49743
|
-
|
|
49744
|
-
|
|
49745
|
-
|
|
49746
|
-
|
|
49747
|
-
|
|
49748
|
-
|
|
49749
|
-
|
|
49750
|
-
|
|
49751
|
-
|
|
49752
|
-
|
|
49753
|
-
|
|
49754
|
-
if (dayResult.error) {
|
|
49755
|
-
throw new Error(`Failed to save day shift: ${dayResult.error.message}`);
|
|
49756
|
-
}
|
|
49757
|
-
const nightResult = await supabase.from("line_operating_hours").upsert(nightShiftData).select();
|
|
49758
|
-
if (nightResult.error) {
|
|
49759
|
-
throw new Error(`Failed to save night shift: ${nightResult.error.message}`);
|
|
49568
|
+
const allSavedRows = [];
|
|
49569
|
+
for (const shift of lineConfig.shifts || []) {
|
|
49570
|
+
const shiftData = {
|
|
49571
|
+
line_id: lineId,
|
|
49572
|
+
shift_id: shift.shiftId,
|
|
49573
|
+
shift_name: shift.shiftName,
|
|
49574
|
+
start_time: shift.startTime,
|
|
49575
|
+
end_time: shift.endTime,
|
|
49576
|
+
breaks: formatBreaks(shift.breaks || [])
|
|
49577
|
+
};
|
|
49578
|
+
const { data, error: error2 } = await supabase.from("line_operating_hours").upsert(shiftData).select();
|
|
49579
|
+
if (error2) {
|
|
49580
|
+
throw new Error(`Failed to save shift ${shift.shiftName}: ${error2.message}`);
|
|
49581
|
+
}
|
|
49582
|
+
if (data) {
|
|
49583
|
+
allSavedRows.push(...data);
|
|
49584
|
+
}
|
|
49760
49585
|
}
|
|
49761
|
-
|
|
49762
|
-
|
|
49763
|
-
...nightResult.data || []
|
|
49764
|
-
];
|
|
49765
|
-
if (updatedRows.length > 0) {
|
|
49766
|
-
shiftConfigStore.setFromOperatingHoursRows(lineId, updatedRows, shiftConfigStore.get(lineId));
|
|
49586
|
+
if (allSavedRows.length > 0) {
|
|
49587
|
+
shiftConfigStore.setFromOperatingHoursRows(lineId, allSavedRows, shiftConfigStore.get(lineId));
|
|
49767
49588
|
}
|
|
49768
49589
|
setLineConfigs((prev) => prev.map(
|
|
49769
49590
|
(config) => config.id === lineId ? { ...config, isSaving: false, saveSuccess: true } : config
|
|
@@ -49842,48 +49663,34 @@ var ShiftsView = ({
|
|
|
49842
49663
|
)
|
|
49843
49664
|
] })
|
|
49844
49665
|
] }) }),
|
|
49845
|
-
/* @__PURE__ */ jsxRuntime.
|
|
49846
|
-
|
|
49847
|
-
|
|
49848
|
-
|
|
49849
|
-
|
|
49850
|
-
|
|
49851
|
-
|
|
49852
|
-
|
|
49853
|
-
|
|
49854
|
-
|
|
49855
|
-
|
|
49856
|
-
|
|
49857
|
-
|
|
49858
|
-
|
|
49859
|
-
|
|
49860
|
-
|
|
49861
|
-
|
|
49862
|
-
|
|
49863
|
-
|
|
49864
|
-
|
|
49865
|
-
|
|
49866
|
-
|
|
49867
|
-
|
|
49868
|
-
|
|
49869
|
-
|
|
49870
|
-
|
|
49871
|
-
|
|
49872
|
-
|
|
49873
|
-
breaks: config.nightShift.breaks,
|
|
49874
|
-
onStartTimeChange: (value) => updateNightShiftStartTime(config.id, value),
|
|
49875
|
-
onEndTimeChange: (value) => updateNightShiftEndTime(config.id, value),
|
|
49876
|
-
onBreakUpdate: (index, field, value) => updateNightShiftBreak(config.id, index, field, value),
|
|
49877
|
-
onBreakRemove: (index) => removeNightShiftBreak(config.id, index),
|
|
49878
|
-
onBreakAdd: () => addNightShiftBreak(config.id),
|
|
49879
|
-
shiftHours: calculateShiftHours(
|
|
49880
|
-
config.nightShift.startTime,
|
|
49881
|
-
config.nightShift.endTime,
|
|
49882
|
-
config.nightShift.breaks
|
|
49883
|
-
)
|
|
49884
|
-
}
|
|
49885
|
-
)
|
|
49886
|
-
] })
|
|
49666
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { id: `shift-panel-${config.id}`, className: "p-3 sm:p-4 md:p-6 border-t border-gray-200 w-full", children: config.shifts && config.shifts.length > 0 ? config.shifts.map((shift, shiftIndex) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
49667
|
+
ShiftPanel,
|
|
49668
|
+
{
|
|
49669
|
+
title: shift.shiftName,
|
|
49670
|
+
icon: (
|
|
49671
|
+
// Icon based on shift name (case-insensitive)
|
|
49672
|
+
shift.shiftName.toLowerCase().includes("day") ? /* @__PURE__ */ jsxRuntime.jsx("svg", { className: "w-5 h-5 text-gray-600", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" }) }) : shift.shiftName.toLowerCase().includes("night") ? /* @__PURE__ */ jsxRuntime.jsx("svg", { className: "w-5 h-5 text-gray-600", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z" }) }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Clock, { className: "w-5 h-5 text-gray-600" })
|
|
49673
|
+
),
|
|
49674
|
+
startTime: shift.startTime,
|
|
49675
|
+
endTime: shift.endTime,
|
|
49676
|
+
breaks: shift.breaks || [],
|
|
49677
|
+
onStartTimeChange: (value) => updateShiftTime(config.id, shiftIndex, "startTime", value),
|
|
49678
|
+
onEndTimeChange: (value) => updateShiftTime(config.id, shiftIndex, "endTime", value),
|
|
49679
|
+
onBreakUpdate: (breakIndex, field, value) => updateShiftBreak(config.id, shiftIndex, breakIndex, field, value),
|
|
49680
|
+
onBreakRemove: (breakIndex) => removeShiftBreak(config.id, shiftIndex, breakIndex),
|
|
49681
|
+
onBreakAdd: () => addShiftBreak(config.id, shiftIndex),
|
|
49682
|
+
shiftHours: calculateShiftHours(
|
|
49683
|
+
shift.startTime,
|
|
49684
|
+
shift.endTime,
|
|
49685
|
+
shift.breaks || []
|
|
49686
|
+
)
|
|
49687
|
+
},
|
|
49688
|
+
shift.shiftId
|
|
49689
|
+
)) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center text-gray-500 py-8", children: [
|
|
49690
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Clock, { className: "w-12 h-12 mx-auto mb-3 text-gray-400" }),
|
|
49691
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm", children: "No shifts configured for this line" }),
|
|
49692
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-gray-400 mt-1", children: "Shifts will appear here once configured in the database" })
|
|
49693
|
+
] }) })
|
|
49887
49694
|
] }, config.id)) })
|
|
49888
49695
|
] })
|
|
49889
49696
|
] });
|
|
@@ -53375,8 +53182,9 @@ var WorkspaceHealthView = ({
|
|
|
53375
53182
|
loading,
|
|
53376
53183
|
error,
|
|
53377
53184
|
refetch,
|
|
53378
|
-
shiftConfig: loadedShiftConfig
|
|
53185
|
+
shiftConfig: loadedShiftConfig,
|
|
53379
53186
|
// Get shift config from the hook to pass to modal
|
|
53187
|
+
shiftConfigMap
|
|
53380
53188
|
} = useWorkspaceHealth({
|
|
53381
53189
|
lineId: effectiveLineIdForFetch,
|
|
53382
53190
|
// undefined in factory view = fetch all lines
|
|
@@ -53388,6 +53196,13 @@ var WorkspaceHealthView = ({
|
|
|
53388
53196
|
date: selectedDate,
|
|
53389
53197
|
shiftId: selectedShiftId
|
|
53390
53198
|
});
|
|
53199
|
+
const modalShiftConfig = React24.useMemo(() => {
|
|
53200
|
+
if (!selectedWorkspace) return void 0;
|
|
53201
|
+
if (isFactoryView) {
|
|
53202
|
+
return shiftConfigMap.get(selectedWorkspace.line_id);
|
|
53203
|
+
}
|
|
53204
|
+
return loadedShiftConfig || void 0;
|
|
53205
|
+
}, [isFactoryView, loadedShiftConfig, selectedWorkspace, shiftConfigMap]);
|
|
53391
53206
|
const handleWorkspaceClick = React24.useCallback(
|
|
53392
53207
|
(workspace) => {
|
|
53393
53208
|
const url = `/workspace/${workspace.workspace_id}`;
|
|
@@ -53625,7 +53440,7 @@ var WorkspaceHealthView = ({
|
|
|
53625
53440
|
workspace: selectedWorkspace,
|
|
53626
53441
|
isOpen: Boolean(selectedWorkspace),
|
|
53627
53442
|
onClose: handleCloseDetails,
|
|
53628
|
-
shiftConfig:
|
|
53443
|
+
shiftConfig: modalShiftConfig,
|
|
53629
53444
|
date: selectedDate,
|
|
53630
53445
|
shiftId: selectedShiftId
|
|
53631
53446
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -49066,43 +49066,6 @@ var calculateShiftHours = (startTime, endTime, breaks = []) => {
|
|
|
49066
49066
|
const hoursDiff = (endMinutes - startMinutes - totalBreakMinutes) / 60;
|
|
49067
49067
|
return Number(hoursDiff.toFixed(1));
|
|
49068
49068
|
};
|
|
49069
|
-
var calculateBreakDuration2 = (startTime, endTime) => {
|
|
49070
|
-
const [startHour, startMinute] = startTime.split(":").map(Number);
|
|
49071
|
-
const [endHour, endMinute] = endTime.split(":").map(Number);
|
|
49072
|
-
let startMinutes = startHour * 60 + startMinute;
|
|
49073
|
-
let endMinutes = endHour * 60 + endMinute;
|
|
49074
|
-
if (endMinutes < startMinutes) {
|
|
49075
|
-
endMinutes += 24 * 60;
|
|
49076
|
-
}
|
|
49077
|
-
return endMinutes - startMinutes;
|
|
49078
|
-
};
|
|
49079
|
-
var parseBreaksFromDB = (dbBreaks) => {
|
|
49080
|
-
if (!dbBreaks) return [];
|
|
49081
|
-
if (Array.isArray(dbBreaks)) {
|
|
49082
|
-
return dbBreaks.map((breakItem) => ({
|
|
49083
|
-
startTime: breakItem.start || breakItem.startTime || "00:00",
|
|
49084
|
-
endTime: breakItem.end || breakItem.endTime || "00:00",
|
|
49085
|
-
duration: calculateBreakDuration2(
|
|
49086
|
-
breakItem.start || breakItem.startTime || "00:00",
|
|
49087
|
-
breakItem.end || breakItem.endTime || "00:00"
|
|
49088
|
-
),
|
|
49089
|
-
remarks: breakItem.remarks || breakItem.name || ""
|
|
49090
|
-
}));
|
|
49091
|
-
} else if (dbBreaks.breaks && Array.isArray(dbBreaks.breaks)) {
|
|
49092
|
-
return dbBreaks.breaks.map((breakItem) => ({
|
|
49093
|
-
startTime: breakItem.start || breakItem.startTime || "00:00",
|
|
49094
|
-
endTime: breakItem.end || breakItem.endTime || "00:00",
|
|
49095
|
-
duration: calculateBreakDuration2(
|
|
49096
|
-
breakItem.start || breakItem.startTime || "00:00",
|
|
49097
|
-
breakItem.end || breakItem.endTime || "00:00"
|
|
49098
|
-
),
|
|
49099
|
-
remarks: breakItem.remarks || breakItem.name || ""
|
|
49100
|
-
}));
|
|
49101
|
-
} else {
|
|
49102
|
-
console.warn("Unexpected breaks format:", dbBreaks);
|
|
49103
|
-
return [];
|
|
49104
|
-
}
|
|
49105
|
-
};
|
|
49106
49069
|
var getStoredLineState = (lineId) => {
|
|
49107
49070
|
try {
|
|
49108
49071
|
return JSON.parse(localStorage.getItem(`line_${lineId}_open`) || "false");
|
|
@@ -49394,16 +49357,9 @@ var ShiftsView = ({
|
|
|
49394
49357
|
() => lineIds.map((id3) => ({
|
|
49395
49358
|
id: id3,
|
|
49396
49359
|
name: lineNames[id3] || `Line ${id3.substring(0, 4)}`,
|
|
49397
|
-
|
|
49398
|
-
|
|
49399
|
-
|
|
49400
|
-
breaks: []
|
|
49401
|
-
},
|
|
49402
|
-
nightShift: {
|
|
49403
|
-
startTime: "20:00",
|
|
49404
|
-
endTime: "04:00",
|
|
49405
|
-
breaks: []
|
|
49406
|
-
},
|
|
49360
|
+
timezone: "Asia/Kolkata",
|
|
49361
|
+
shifts: [],
|
|
49362
|
+
// Will be populated from DB
|
|
49407
49363
|
isOpen: true,
|
|
49408
49364
|
isSaving: false,
|
|
49409
49365
|
saveSuccess: false
|
|
@@ -49441,58 +49397,37 @@ var ShiftsView = ({
|
|
|
49441
49397
|
setLoading(false);
|
|
49442
49398
|
return;
|
|
49443
49399
|
}
|
|
49444
|
-
const { data:
|
|
49445
|
-
if (
|
|
49446
|
-
console.error("Error fetching
|
|
49447
|
-
showToast("error", "Error loading
|
|
49448
|
-
setError("Failed to load
|
|
49449
|
-
return;
|
|
49450
|
-
}
|
|
49451
|
-
const { data: nightShiftOperatingHours, error: nightShiftError } = await supabase.from("line_operating_hours").select("line_id, start_time, end_time, breaks").eq("shift_id", 1).in("line_id", enabledLineIds);
|
|
49452
|
-
if (nightShiftError) {
|
|
49453
|
-
console.error("Error fetching night shift operating hours:", nightShiftError);
|
|
49454
|
-
showToast("error", "Error loading night shift data");
|
|
49455
|
-
setError("Failed to load night shift data");
|
|
49400
|
+
const { data: allShifts, error: shiftsError } = await supabase.from("line_operating_hours").select("line_id, shift_id, shift_name, start_time, end_time, breaks, timezone").in("line_id", enabledLineIds);
|
|
49401
|
+
if (shiftsError) {
|
|
49402
|
+
console.error("Error fetching shifts:", shiftsError);
|
|
49403
|
+
showToast("error", "Error loading shift data");
|
|
49404
|
+
setError("Failed to load shift data");
|
|
49456
49405
|
return;
|
|
49457
49406
|
}
|
|
49458
|
-
const
|
|
49459
|
-
|
|
49460
|
-
|
|
49461
|
-
|
|
49462
|
-
breaks: parseBreaksFromDB(item.breaks)
|
|
49463
|
-
};
|
|
49464
|
-
return map;
|
|
49407
|
+
const shiftsByLine = (allShifts || []).reduce((acc, row) => {
|
|
49408
|
+
if (!acc[row.line_id]) acc[row.line_id] = [];
|
|
49409
|
+
acc[row.line_id].push(row);
|
|
49410
|
+
return acc;
|
|
49465
49411
|
}, {});
|
|
49466
|
-
const
|
|
49467
|
-
|
|
49468
|
-
|
|
49469
|
-
|
|
49470
|
-
breaks: parseBreaksFromDB(item.breaks)
|
|
49471
|
-
};
|
|
49472
|
-
return map;
|
|
49412
|
+
const { data: linesData } = await supabase.from("lines").select("id, line_name").in("id", enabledLineIds);
|
|
49413
|
+
const lineNameMap = (linesData || []).reduce((acc, line) => {
|
|
49414
|
+
if (line.line_name) acc[line.id] = line.line_name;
|
|
49415
|
+
return acc;
|
|
49473
49416
|
}, {});
|
|
49474
49417
|
setLineConfigs((prev) => {
|
|
49475
49418
|
const enabledConfigs = prev.filter((config) => enabledLineIds.includes(config.id));
|
|
49476
49419
|
return enabledConfigs.map((config) => {
|
|
49477
|
-
const
|
|
49478
|
-
const
|
|
49479
|
-
const
|
|
49480
|
-
|
|
49481
|
-
|
|
49482
|
-
|
|
49483
|
-
|
|
49484
|
-
|
|
49485
|
-
|
|
49486
|
-
|
|
49487
|
-
|
|
49488
|
-
...newConfig.nightShift,
|
|
49489
|
-
...nightShiftHoursMap[lineId]
|
|
49490
|
-
};
|
|
49491
|
-
}
|
|
49492
|
-
if (newConfig.isOpen === void 0) {
|
|
49493
|
-
newConfig.isOpen = getStoredLineState(lineId);
|
|
49494
|
-
}
|
|
49495
|
-
return newConfig;
|
|
49420
|
+
const rows = shiftsByLine[config.id] || [];
|
|
49421
|
+
const builtConfig = buildShiftConfigFromOperatingHoursRows(rows);
|
|
49422
|
+
const lineName = lineNameMap[config.id] || lineNames[config.id] || `Line ${config.id.substring(0, 4)}`;
|
|
49423
|
+
const sortedShifts = [...builtConfig.shifts || []].sort((a, b) => a.shiftId - b.shiftId);
|
|
49424
|
+
return {
|
|
49425
|
+
...config,
|
|
49426
|
+
name: lineName,
|
|
49427
|
+
shifts: sortedShifts,
|
|
49428
|
+
timezone: builtConfig.timezone || config.timezone,
|
|
49429
|
+
isOpen: config.isOpen ?? getStoredLineState(config.id)
|
|
49430
|
+
};
|
|
49496
49431
|
});
|
|
49497
49432
|
});
|
|
49498
49433
|
setLoading(false);
|
|
@@ -49515,183 +49450,79 @@ var ShiftsView = ({
|
|
|
49515
49450
|
);
|
|
49516
49451
|
});
|
|
49517
49452
|
}, []);
|
|
49518
|
-
const
|
|
49519
|
-
setLineConfigs((prev) => prev.map((config) => {
|
|
49520
|
-
const typedConfig = config;
|
|
49521
|
-
if (typedConfig.id === lineId) {
|
|
49522
|
-
const updatedDayShift = { ...typedConfig.dayShift, startTime: value };
|
|
49523
|
-
return {
|
|
49524
|
-
...typedConfig,
|
|
49525
|
-
dayShift: updatedDayShift
|
|
49526
|
-
};
|
|
49527
|
-
}
|
|
49528
|
-
return typedConfig;
|
|
49529
|
-
}));
|
|
49530
|
-
}, []);
|
|
49531
|
-
const updateDayShiftEndTime = useCallback((lineId, value) => {
|
|
49532
|
-
setLineConfigs((prev) => prev.map((config) => {
|
|
49533
|
-
const typedConfig = config;
|
|
49534
|
-
if (typedConfig.id === lineId) {
|
|
49535
|
-
const updatedDayShift = { ...typedConfig.dayShift, endTime: value };
|
|
49536
|
-
return {
|
|
49537
|
-
...typedConfig,
|
|
49538
|
-
dayShift: updatedDayShift
|
|
49539
|
-
};
|
|
49540
|
-
}
|
|
49541
|
-
return typedConfig;
|
|
49542
|
-
}));
|
|
49543
|
-
}, []);
|
|
49544
|
-
const updateNightShiftStartTime = useCallback((lineId, value) => {
|
|
49545
|
-
setLineConfigs((prev) => prev.map((config) => {
|
|
49546
|
-
const typedConfig = config;
|
|
49547
|
-
if (typedConfig.id === lineId) {
|
|
49548
|
-
const updatedNightShift = { ...typedConfig.nightShift, startTime: value };
|
|
49549
|
-
return {
|
|
49550
|
-
...typedConfig,
|
|
49551
|
-
nightShift: updatedNightShift
|
|
49552
|
-
};
|
|
49553
|
-
}
|
|
49554
|
-
return typedConfig;
|
|
49555
|
-
}));
|
|
49556
|
-
}, []);
|
|
49557
|
-
const updateNightShiftEndTime = useCallback((lineId, value) => {
|
|
49453
|
+
const updateShiftTime = useCallback((lineId, shiftIndex, field, value) => {
|
|
49558
49454
|
setLineConfigs((prev) => prev.map((config) => {
|
|
49559
|
-
|
|
49560
|
-
|
|
49561
|
-
|
|
49562
|
-
|
|
49563
|
-
...typedConfig,
|
|
49564
|
-
nightShift: updatedNightShift
|
|
49565
|
-
};
|
|
49566
|
-
}
|
|
49567
|
-
return typedConfig;
|
|
49568
|
-
}));
|
|
49569
|
-
}, []);
|
|
49570
|
-
const addDayShiftBreak = useCallback((lineId) => {
|
|
49571
|
-
setLineConfigs((prev) => prev.map((config) => {
|
|
49572
|
-
const typedConfig = config;
|
|
49573
|
-
if (typedConfig.id === lineId) {
|
|
49574
|
-
const dayShift = { ...typedConfig.dayShift };
|
|
49575
|
-
const newBreak = {
|
|
49576
|
-
startTime: dayShift.startTime,
|
|
49577
|
-
endTime: dayShift.startTime,
|
|
49578
|
-
duration: 0,
|
|
49579
|
-
remarks: ""
|
|
49580
|
-
};
|
|
49581
|
-
return {
|
|
49582
|
-
...typedConfig,
|
|
49583
|
-
dayShift: {
|
|
49584
|
-
...dayShift,
|
|
49585
|
-
breaks: [...dayShift.breaks, newBreak]
|
|
49586
|
-
}
|
|
49587
|
-
};
|
|
49588
|
-
}
|
|
49589
|
-
return typedConfig;
|
|
49590
|
-
}));
|
|
49591
|
-
}, []);
|
|
49592
|
-
const addNightShiftBreak = useCallback((lineId) => {
|
|
49593
|
-
setLineConfigs((prev) => prev.map((config) => {
|
|
49594
|
-
const typedConfig = config;
|
|
49595
|
-
if (typedConfig.id === lineId) {
|
|
49596
|
-
const nightShift = { ...typedConfig.nightShift };
|
|
49597
|
-
const newBreak = {
|
|
49598
|
-
startTime: nightShift.startTime,
|
|
49599
|
-
endTime: nightShift.startTime,
|
|
49600
|
-
duration: 0
|
|
49601
|
-
};
|
|
49602
|
-
return {
|
|
49603
|
-
...typedConfig,
|
|
49604
|
-
nightShift: {
|
|
49605
|
-
...nightShift,
|
|
49606
|
-
breaks: [...nightShift.breaks, newBreak]
|
|
49607
|
-
}
|
|
49608
|
-
};
|
|
49609
|
-
}
|
|
49610
|
-
return typedConfig;
|
|
49611
|
-
}));
|
|
49612
|
-
}, []);
|
|
49613
|
-
const updateDayShiftBreak = useCallback((lineId, index, field, value) => {
|
|
49614
|
-
setLineConfigs((prev) => prev.map((config) => {
|
|
49615
|
-
const typedConfig = config;
|
|
49616
|
-
if (typedConfig.id === lineId) {
|
|
49617
|
-
const dayShift = { ...typedConfig.dayShift };
|
|
49618
|
-
const newBreaks = [...dayShift.breaks];
|
|
49619
|
-
newBreaks[index] = { ...newBreaks[index], [field]: value };
|
|
49620
|
-
if (field === "startTime" || field === "endTime") {
|
|
49621
|
-
const startParts = newBreaks[index].startTime.split(":").map(Number);
|
|
49622
|
-
const endParts = newBreaks[index].endTime.split(":").map(Number);
|
|
49623
|
-
let startMinutes = startParts[0] * 60 + startParts[1];
|
|
49624
|
-
let endMinutes = endParts[0] * 60 + endParts[1];
|
|
49625
|
-
if (endMinutes < startMinutes) {
|
|
49626
|
-
endMinutes += 24 * 60;
|
|
49627
|
-
}
|
|
49628
|
-
newBreaks[index].duration = endMinutes - startMinutes;
|
|
49455
|
+
if (config.id === lineId && config.shifts) {
|
|
49456
|
+
const newShifts = [...config.shifts];
|
|
49457
|
+
if (newShifts[shiftIndex]) {
|
|
49458
|
+
newShifts[shiftIndex] = { ...newShifts[shiftIndex], [field]: value };
|
|
49629
49459
|
}
|
|
49630
|
-
return {
|
|
49631
|
-
...typedConfig,
|
|
49632
|
-
dayShift: {
|
|
49633
|
-
...dayShift,
|
|
49634
|
-
breaks: newBreaks
|
|
49635
|
-
}
|
|
49636
|
-
};
|
|
49460
|
+
return { ...config, shifts: newShifts };
|
|
49637
49461
|
}
|
|
49638
|
-
return
|
|
49462
|
+
return config;
|
|
49639
49463
|
}));
|
|
49640
49464
|
}, []);
|
|
49641
|
-
const
|
|
49465
|
+
const addShiftBreak = useCallback((lineId, shiftIndex) => {
|
|
49642
49466
|
setLineConfigs((prev) => prev.map((config) => {
|
|
49643
|
-
|
|
49644
|
-
|
|
49645
|
-
|
|
49646
|
-
|
|
49647
|
-
|
|
49648
|
-
|
|
49649
|
-
|
|
49650
|
-
|
|
49651
|
-
|
|
49652
|
-
|
|
49653
|
-
|
|
49654
|
-
|
|
49655
|
-
|
|
49656
|
-
|
|
49467
|
+
if (config.id === lineId && config.shifts) {
|
|
49468
|
+
const newShifts = [...config.shifts];
|
|
49469
|
+
if (newShifts[shiftIndex]) {
|
|
49470
|
+
const shift = newShifts[shiftIndex];
|
|
49471
|
+
const newBreak = {
|
|
49472
|
+
startTime: shift.startTime,
|
|
49473
|
+
endTime: shift.startTime,
|
|
49474
|
+
duration: 0,
|
|
49475
|
+
remarks: ""
|
|
49476
|
+
};
|
|
49477
|
+
newShifts[shiftIndex] = {
|
|
49478
|
+
...shift,
|
|
49479
|
+
breaks: [...shift.breaks || [], newBreak]
|
|
49480
|
+
};
|
|
49657
49481
|
}
|
|
49658
|
-
return {
|
|
49659
|
-
...typedConfig,
|
|
49660
|
-
nightShift: {
|
|
49661
|
-
...nightShift,
|
|
49662
|
-
breaks: newBreaks
|
|
49663
|
-
}
|
|
49664
|
-
};
|
|
49482
|
+
return { ...config, shifts: newShifts };
|
|
49665
49483
|
}
|
|
49666
|
-
return
|
|
49484
|
+
return config;
|
|
49667
49485
|
}));
|
|
49668
49486
|
}, []);
|
|
49669
|
-
const
|
|
49487
|
+
const updateShiftBreak = useCallback((lineId, shiftIndex, breakIndex, field, value) => {
|
|
49670
49488
|
setLineConfigs((prev) => prev.map((config) => {
|
|
49671
|
-
if (config.id === lineId) {
|
|
49672
|
-
const
|
|
49673
|
-
|
|
49674
|
-
|
|
49675
|
-
|
|
49676
|
-
|
|
49677
|
-
|
|
49489
|
+
if (config.id === lineId && config.shifts) {
|
|
49490
|
+
const newShifts = [...config.shifts];
|
|
49491
|
+
if (newShifts[shiftIndex]) {
|
|
49492
|
+
const shift = newShifts[shiftIndex];
|
|
49493
|
+
const newBreaks = [...shift.breaks || []];
|
|
49494
|
+
if (newBreaks[breakIndex]) {
|
|
49495
|
+
newBreaks[breakIndex] = { ...newBreaks[breakIndex], [field]: value };
|
|
49496
|
+
if (field === "startTime" || field === "endTime") {
|
|
49497
|
+
const startParts = newBreaks[breakIndex].startTime.split(":").map(Number);
|
|
49498
|
+
const endParts = newBreaks[breakIndex].endTime.split(":").map(Number);
|
|
49499
|
+
let startMinutes = startParts[0] * 60 + startParts[1];
|
|
49500
|
+
let endMinutes = endParts[0] * 60 + endParts[1];
|
|
49501
|
+
if (endMinutes < startMinutes) {
|
|
49502
|
+
endMinutes += 24 * 60;
|
|
49503
|
+
}
|
|
49504
|
+
newBreaks[breakIndex].duration = endMinutes - startMinutes;
|
|
49505
|
+
}
|
|
49678
49506
|
}
|
|
49679
|
-
|
|
49507
|
+
newShifts[shiftIndex] = { ...shift, breaks: newBreaks };
|
|
49508
|
+
}
|
|
49509
|
+
return { ...config, shifts: newShifts };
|
|
49680
49510
|
}
|
|
49681
49511
|
return config;
|
|
49682
49512
|
}));
|
|
49683
49513
|
}, []);
|
|
49684
|
-
const
|
|
49514
|
+
const removeShiftBreak = useCallback((lineId, shiftIndex, breakIndex) => {
|
|
49685
49515
|
setLineConfigs((prev) => prev.map((config) => {
|
|
49686
|
-
if (config.id === lineId) {
|
|
49687
|
-
const
|
|
49688
|
-
|
|
49689
|
-
|
|
49690
|
-
|
|
49691
|
-
...
|
|
49692
|
-
breaks:
|
|
49693
|
-
}
|
|
49694
|
-
}
|
|
49516
|
+
if (config.id === lineId && config.shifts) {
|
|
49517
|
+
const newShifts = [...config.shifts];
|
|
49518
|
+
if (newShifts[shiftIndex]) {
|
|
49519
|
+
const shift = newShifts[shiftIndex];
|
|
49520
|
+
newShifts[shiftIndex] = {
|
|
49521
|
+
...shift,
|
|
49522
|
+
breaks: (shift.breaks || []).filter((_, i) => i !== breakIndex)
|
|
49523
|
+
};
|
|
49524
|
+
}
|
|
49525
|
+
return { ...config, shifts: newShifts };
|
|
49695
49526
|
}
|
|
49696
49527
|
return config;
|
|
49697
49528
|
}));
|
|
@@ -49705,36 +49536,26 @@ var ShiftsView = ({
|
|
|
49705
49536
|
if (!lineConfig) {
|
|
49706
49537
|
throw new Error("Line configuration not found");
|
|
49707
49538
|
}
|
|
49708
|
-
const
|
|
49709
|
-
|
|
49710
|
-
|
|
49711
|
-
|
|
49712
|
-
|
|
49713
|
-
|
|
49714
|
-
|
|
49715
|
-
|
|
49716
|
-
|
|
49717
|
-
|
|
49718
|
-
|
|
49719
|
-
|
|
49720
|
-
|
|
49721
|
-
|
|
49722
|
-
|
|
49723
|
-
|
|
49724
|
-
|
|
49725
|
-
if (dayResult.error) {
|
|
49726
|
-
throw new Error(`Failed to save day shift: ${dayResult.error.message}`);
|
|
49727
|
-
}
|
|
49728
|
-
const nightResult = await supabase.from("line_operating_hours").upsert(nightShiftData).select();
|
|
49729
|
-
if (nightResult.error) {
|
|
49730
|
-
throw new Error(`Failed to save night shift: ${nightResult.error.message}`);
|
|
49539
|
+
const allSavedRows = [];
|
|
49540
|
+
for (const shift of lineConfig.shifts || []) {
|
|
49541
|
+
const shiftData = {
|
|
49542
|
+
line_id: lineId,
|
|
49543
|
+
shift_id: shift.shiftId,
|
|
49544
|
+
shift_name: shift.shiftName,
|
|
49545
|
+
start_time: shift.startTime,
|
|
49546
|
+
end_time: shift.endTime,
|
|
49547
|
+
breaks: formatBreaks(shift.breaks || [])
|
|
49548
|
+
};
|
|
49549
|
+
const { data, error: error2 } = await supabase.from("line_operating_hours").upsert(shiftData).select();
|
|
49550
|
+
if (error2) {
|
|
49551
|
+
throw new Error(`Failed to save shift ${shift.shiftName}: ${error2.message}`);
|
|
49552
|
+
}
|
|
49553
|
+
if (data) {
|
|
49554
|
+
allSavedRows.push(...data);
|
|
49555
|
+
}
|
|
49731
49556
|
}
|
|
49732
|
-
|
|
49733
|
-
|
|
49734
|
-
...nightResult.data || []
|
|
49735
|
-
];
|
|
49736
|
-
if (updatedRows.length > 0) {
|
|
49737
|
-
shiftConfigStore.setFromOperatingHoursRows(lineId, updatedRows, shiftConfigStore.get(lineId));
|
|
49557
|
+
if (allSavedRows.length > 0) {
|
|
49558
|
+
shiftConfigStore.setFromOperatingHoursRows(lineId, allSavedRows, shiftConfigStore.get(lineId));
|
|
49738
49559
|
}
|
|
49739
49560
|
setLineConfigs((prev) => prev.map(
|
|
49740
49561
|
(config) => config.id === lineId ? { ...config, isSaving: false, saveSuccess: true } : config
|
|
@@ -49813,48 +49634,34 @@ var ShiftsView = ({
|
|
|
49813
49634
|
)
|
|
49814
49635
|
] })
|
|
49815
49636
|
] }) }),
|
|
49816
|
-
/* @__PURE__ */
|
|
49817
|
-
|
|
49818
|
-
|
|
49819
|
-
|
|
49820
|
-
|
|
49821
|
-
|
|
49822
|
-
|
|
49823
|
-
|
|
49824
|
-
|
|
49825
|
-
|
|
49826
|
-
|
|
49827
|
-
|
|
49828
|
-
|
|
49829
|
-
|
|
49830
|
-
|
|
49831
|
-
|
|
49832
|
-
|
|
49833
|
-
|
|
49834
|
-
|
|
49835
|
-
|
|
49836
|
-
|
|
49837
|
-
|
|
49838
|
-
|
|
49839
|
-
|
|
49840
|
-
|
|
49841
|
-
|
|
49842
|
-
|
|
49843
|
-
|
|
49844
|
-
breaks: config.nightShift.breaks,
|
|
49845
|
-
onStartTimeChange: (value) => updateNightShiftStartTime(config.id, value),
|
|
49846
|
-
onEndTimeChange: (value) => updateNightShiftEndTime(config.id, value),
|
|
49847
|
-
onBreakUpdate: (index, field, value) => updateNightShiftBreak(config.id, index, field, value),
|
|
49848
|
-
onBreakRemove: (index) => removeNightShiftBreak(config.id, index),
|
|
49849
|
-
onBreakAdd: () => addNightShiftBreak(config.id),
|
|
49850
|
-
shiftHours: calculateShiftHours(
|
|
49851
|
-
config.nightShift.startTime,
|
|
49852
|
-
config.nightShift.endTime,
|
|
49853
|
-
config.nightShift.breaks
|
|
49854
|
-
)
|
|
49855
|
-
}
|
|
49856
|
-
)
|
|
49857
|
-
] })
|
|
49637
|
+
/* @__PURE__ */ jsx("div", { id: `shift-panel-${config.id}`, className: "p-3 sm:p-4 md:p-6 border-t border-gray-200 w-full", children: config.shifts && config.shifts.length > 0 ? config.shifts.map((shift, shiftIndex) => /* @__PURE__ */ jsx(
|
|
49638
|
+
ShiftPanel,
|
|
49639
|
+
{
|
|
49640
|
+
title: shift.shiftName,
|
|
49641
|
+
icon: (
|
|
49642
|
+
// Icon based on shift name (case-insensitive)
|
|
49643
|
+
shift.shiftName.toLowerCase().includes("day") ? /* @__PURE__ */ jsx("svg", { className: "w-5 h-5 text-gray-600", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" }) }) : shift.shiftName.toLowerCase().includes("night") ? /* @__PURE__ */ jsx("svg", { className: "w-5 h-5 text-gray-600", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z" }) }) : /* @__PURE__ */ jsx(Clock, { className: "w-5 h-5 text-gray-600" })
|
|
49644
|
+
),
|
|
49645
|
+
startTime: shift.startTime,
|
|
49646
|
+
endTime: shift.endTime,
|
|
49647
|
+
breaks: shift.breaks || [],
|
|
49648
|
+
onStartTimeChange: (value) => updateShiftTime(config.id, shiftIndex, "startTime", value),
|
|
49649
|
+
onEndTimeChange: (value) => updateShiftTime(config.id, shiftIndex, "endTime", value),
|
|
49650
|
+
onBreakUpdate: (breakIndex, field, value) => updateShiftBreak(config.id, shiftIndex, breakIndex, field, value),
|
|
49651
|
+
onBreakRemove: (breakIndex) => removeShiftBreak(config.id, shiftIndex, breakIndex),
|
|
49652
|
+
onBreakAdd: () => addShiftBreak(config.id, shiftIndex),
|
|
49653
|
+
shiftHours: calculateShiftHours(
|
|
49654
|
+
shift.startTime,
|
|
49655
|
+
shift.endTime,
|
|
49656
|
+
shift.breaks || []
|
|
49657
|
+
)
|
|
49658
|
+
},
|
|
49659
|
+
shift.shiftId
|
|
49660
|
+
)) : /* @__PURE__ */ jsxs("div", { className: "text-center text-gray-500 py-8", children: [
|
|
49661
|
+
/* @__PURE__ */ jsx(Clock, { className: "w-12 h-12 mx-auto mb-3 text-gray-400" }),
|
|
49662
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm", children: "No shifts configured for this line" }),
|
|
49663
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-gray-400 mt-1", children: "Shifts will appear here once configured in the database" })
|
|
49664
|
+
] }) })
|
|
49858
49665
|
] }, config.id)) })
|
|
49859
49666
|
] })
|
|
49860
49667
|
] });
|
|
@@ -53346,8 +53153,9 @@ var WorkspaceHealthView = ({
|
|
|
53346
53153
|
loading,
|
|
53347
53154
|
error,
|
|
53348
53155
|
refetch,
|
|
53349
|
-
shiftConfig: loadedShiftConfig
|
|
53156
|
+
shiftConfig: loadedShiftConfig,
|
|
53350
53157
|
// Get shift config from the hook to pass to modal
|
|
53158
|
+
shiftConfigMap
|
|
53351
53159
|
} = useWorkspaceHealth({
|
|
53352
53160
|
lineId: effectiveLineIdForFetch,
|
|
53353
53161
|
// undefined in factory view = fetch all lines
|
|
@@ -53359,6 +53167,13 @@ var WorkspaceHealthView = ({
|
|
|
53359
53167
|
date: selectedDate,
|
|
53360
53168
|
shiftId: selectedShiftId
|
|
53361
53169
|
});
|
|
53170
|
+
const modalShiftConfig = useMemo(() => {
|
|
53171
|
+
if (!selectedWorkspace) return void 0;
|
|
53172
|
+
if (isFactoryView) {
|
|
53173
|
+
return shiftConfigMap.get(selectedWorkspace.line_id);
|
|
53174
|
+
}
|
|
53175
|
+
return loadedShiftConfig || void 0;
|
|
53176
|
+
}, [isFactoryView, loadedShiftConfig, selectedWorkspace, shiftConfigMap]);
|
|
53362
53177
|
const handleWorkspaceClick = useCallback(
|
|
53363
53178
|
(workspace) => {
|
|
53364
53179
|
const url = `/workspace/${workspace.workspace_id}`;
|
|
@@ -53596,7 +53411,7 @@ var WorkspaceHealthView = ({
|
|
|
53596
53411
|
workspace: selectedWorkspace,
|
|
53597
53412
|
isOpen: Boolean(selectedWorkspace),
|
|
53598
53413
|
onClose: handleCloseDetails,
|
|
53599
|
-
shiftConfig:
|
|
53414
|
+
shiftConfig: modalShiftConfig,
|
|
53600
53415
|
date: selectedDate,
|
|
53601
53416
|
shiftId: selectedShiftId
|
|
53602
53417
|
}
|