nit changes

feat/alby
Alan 2023-09-25 14:18:18 -07:00
parent f8caf08ccf
commit af1030abc0
4 changed files with 21 additions and 27 deletions

View File

@ -125,4 +125,11 @@ SALESFORCE_CONSUMER_SECRET=""
ZOHOCRM_CLIENT_ID="" ZOHOCRM_CLIENT_ID=""
ZOHOCRM_CLIENT_SECRET="" ZOHOCRM_CLIENT_SECRET=""
# ALBY
# Used for the Alby payment app / receiving Alby payments
# Get it from: https://getalby.com/developer/oauth_clients
# Set callbackUrl to /api/integrations/alby/alby-webhooks
NEXT_PUBLIC_ALBY_CLIENT_ID=""
NEXT_PUBLIC_ALBY_CLIENT_SECRET=""
# ********************************************************************************************************* # *********************************************************************************************************

View File

@ -230,12 +230,6 @@ AUTH_BEARER_TOKEN_VERCEL=
E2E_TEST_APPLE_CALENDAR_EMAIL="" E2E_TEST_APPLE_CALENDAR_EMAIL=""
E2E_TEST_APPLE_CALENDAR_PASSWORD="" E2E_TEST_APPLE_CALENDAR_PASSWORD=""
# ALBY
# Used for the Alby payment app / receiving Alby payments
# Get it from: https://getalby.com/developer/oauth_clients
NEXT_PUBLIC_ALBY_CLIENT_ID=
NEXT_PUBLIC_ALBY_CLIENT_SECRET=
# - APP CREDENTIAL SYNC *********************************************************************************** # - APP CREDENTIAL SYNC ***********************************************************************************
# Used for self-hosters that are implementing Cal.com into their applications that already have certain integrations # Used for self-hosters that are implementing Cal.com into their applications that already have certain integrations
# Under settings/admin/apps ensure that all app secrets are set the same as the parent application # Under settings/admin/apps ensure that all app secrets are set the same as the parent application

View File

@ -89,8 +89,7 @@ export const AppPage = ({
const [existingCredentials, setExistingCredentials] = useState<number[]>([]); const [existingCredentials, setExistingCredentials] = useState<number[]>([]);
const [showDisconnectIntegration, setShowDisconnectIntegration] = useState(false); const [showDisconnectIntegration, setShowDisconnectIntegration] = useState(false);
// FIXME: remove hardcoding
const showSetupIntegration = slug === "alby";
const appDbQuery = trpc.viewer.appCredentialsByType.useQuery( const appDbQuery = trpc.viewer.appCredentialsByType.useQuery(
{ appType: type }, { appType: type },
{ {
@ -215,21 +214,14 @@ export const AppPage = ({
)} )}
</div> </div>
) : showDisconnectIntegration ? ( ) : showDisconnectIntegration ? (
<div className="flex gap-2"> <DisconnectIntegration
{showSetupIntegration && ( buttonProps={{ color: "secondary" }}
<Link href={`/apps/${slug}/setup`}> label={t("disconnect")}
<Button color="secondary">Setup</Button> credentialId={existingCredentials[0]}
</Link> onSuccess={() => {
)} appDbQuery.refetch();
<DisconnectIntegration }}
buttonProps={{ color: "secondary" }} />
label={t("disconnect")}
credentialId={existingCredentials[0]}
onSuccess={() => {
appDbQuery.refetch();
}}
/>
</div>
) : ( ) : (
<InstallAppButton <InstallAppButton
type={type} type={type}

View File

@ -1,6 +1,7 @@
import { auth, Client, webln } from "@getalby/sdk"; import { auth, Client, webln } from "@getalby/sdk";
import Link from "next/link"; import Link from "next/link";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { useSearchParams } from "next/navigation";
import { useState, useCallback, useEffect } from "react"; import { useState, useCallback, useEffect } from "react";
import { Toaster } from "react-hot-toast"; import { Toaster } from "react-hot-toast";
@ -17,7 +18,7 @@ export interface IAlbySetupProps {
} }
export default function AlbySetup(props: IAlbySetupProps) { export default function AlbySetup(props: IAlbySetupProps) {
const params = globalThis.window && new URLSearchParams(window.location.search); const params = useSearchParams();
if (params?.get("callback") === "true") { if (params?.get("callback") === "true") {
return <AlbySetupCallback />; return <AlbySetupCallback />;
} }
@ -27,13 +28,13 @@ export default function AlbySetup(props: IAlbySetupProps) {
function AlbySetupCallback() { function AlbySetupCallback() {
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const params = useSearchParams();
useEffect(() => { useEffect(() => {
if (!window.opener) { if (!window.opener) {
setError("Something went wrong. Opener not available. Please contact support@getalby.com"); setError("Something went wrong. Opener not available. Please contact support@getalby.com");
return; return;
} }
const params = new URLSearchParams(window.location.search);
const code = params.get("code"); const code = params.get("code");
const error = params.get("error"); const error = params.get("error");
@ -86,7 +87,7 @@ function AlbySetupPage(props: IAlbySetupProps) {
const authClient = new auth.OAuth2User({ const authClient = new auth.OAuth2User({
client_id: process.env.NEXT_PUBLIC_ALBY_CLIENT_ID, client_id: process.env.NEXT_PUBLIC_ALBY_CLIENT_ID,
client_secret: process.env.NEXT_PUBLIC_ALBY_CLIENT_SECRET, client_secret: process.env.NEXT_PUBLIC_ALBY_CLIENT_SECRET,
callback: process.env.NEXT_PUBLIC_WEBAPP_URL + "/apps/alby/setup?callback=true", callback: `${process.env.NEXT_PUBLIC_WEBAPP_URL}/apps/alby/setup?callback=true`,
scopes: ["invoices:read", "account:read"], scopes: ["invoices:read", "account:read"],
user_agent: "cal.com", user_agent: "cal.com",
}); });