/* eslint-disable react/prop-types */ // @ts-ignore import { createContext, useState, useEffect, ReactNode } from "react"; import DomoApi from "./domoAPI"; export interface UserContextType { currentUser: string; currentUserId: string; avatarKey: string; customer: string; host: string; } export const UserContext = createContext( undefined ); export const UserProvider = ({ children }: { children: ReactNode }) => { const [currentUser, setCurrentUser] = useState(""); const [currentUserId, setCurrentUserId] = useState(""); const [avatarKey, setAvatarKey] = useState(""); const [customer, setCustomer] = useState(""); const [host, setHost] = useState(""); useEffect(() => { let isUserFetched = false; DomoApi.GetCurrentUser().then((data: any) => { // console.log("User Data",data); if (!isUserFetched) { const userId = data?.userId; const displayName = data?.displayName; const avatarKey = data?.avatarKey; const customer = data?.customer; const host = data?.host; setCurrentUser(displayName || ""); setCurrentUserId(userId || ""); setAvatarKey(avatarKey || ""); setCustomer(customer || ""); setHost(host || ""); isUserFetched = true; } }); return () => { isUserFetched = true; }; }, []); return ( {children} ); };