@propknot/shared-ui 1.0.5 → 1.0.7

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 CHANGED
@@ -1545,21 +1545,39 @@ var CustomThemeProvider = ({ children }) => {
1545
1545
  const [currentTheme, setCurrentTheme] = (0, import_react3.useState)("light");
1546
1546
  const [loading, setLoading] = (0, import_react3.useState)(false);
1547
1547
  const { user, companyBranding } = useAuth();
1548
+ const isEmbedded = new URLSearchParams(window.location.search).get("embedded") === "true";
1548
1549
  const canModifyTheme = Boolean(user && (user.role === "admin" || user.role === "owner" || user.role === "property_manager" || user.role === "maintenance"));
1549
1550
  (0, import_react3.useEffect)(() => {
1551
+ if (!isEmbedded) return;
1552
+ const handleMessage = (event) => {
1553
+ if (!event.origin.startsWith("http://localhost:")) return;
1554
+ const { type, theme } = event.data;
1555
+ if (type === "THEME_CHANGE" && theme && ["light", "dark"].includes(theme)) {
1556
+ console.log("Embedded app received theme change:", theme);
1557
+ setCurrentTheme(theme);
1558
+ }
1559
+ };
1560
+ window.addEventListener("message", handleMessage);
1561
+ if (window.parent !== window) {
1562
+ window.parent.postMessage({ type: "REQUEST_THEME" }, "*");
1563
+ }
1564
+ return () => window.removeEventListener("message", handleMessage);
1565
+ }, [isEmbedded]);
1566
+ (0, import_react3.useEffect)(() => {
1567
+ if (isEmbedded) return;
1550
1568
  if (user && canModifyTheme) {
1551
1569
  const themeToUse = user.themePreference || "light";
1552
1570
  setCurrentTheme(themeToUse);
1553
1571
  } else {
1554
1572
  setCurrentTheme("light");
1555
1573
  }
1556
- }, [user, canModifyTheme]);
1574
+ }, [user, canModifyTheme, isEmbedded]);
1557
1575
  const toggleTheme = async () => {
1558
1576
  if (!canModifyTheme) return;
1559
1577
  const newTheme = currentTheme === "light" ? "dark" : "light";
1560
1578
  setCurrentTheme(newTheme);
1561
1579
  try {
1562
- await api_default.put("/auth/theme-preference", { themePreference: newTheme });
1580
+ await api_default.put("/users/me", { themePreference: newTheme });
1563
1581
  } catch (error) {
1564
1582
  console.error("Failed to save theme preference:", error);
1565
1583
  setCurrentTheme(currentTheme);
@@ -1569,7 +1587,7 @@ var CustomThemeProvider = ({ children }) => {
1569
1587
  if (!canModifyTheme || !["light", "dark"].includes(themeKey)) return;
1570
1588
  setCurrentTheme(themeKey);
1571
1589
  try {
1572
- await api_default.put("/auth/theme-preference", { themePreference: themeKey });
1590
+ await api_default.put("/users/me", { themePreference: themeKey });
1573
1591
  } catch (error) {
1574
1592
  console.error("Failed to save theme preference:", error);
1575
1593
  setCurrentTheme(currentTheme);
@@ -1579,7 +1597,7 @@ var CustomThemeProvider = ({ children }) => {
1579
1597
  if (!canModifyTheme) return;
1580
1598
  setCurrentTheme("light");
1581
1599
  try {
1582
- await api_default.put("/auth/theme-preference", { themePreference: "light" });
1600
+ await api_default.put("/users/me", { themePreference: "light" });
1583
1601
  } catch (error) {
1584
1602
  console.error("Failed to save theme preference:", error);
1585
1603
  setCurrentTheme(currentTheme);
package/dist/index.mjs CHANGED
@@ -1481,21 +1481,39 @@ var CustomThemeProvider = ({ children }) => {
1481
1481
  const [currentTheme, setCurrentTheme] = useState3("light");
1482
1482
  const [loading, setLoading] = useState3(false);
1483
1483
  const { user, companyBranding } = useAuth();
1484
+ const isEmbedded = new URLSearchParams(window.location.search).get("embedded") === "true";
1484
1485
  const canModifyTheme = Boolean(user && (user.role === "admin" || user.role === "owner" || user.role === "property_manager" || user.role === "maintenance"));
1485
1486
  useEffect2(() => {
1487
+ if (!isEmbedded) return;
1488
+ const handleMessage = (event) => {
1489
+ if (!event.origin.startsWith("http://localhost:")) return;
1490
+ const { type, theme } = event.data;
1491
+ if (type === "THEME_CHANGE" && theme && ["light", "dark"].includes(theme)) {
1492
+ console.log("Embedded app received theme change:", theme);
1493
+ setCurrentTheme(theme);
1494
+ }
1495
+ };
1496
+ window.addEventListener("message", handleMessage);
1497
+ if (window.parent !== window) {
1498
+ window.parent.postMessage({ type: "REQUEST_THEME" }, "*");
1499
+ }
1500
+ return () => window.removeEventListener("message", handleMessage);
1501
+ }, [isEmbedded]);
1502
+ useEffect2(() => {
1503
+ if (isEmbedded) return;
1486
1504
  if (user && canModifyTheme) {
1487
1505
  const themeToUse = user.themePreference || "light";
1488
1506
  setCurrentTheme(themeToUse);
1489
1507
  } else {
1490
1508
  setCurrentTheme("light");
1491
1509
  }
1492
- }, [user, canModifyTheme]);
1510
+ }, [user, canModifyTheme, isEmbedded]);
1493
1511
  const toggleTheme = async () => {
1494
1512
  if (!canModifyTheme) return;
1495
1513
  const newTheme = currentTheme === "light" ? "dark" : "light";
1496
1514
  setCurrentTheme(newTheme);
1497
1515
  try {
1498
- await api_default.put("/auth/theme-preference", { themePreference: newTheme });
1516
+ await api_default.put("/users/me", { themePreference: newTheme });
1499
1517
  } catch (error) {
1500
1518
  console.error("Failed to save theme preference:", error);
1501
1519
  setCurrentTheme(currentTheme);
@@ -1505,7 +1523,7 @@ var CustomThemeProvider = ({ children }) => {
1505
1523
  if (!canModifyTheme || !["light", "dark"].includes(themeKey)) return;
1506
1524
  setCurrentTheme(themeKey);
1507
1525
  try {
1508
- await api_default.put("/auth/theme-preference", { themePreference: themeKey });
1526
+ await api_default.put("/users/me", { themePreference: themeKey });
1509
1527
  } catch (error) {
1510
1528
  console.error("Failed to save theme preference:", error);
1511
1529
  setCurrentTheme(currentTheme);
@@ -1515,7 +1533,7 @@ var CustomThemeProvider = ({ children }) => {
1515
1533
  if (!canModifyTheme) return;
1516
1534
  setCurrentTheme("light");
1517
1535
  try {
1518
- await api_default.put("/auth/theme-preference", { themePreference: "light" });
1536
+ await api_default.put("/users/me", { themePreference: "light" });
1519
1537
  } catch (error) {
1520
1538
  console.error("Failed to save theme preference:", error);
1521
1539
  setCurrentTheme(currentTheme);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@propknot/shared-ui",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "files": [