2
0

first commit

This commit is contained in:
2024-08-09 00:39:27 +02:00
commit 79688abe2e
5698 changed files with 497838 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
import { useState } from "react";
import { useAppContextWithSchema } from "@calcom/app-store/EventTypeAppContext";
import type { EventTypeAppCardApp } from "../types";
function useIsAppEnabled(app: EventTypeAppCardApp) {
const { getAppData, setAppData } = useAppContextWithSchema();
const [enabled, setEnabled] = useState(() => {
const isAppEnabled = getAppData("enabled");
if (!app.credentialOwner) {
return isAppEnabled ?? false; // Default to false if undefined
}
const credentialId = getAppData("credentialId");
const isAppEnabledForCredential =
isAppEnabled &&
(app.userCredentialIds.some((id) => id === credentialId) ||
app.credentialOwner.credentialId === credentialId);
return isAppEnabledForCredential ?? false; // Default to false if undefined
});
const updateEnabled = (newValue: boolean) => {
if (!newValue) {
setAppData("credentialId", undefined);
}
if (newValue && (app.userCredentialIds?.length || app.credentialOwner?.credentialId)) {
setAppData("credentialId", app.credentialOwner?.credentialId || app.userCredentialIds[0]);
}
setEnabled(newValue);
};
return { enabled, updateEnabled };
}
export default useIsAppEnabled;