@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.
Files changed (3) hide show
  1. package/dist/index.js +140 -325
  2. package/dist/index.mjs +140 -325
  3. 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
- dayShift: {
49427
- startTime: "08:00",
49428
- endTime: "16:00",
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: dayShiftOperatingHours, error: dayShiftError } = await supabase.from("line_operating_hours").select("line_id, start_time, end_time, breaks").eq("shift_id", 0).in("line_id", enabledLineIds);
49474
- if (dayShiftError) {
49475
- console.error("Error fetching day shift operating hours:", dayShiftError);
49476
- showToast("error", "Error loading day shift data");
49477
- setError("Failed to load day shift data");
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 dayShiftHoursMap = (dayShiftOperatingHours || []).reduce((map, item) => {
49488
- map[item.line_id] = {
49489
- startTime: item.start_time,
49490
- endTime: item.end_time,
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 nightShiftHoursMap = (nightShiftOperatingHours || []).reduce((map, item) => {
49496
- map[item.line_id] = {
49497
- startTime: item.start_time,
49498
- endTime: item.end_time,
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 typedConfig = config;
49507
- const lineId = typedConfig.id;
49508
- const newConfig = { ...typedConfig };
49509
- if (dayShiftHoursMap[lineId]) {
49510
- newConfig.dayShift = {
49511
- ...newConfig.dayShift,
49512
- ...dayShiftHoursMap[lineId]
49513
- };
49514
- }
49515
- if (nightShiftHoursMap[lineId]) {
49516
- newConfig.nightShift = {
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 updateDayShiftStartTime = React24.useCallback((lineId, value) => {
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
- const typedConfig = config;
49589
- if (typedConfig.id === lineId) {
49590
- const updatedNightShift = { ...typedConfig.nightShift, endTime: value };
49591
- return {
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 typedConfig;
49491
+ return config;
49668
49492
  }));
49669
49493
  }, []);
49670
- const updateNightShiftBreak = React24.useCallback((lineId, index, field, value) => {
49494
+ const addShiftBreak = React24.useCallback((lineId, shiftIndex) => {
49671
49495
  setLineConfigs((prev) => prev.map((config) => {
49672
- const typedConfig = config;
49673
- if (typedConfig.id === lineId) {
49674
- const nightShift = { ...typedConfig.nightShift };
49675
- const newBreaks = [...nightShift.breaks];
49676
- newBreaks[index] = { ...newBreaks[index], [field]: value };
49677
- if (field === "startTime" || field === "endTime") {
49678
- const startParts = newBreaks[index].startTime.split(":").map(Number);
49679
- const endParts = newBreaks[index].endTime.split(":").map(Number);
49680
- let startMinutes = startParts[0] * 60 + startParts[1];
49681
- let endMinutes = endParts[0] * 60 + endParts[1];
49682
- if (endMinutes < startMinutes) {
49683
- endMinutes += 24 * 60;
49684
- }
49685
- newBreaks[index].duration = endMinutes - startMinutes;
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 typedConfig;
49513
+ return config;
49696
49514
  }));
49697
49515
  }, []);
49698
- const removeDayShiftBreak = React24.useCallback((lineId, index) => {
49516
+ const updateShiftBreak = React24.useCallback((lineId, shiftIndex, breakIndex, field, value) => {
49699
49517
  setLineConfigs((prev) => prev.map((config) => {
49700
- if (config.id === lineId) {
49701
- const dayShift = { ...config.dayShift };
49702
- return {
49703
- ...config,
49704
- dayShift: {
49705
- ...dayShift,
49706
- breaks: dayShift.breaks.filter((_, i) => i !== index)
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 removeNightShiftBreak = React24.useCallback((lineId, index) => {
49543
+ const removeShiftBreak = React24.useCallback((lineId, shiftIndex, breakIndex) => {
49714
49544
  setLineConfigs((prev) => prev.map((config) => {
49715
- if (config.id === lineId) {
49716
- const nightShift = { ...config.nightShift };
49717
- return {
49718
- ...config,
49719
- nightShift: {
49720
- ...nightShift,
49721
- breaks: nightShift.breaks.filter((_, i) => i !== index)
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 dayShiftData = {
49738
- line_id: lineId,
49739
- shift_id: 0,
49740
- shift_name: "Day Shift",
49741
- start_time: lineConfig.dayShift.startTime,
49742
- end_time: lineConfig.dayShift.endTime,
49743
- breaks: formatBreaks(lineConfig.dayShift.breaks)
49744
- };
49745
- const nightShiftData = {
49746
- line_id: lineId,
49747
- shift_id: 1,
49748
- shift_name: "Night Shift",
49749
- start_time: lineConfig.nightShift.startTime,
49750
- end_time: lineConfig.nightShift.endTime,
49751
- breaks: formatBreaks(lineConfig.nightShift.breaks)
49752
- };
49753
- const dayResult = await supabase.from("line_operating_hours").upsert(dayShiftData).select();
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
- const updatedRows = [
49762
- ...dayResult.data || [],
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.jsxs("div", { id: `shift-panel-${config.id}`, className: "p-3 sm:p-4 md:p-6 border-t border-gray-200 w-full", children: [
49846
- /* @__PURE__ */ jsxRuntime.jsx(
49847
- ShiftPanel,
49848
- {
49849
- title: "Day Shift",
49850
- icon: /* @__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" }) }),
49851
- startTime: config.dayShift.startTime,
49852
- endTime: config.dayShift.endTime,
49853
- breaks: config.dayShift.breaks,
49854
- onStartTimeChange: (value) => updateDayShiftStartTime(config.id, value),
49855
- onEndTimeChange: (value) => updateDayShiftEndTime(config.id, value),
49856
- onBreakUpdate: (index, field, value) => updateDayShiftBreak(config.id, index, field, value),
49857
- onBreakRemove: (index) => removeDayShiftBreak(config.id, index),
49858
- onBreakAdd: () => addDayShiftBreak(config.id),
49859
- shiftHours: calculateShiftHours(
49860
- config.dayShift.startTime,
49861
- config.dayShift.endTime,
49862
- config.dayShift.breaks
49863
- )
49864
- }
49865
- ),
49866
- /* @__PURE__ */ jsxRuntime.jsx(
49867
- ShiftPanel,
49868
- {
49869
- title: "Night Shift",
49870
- icon: /* @__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" }) }),
49871
- startTime: config.nightShift.startTime,
49872
- endTime: config.nightShift.endTime,
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: loadedShiftConfig,
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
- dayShift: {
49398
- startTime: "08:00",
49399
- endTime: "16:00",
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: dayShiftOperatingHours, error: dayShiftError } = await supabase.from("line_operating_hours").select("line_id, start_time, end_time, breaks").eq("shift_id", 0).in("line_id", enabledLineIds);
49445
- if (dayShiftError) {
49446
- console.error("Error fetching day shift operating hours:", dayShiftError);
49447
- showToast("error", "Error loading day shift data");
49448
- setError("Failed to load day shift data");
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 dayShiftHoursMap = (dayShiftOperatingHours || []).reduce((map, item) => {
49459
- map[item.line_id] = {
49460
- startTime: item.start_time,
49461
- endTime: item.end_time,
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 nightShiftHoursMap = (nightShiftOperatingHours || []).reduce((map, item) => {
49467
- map[item.line_id] = {
49468
- startTime: item.start_time,
49469
- endTime: item.end_time,
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 typedConfig = config;
49478
- const lineId = typedConfig.id;
49479
- const newConfig = { ...typedConfig };
49480
- if (dayShiftHoursMap[lineId]) {
49481
- newConfig.dayShift = {
49482
- ...newConfig.dayShift,
49483
- ...dayShiftHoursMap[lineId]
49484
- };
49485
- }
49486
- if (nightShiftHoursMap[lineId]) {
49487
- newConfig.nightShift = {
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 updateDayShiftStartTime = useCallback((lineId, value) => {
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
- const typedConfig = config;
49560
- if (typedConfig.id === lineId) {
49561
- const updatedNightShift = { ...typedConfig.nightShift, endTime: value };
49562
- return {
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 typedConfig;
49462
+ return config;
49639
49463
  }));
49640
49464
  }, []);
49641
- const updateNightShiftBreak = useCallback((lineId, index, field, value) => {
49465
+ const addShiftBreak = useCallback((lineId, shiftIndex) => {
49642
49466
  setLineConfigs((prev) => prev.map((config) => {
49643
- const typedConfig = config;
49644
- if (typedConfig.id === lineId) {
49645
- const nightShift = { ...typedConfig.nightShift };
49646
- const newBreaks = [...nightShift.breaks];
49647
- newBreaks[index] = { ...newBreaks[index], [field]: value };
49648
- if (field === "startTime" || field === "endTime") {
49649
- const startParts = newBreaks[index].startTime.split(":").map(Number);
49650
- const endParts = newBreaks[index].endTime.split(":").map(Number);
49651
- let startMinutes = startParts[0] * 60 + startParts[1];
49652
- let endMinutes = endParts[0] * 60 + endParts[1];
49653
- if (endMinutes < startMinutes) {
49654
- endMinutes += 24 * 60;
49655
- }
49656
- newBreaks[index].duration = endMinutes - startMinutes;
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 typedConfig;
49484
+ return config;
49667
49485
  }));
49668
49486
  }, []);
49669
- const removeDayShiftBreak = useCallback((lineId, index) => {
49487
+ const updateShiftBreak = useCallback((lineId, shiftIndex, breakIndex, field, value) => {
49670
49488
  setLineConfigs((prev) => prev.map((config) => {
49671
- if (config.id === lineId) {
49672
- const dayShift = { ...config.dayShift };
49673
- return {
49674
- ...config,
49675
- dayShift: {
49676
- ...dayShift,
49677
- breaks: dayShift.breaks.filter((_, i) => i !== index)
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 removeNightShiftBreak = useCallback((lineId, index) => {
49514
+ const removeShiftBreak = useCallback((lineId, shiftIndex, breakIndex) => {
49685
49515
  setLineConfigs((prev) => prev.map((config) => {
49686
- if (config.id === lineId) {
49687
- const nightShift = { ...config.nightShift };
49688
- return {
49689
- ...config,
49690
- nightShift: {
49691
- ...nightShift,
49692
- breaks: nightShift.breaks.filter((_, i) => i !== index)
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 dayShiftData = {
49709
- line_id: lineId,
49710
- shift_id: 0,
49711
- shift_name: "Day Shift",
49712
- start_time: lineConfig.dayShift.startTime,
49713
- end_time: lineConfig.dayShift.endTime,
49714
- breaks: formatBreaks(lineConfig.dayShift.breaks)
49715
- };
49716
- const nightShiftData = {
49717
- line_id: lineId,
49718
- shift_id: 1,
49719
- shift_name: "Night Shift",
49720
- start_time: lineConfig.nightShift.startTime,
49721
- end_time: lineConfig.nightShift.endTime,
49722
- breaks: formatBreaks(lineConfig.nightShift.breaks)
49723
- };
49724
- const dayResult = await supabase.from("line_operating_hours").upsert(dayShiftData).select();
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
- const updatedRows = [
49733
- ...dayResult.data || [],
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__ */ jsxs("div", { id: `shift-panel-${config.id}`, className: "p-3 sm:p-4 md:p-6 border-t border-gray-200 w-full", children: [
49817
- /* @__PURE__ */ jsx(
49818
- ShiftPanel,
49819
- {
49820
- title: "Day Shift",
49821
- icon: /* @__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" }) }),
49822
- startTime: config.dayShift.startTime,
49823
- endTime: config.dayShift.endTime,
49824
- breaks: config.dayShift.breaks,
49825
- onStartTimeChange: (value) => updateDayShiftStartTime(config.id, value),
49826
- onEndTimeChange: (value) => updateDayShiftEndTime(config.id, value),
49827
- onBreakUpdate: (index, field, value) => updateDayShiftBreak(config.id, index, field, value),
49828
- onBreakRemove: (index) => removeDayShiftBreak(config.id, index),
49829
- onBreakAdd: () => addDayShiftBreak(config.id),
49830
- shiftHours: calculateShiftHours(
49831
- config.dayShift.startTime,
49832
- config.dayShift.endTime,
49833
- config.dayShift.breaks
49834
- )
49835
- }
49836
- ),
49837
- /* @__PURE__ */ jsx(
49838
- ShiftPanel,
49839
- {
49840
- title: "Night Shift",
49841
- icon: /* @__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" }) }),
49842
- startTime: config.nightShift.startTime,
49843
- endTime: config.nightShift.endTime,
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: loadedShiftConfig,
53414
+ shiftConfig: modalShiftConfig,
53600
53415
  date: selectedDate,
53601
53416
  shiftId: selectedShiftId
53602
53417
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optifye/dashboard-core",
3
- "version": "6.10.2",
3
+ "version": "6.10.3",
4
4
  "description": "Reusable UI & logic for Optifye dashboard",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",