@propknot/shared-ui 1.0.8 → 1.0.10
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 +24 -0
- package/dist/index.mjs +24 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -328,6 +328,7 @@ var AuthProvider = ({ children }) => {
|
|
|
328
328
|
const [user, setUser] = (0, import_react.useState)(null);
|
|
329
329
|
const [companyBranding, setCompanyBranding] = (0, import_react.useState)(null);
|
|
330
330
|
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
331
|
+
const [needsOnboarding, setNeedsOnboarding] = (0, import_react.useState)(false);
|
|
331
332
|
(0, import_react.useEffect)(() => {
|
|
332
333
|
const token = localStorage.getItem("token");
|
|
333
334
|
const isValidToken = token && token !== "null" && token !== "undefined" && token !== "" && token.length > 20 && token.split(".").length === 3;
|
|
@@ -355,6 +356,9 @@ var AuthProvider = ({ children }) => {
|
|
|
355
356
|
}
|
|
356
357
|
};
|
|
357
358
|
setUser(normalizedUser);
|
|
359
|
+
const isOwnerRole = ["owner", "admin", "super_admin"].includes(normalizedUser.role);
|
|
360
|
+
const hasNoCompany = !normalizedUser.company;
|
|
361
|
+
setNeedsOnboarding(isOwnerRole && hasNoCompany);
|
|
358
362
|
if (normalizedUser.role === "property_manager" || normalizedUser.role === "maintenance") {
|
|
359
363
|
try {
|
|
360
364
|
const brandingResponse = await api_default.get("/auth/company-branding");
|
|
@@ -404,16 +408,36 @@ var AuthProvider = ({ children }) => {
|
|
|
404
408
|
const updateUser = (updatedUser) => {
|
|
405
409
|
setUser(updatedUser);
|
|
406
410
|
};
|
|
411
|
+
const completeOnboarding = async (companyData) => {
|
|
412
|
+
var _a, _b, _c;
|
|
413
|
+
try {
|
|
414
|
+
const response = await api_default.post("/companies/onboard", companyData);
|
|
415
|
+
if (response.data.success) {
|
|
416
|
+
setUser(response.data.data.user);
|
|
417
|
+
setNeedsOnboarding(false);
|
|
418
|
+
return { success: true, data: response.data.data };
|
|
419
|
+
}
|
|
420
|
+
return { success: false, error: "Onboarding failed" };
|
|
421
|
+
} catch (error) {
|
|
422
|
+
console.error("Onboarding failed:", error);
|
|
423
|
+
return {
|
|
424
|
+
success: false,
|
|
425
|
+
error: ((_c = (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.error) == null ? void 0 : _c.message) || "Onboarding failed"
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
};
|
|
407
429
|
const value = {
|
|
408
430
|
user,
|
|
409
431
|
isAuthenticated: !!user,
|
|
410
432
|
companyBranding,
|
|
411
433
|
managerBranding: companyBranding,
|
|
412
434
|
// Keep old name for backward compatibility
|
|
435
|
+
needsOnboarding,
|
|
413
436
|
login,
|
|
414
437
|
logout,
|
|
415
438
|
refreshUser,
|
|
416
439
|
updateUser,
|
|
440
|
+
completeOnboarding,
|
|
417
441
|
isLoading
|
|
418
442
|
};
|
|
419
443
|
return /* @__PURE__ */ import_react.default.createElement(AuthContext.Provider, { value }, children);
|
package/dist/index.mjs
CHANGED
|
@@ -263,6 +263,7 @@ var AuthProvider = ({ children }) => {
|
|
|
263
263
|
const [user, setUser] = useState(null);
|
|
264
264
|
const [companyBranding, setCompanyBranding] = useState(null);
|
|
265
265
|
const [isLoading, setIsLoading] = useState(true);
|
|
266
|
+
const [needsOnboarding, setNeedsOnboarding] = useState(false);
|
|
266
267
|
useEffect(() => {
|
|
267
268
|
const token = localStorage.getItem("token");
|
|
268
269
|
const isValidToken = token && token !== "null" && token !== "undefined" && token !== "" && token.length > 20 && token.split(".").length === 3;
|
|
@@ -290,6 +291,9 @@ var AuthProvider = ({ children }) => {
|
|
|
290
291
|
}
|
|
291
292
|
};
|
|
292
293
|
setUser(normalizedUser);
|
|
294
|
+
const isOwnerRole = ["owner", "admin", "super_admin"].includes(normalizedUser.role);
|
|
295
|
+
const hasNoCompany = !normalizedUser.company;
|
|
296
|
+
setNeedsOnboarding(isOwnerRole && hasNoCompany);
|
|
293
297
|
if (normalizedUser.role === "property_manager" || normalizedUser.role === "maintenance") {
|
|
294
298
|
try {
|
|
295
299
|
const brandingResponse = await api_default.get("/auth/company-branding");
|
|
@@ -339,16 +343,36 @@ var AuthProvider = ({ children }) => {
|
|
|
339
343
|
const updateUser = (updatedUser) => {
|
|
340
344
|
setUser(updatedUser);
|
|
341
345
|
};
|
|
346
|
+
const completeOnboarding = async (companyData) => {
|
|
347
|
+
var _a, _b, _c;
|
|
348
|
+
try {
|
|
349
|
+
const response = await api_default.post("/companies/onboard", companyData);
|
|
350
|
+
if (response.data.success) {
|
|
351
|
+
setUser(response.data.data.user);
|
|
352
|
+
setNeedsOnboarding(false);
|
|
353
|
+
return { success: true, data: response.data.data };
|
|
354
|
+
}
|
|
355
|
+
return { success: false, error: "Onboarding failed" };
|
|
356
|
+
} catch (error) {
|
|
357
|
+
console.error("Onboarding failed:", error);
|
|
358
|
+
return {
|
|
359
|
+
success: false,
|
|
360
|
+
error: ((_c = (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.error) == null ? void 0 : _c.message) || "Onboarding failed"
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
};
|
|
342
364
|
const value = {
|
|
343
365
|
user,
|
|
344
366
|
isAuthenticated: !!user,
|
|
345
367
|
companyBranding,
|
|
346
368
|
managerBranding: companyBranding,
|
|
347
369
|
// Keep old name for backward compatibility
|
|
370
|
+
needsOnboarding,
|
|
348
371
|
login,
|
|
349
372
|
logout,
|
|
350
373
|
refreshUser,
|
|
351
374
|
updateUser,
|
|
375
|
+
completeOnboarding,
|
|
352
376
|
isLoading
|
|
353
377
|
};
|
|
354
378
|
return /* @__PURE__ */ React2.createElement(AuthContext.Provider, { value }, children);
|