@easyteam/auto-scheduler-modal-ui 0.1.0 → 0.1.1

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.d.cts CHANGED
@@ -272,7 +272,15 @@ type AutoSchedulerModalProps = {
272
272
  url: string;
273
273
  headers?: Record<string, string>;
274
274
  };
275
+ getTokenURLAndHeaders: {
276
+ url: string;
277
+ headers?: Record<string, string>;
278
+ };
275
279
  onSolution: (solution: ScheduleSolution) => Promise<void>;
280
+ /** When provided, fetches stored config for a location set to prefill the form */
281
+ getStoredConfigForLocations?: (locationIds: string[]) => AutoSchedulerModalConfig | null;
282
+ /** When provided, persists config after successful schedule creation */
283
+ persistConfigForLocations?: (locationIds: string[], config: AutoSchedulerModalConfig) => void;
276
284
  };
277
285
  type Screen = "configure" | "creating" | "failed";
278
286
  type StepStatus = "pending" | "active" | "done";
@@ -393,7 +401,7 @@ type ScheduleRecommendation = {
393
401
  why_this_resolves_it: string;
394
402
  };
395
403
 
396
- declare function AutoSchedulerModal({ baseURL, isOpen, title, bannerText, jurisdictions, openShifts, employees, timeOffs, locationPlaceholder, onClose, cancelLabel, primaryActionLabel, onPrimaryAction: _onPrimaryAction, onFixManually, initialConfig, theme, cssVarsRoot, generateRecommendationsURLAndHeaders, onSolution, }: AutoSchedulerModalProps): react_jsx_runtime.JSX.Element;
404
+ declare function AutoSchedulerModal({ baseURL, isOpen, title, bannerText, jurisdictions, openShifts, employees, timeOffs, locationPlaceholder, onClose, cancelLabel, primaryActionLabel, onPrimaryAction: _onPrimaryAction, onFixManually, initialConfig, theme, cssVarsRoot, generateRecommendationsURLAndHeaders, getTokenURLAndHeaders, onSolution, getStoredConfigForLocations, persistConfigForLocations, }: AutoSchedulerModalProps): react_jsx_runtime.JSX.Element;
397
405
 
398
406
  /**
399
407
  * Self-contained AutoSchedulerModal that wraps itself in ChakraProvider.
package/dist/index.d.ts CHANGED
@@ -272,7 +272,15 @@ type AutoSchedulerModalProps = {
272
272
  url: string;
273
273
  headers?: Record<string, string>;
274
274
  };
275
+ getTokenURLAndHeaders: {
276
+ url: string;
277
+ headers?: Record<string, string>;
278
+ };
275
279
  onSolution: (solution: ScheduleSolution) => Promise<void>;
280
+ /** When provided, fetches stored config for a location set to prefill the form */
281
+ getStoredConfigForLocations?: (locationIds: string[]) => AutoSchedulerModalConfig | null;
282
+ /** When provided, persists config after successful schedule creation */
283
+ persistConfigForLocations?: (locationIds: string[], config: AutoSchedulerModalConfig) => void;
276
284
  };
277
285
  type Screen = "configure" | "creating" | "failed";
278
286
  type StepStatus = "pending" | "active" | "done";
@@ -393,7 +401,7 @@ type ScheduleRecommendation = {
393
401
  why_this_resolves_it: string;
394
402
  };
395
403
 
396
- declare function AutoSchedulerModal({ baseURL, isOpen, title, bannerText, jurisdictions, openShifts, employees, timeOffs, locationPlaceholder, onClose, cancelLabel, primaryActionLabel, onPrimaryAction: _onPrimaryAction, onFixManually, initialConfig, theme, cssVarsRoot, generateRecommendationsURLAndHeaders, onSolution, }: AutoSchedulerModalProps): react_jsx_runtime.JSX.Element;
404
+ declare function AutoSchedulerModal({ baseURL, isOpen, title, bannerText, jurisdictions, openShifts, employees, timeOffs, locationPlaceholder, onClose, cancelLabel, primaryActionLabel, onPrimaryAction: _onPrimaryAction, onFixManually, initialConfig, theme, cssVarsRoot, generateRecommendationsURLAndHeaders, getTokenURLAndHeaders, onSolution, getStoredConfigForLocations, persistConfigForLocations, }: AutoSchedulerModalProps): react_jsx_runtime.JSX.Element;
397
405
 
