@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.cjs CHANGED
@@ -1437,14 +1437,29 @@ function buildSchedulePayload(input) {
1437
1437
  };
1438
1438
  }
1439
1439
 
1440
- // src/api/solveSchedule.ts
1440
+ // src/api/api.ts
1441
1441
  var import_axios = __toESM(require("axios"), 1);
1442
1442
  var axiosInstance = import_axios.default.create({
1443
1443
  headers: { "Content-Type": "application/json" }
1444
1444
  });
1445
- async function solveSchedule(baseURL, payload) {
1445
+ async function getToken(fullUrl, headers) {
1446
+ var _a;
1447
+ const tokenRes = await axiosInstance.get(fullUrl, {
1448
+ ...headers ? { headers } : {}
1449
+ });
1450
+ return (_a = tokenRes.data) == null ? void 0 : _a.token;
1451
+ }
1452
+ async function solveSchedule(baseURL, payload, options) {
1446
1453
  const cleanBaseUrl = baseURL.replace(/\/$/, "");
1447
- const response = await axiosInstance.post(`${cleanBaseUrl}/api/schedule/solve`, payload);
1454
+ const headers = {};
1455
+ if (options == null ? void 0 : options.authorization) {
1456
+ headers.Authorization = options.authorization;
1457
+ }
1458
+ const response = await axiosInstance.post(
1459
+ `${cleanBaseUrl}/api/schedule/solve`,
1460
+ payload,
1461
+ { headers: Object.keys(headers).length > 0 ? headers : void 0 }
1462
+ );
1448
1463
  return response.data;
1449
1464
  }
1450
1465
 
@@ -1799,7 +1814,10 @@ function AutoSchedulerModal({
1799
1814
  theme,
1800
1815
  cssVarsRoot,
1801
1816
  generateRecommendationsURLAndHeaders,
1802
- onSolution
1817
+ getTokenURLAndHeaders,
1818
+ onSolution,
1819
+ getStoredConfigForLocations,
1820
+ persistConfigForLocations
1803
1821
  }) {
1804
1822
  const baseTheme = (0, import_react4.useTheme)();
1805
1823
  const { chakraOverride, styleOverrides } = (0, import_react3.useMemo)(
@@ -1917,6 +1935,23 @@ function AutoSchedulerModal({
1917
1935
  setScreen("configure");
1918
1936
  }
1919
1937
  }, [isOpen, initialConfig]);
1938
+ (0, import_react3.useEffect)(() => {
1939
+ if (selectedLocationIds.length === 0 || initialConfig || !getStoredConfigForLocations) {
1940
+ return;
1941
+ }
1942
+ const stored = getStoredConfigForLocations(selectedLocationIds);
1943
+ if (stored) {
1944
+ setSelectedConstraintIds(stored.selectedConstraintIds);
1945
+ setConstraintValues(stored.constraintValues);
1946
+ setSelectedOptimizationIds(stored.selectedOptimizationIds);
1947
+ setOptimizationValues(stored.optimizationValues);
1948
+ } else {
1949
+ setSelectedConstraintIds([]);
1950
+ setConstraintValues({});
1951
+ setSelectedOptimizationIds([]);
1952
+ setOptimizationValues({});
1953
+ }
1954
+ }, [selectedLocationIds, initialConfig, getStoredConfigForLocations]);
1920
1955
  (0, import_react3.useEffect)(() => () => clearTimers(), []);
1921
1956
  const stepStatusForIndex = (index) => {
1922
1957
  if (index <= completedStepIndex) {
@@ -1993,14 +2028,30 @@ function AutoSchedulerModal({
1993
2028
  selectedOptimizationIds,
1994
2029
  optimizationValues
1995
2030
  });
1996
- const solvePromise = solveSchedule(baseURL, payload);
2031
+ persistConfigForLocations == null ? void 0 : persistConfigForLocations(selectedLocationIds, {
2032
+ selectedLocationIds,
2033
+ selectedConstraintIds,
2034
+ constraintValues,
2035
+ selectedOptimizationIds,
2036
+ optimizationValues
2037
+ });
1997
2038
  const runId = resetBeforeSubmit();
1998
2039
  schedule(STEP_INTERVAL_MS, async () => {
1999
2040
  var _a, _b;
2000
2041
  setCompletedStepIndex(0);
2001
2042
  setActiveStepIndex(1);
2002
2043
  try {
2003
- const response = await solvePromise;
2044
+ const token = await getToken(getTokenURLAndHeaders.url, getTokenURLAndHeaders.headers);
2045
+ if (!token) {
2046
+ throw new Error("Failed to get auto-scheduler token");
2047
+ }
2048
+ const response = await solveSchedule(
2049
+ baseURL,
2050
+ payload,
2051
+ {
2052
+ authorization: `Bearer ${token}`
2053
+ }
2054
+ );
2004
2055
  if (runIdRef.current !== runId) {
2005
2056
  return;
2006
2057
  }