398
406
  /**
399
407
  * Self-contained AutoSchedulerModal that wraps itself in ChakraProvider.
package/dist/index.js CHANGED
@@ -1421,14 +1421,29 @@ function buildSchedulePayload(input) {
1421
1421
  };
1422
1422
  }
1423
1423
 
1424
- // src/api/solveSchedule.ts
1424
+ // src/api/api.ts
1425
1425
  import axios from "axios";
1426
1426
  var axiosInstance = axios.create({
1427
1427
  headers: { "Content-Type": "application/json" }
1428
1428
  });
1429
- async function solveSchedule(baseURL, payload) {
1429
+ async function getToken(fullUrl, headers) {
1430
+ var _a;
1431
+ const tokenRes = await axiosInstance.get(fullUrl, {
1432
+ ...headers ? { headers } : {}
1433
+ });
1434
+ return (_a = tokenRes.data) == null ? void 0 : _a.token;
1435
+ }
1436
+ async function solveSchedule(baseURL, payload, options) {
1430
1437
  const cleanBaseUrl = baseURL.replace(/\/$/, "");
1431
- const response = await axiosInstance.post(`${cleanBaseUrl}/api/schedule/solve`, payload);
1438
+ const headers = {};
1439
+ if (options == null ? void 0 : options.authorization) {
1440
+ headers.Authorization = options.authorization;
1441
+ }
1442
+ const response = await axiosInstance.post(
1443
+ `${cleanBaseUrl}/api/schedule/solve`,
1444
+ payload,
1445
+ { headers: Object.keys(headers).length > 0 ? headers : void 0 }
1446
+ );
1432
1447
  return response.data;
1433
1448
  }
1434
1449
 
@@ -1791,7 +1806,10 @@ function AutoSchedulerModal({
1791
1806
  theme,
1792
1807
  cssVarsRoot,
1793
1808
  generateRecommendationsURLAndHeaders,
1794
- onSolution
1809
+ getTokenURLAndHeaders,
1810
+ onSolution,
1811
+ getStoredConfigForLocations,
1812
+ persistConfigForLocations
1795
1813
  }) {
1796
1814
  const baseTheme = useTheme();
1797
1815
  const { chakraOverride, styleOverrides } = useMemo2(
@@ -1909,6 +1927,23 @@ function AutoSchedulerModal({
1909
1927
  setScreen("configure");
1910
1928
  }
1911
1929
  }, [isOpen, initialConfig]);
1930
+ useEffect(() => {
1931
+ if (selectedLocationIds.length === 0 || initialConfig || !getStoredConfigForLocations) {
1932
+ return;
1933
+ }
1934
+ const stored = getStoredConfigForLocations(selectedLocationIds);
1935
+ if (stored) {
1936
+ setSelectedConstraintIds(stored.selectedConstraintIds);
1937
+ setConstraintValues(stored.constraintValues);
1938
+ setSelectedOptimizationIds(stored.selectedOptimizationIds);
1939
+ setOptimizationValues(stored.optimizationValues);
1940
+ } else {
1941
+ setSelectedConstraintIds([]);
1942
+ setConstraintValues({});
1943
+ setSelectedOptimizationIds([]);
1944
+ setOptimizationValues({});
1945
+ }
1946
+ }, [selectedLocationIds, initialConfig, getStoredConfigForLocations]);
1912
1947
  useEffect(() => () => clearTimers(), []);
1913
1948
  const stepStatusForIndex = (index) => {
1914
1949
  if (index <= completedStepIndex) {
@@ -1985,14 +2020,30 @@ function AutoSchedulerModal({
1985
2020
  selectedOptimizationIds,
1986
2021
  optimizationValues
1987
2022
  });
1988
- const solvePromise = solveSchedule(baseURL, payload);
2023
+ persistConfigForLocations == null ? void 0 : persistConfigForLocations(selectedLocationIds, {
2024
+ selectedLocationIds,
2025
+ selectedConstraintIds,
2026
+ constraintValues,
2027
+ selectedOptimizationIds,
2028
+ optimizationValues
2029
+ });
1989
2030
  const runId = resetBeforeSubmit();
1990
2031
  schedule(STEP_INTERVAL_MS, async () => {
1991
2032
  var _a, _b;
1992
2033
  setCompletedStepIndex(0);
1993
2034
  setActiveStepIndex(1);
1994
2035
  try {
1995
- const response = await solvePromise;
2036
+ const token = await getToken(getTokenURLAndHeaders.url, getTokenURLAndHeaders.headers);
2037
+ if (!token) {
2038
+ throw new Error("Failed to get auto-scheduler token");
2039
+ }
2040
+ const response = await solveSchedule(
2041
+ baseURL,
2042
+ payload,
2043
+ {
2044
+ authorization: `Bearer ${token}`
2045
+ }
2046
+ );
1996
2047
  if (runIdRef.current !== runId) {
1997
2048
  return;
1998
2049
  }