Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+48
@@ -0,0 +1,48 @@
|
||||
import type { LoaderFunctionArgs } from "react-router";
|
||||
|
||||
import {
|
||||
completeAdminAircallConnection,
|
||||
runAsAdminTelephonyOperator,
|
||||
} from "~/services/admin/admin-telephony-connections.server";
|
||||
import { consumeAdminTelephonyOAuthState } from "~/services/admin/admin-telephony-oauth-state.server";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
|
||||
export async function loader({ request }: LoaderFunctionArgs) {
|
||||
const url = new URL(request.url);
|
||||
const code = url.searchParams.get("code") ?? "";
|
||||
const state = url.searchParams.get("state") ?? "";
|
||||
return runAsAdminTelephonyOperator(
|
||||
request,
|
||||
"admin_sales.integrations.manage",
|
||||
async (context) => {
|
||||
const challenge = consumeAdminTelephonyOAuthState(request, {
|
||||
expectedState: state,
|
||||
expectedAdminUserId: context.adminUserId,
|
||||
});
|
||||
if (!challenge.ok || !code) {
|
||||
return redirect("oauth-error", challenge.clearCookie, request.url);
|
||||
}
|
||||
try {
|
||||
await completeAdminAircallConnection({ context, code });
|
||||
return redirect("connected", challenge.clearCookie, request.url);
|
||||
} catch {
|
||||
return redirect("connection-error", challenge.clearCookie, request.url);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function redirect(status: string, cookie: string, requestUrl: string) {
|
||||
const location = new URL(
|
||||
`${adminPath("settings/telephony", { mode: "host-aware" })}?status=${status}`,
|
||||
requestUrl
|
||||
);
|
||||
return new Response(null, {
|
||||
status: 303,
|
||||
headers: {
|
||||
Location: location.toString(),
|
||||
"Set-Cookie": cookie,
|
||||
"Cache-Control": "no-store",
|
||||
},
|
||||
});
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import type { LoaderFunctionArgs } from "react-router";
|
||||
|
||||
import {
|
||||
getAdminAircallAuthorizationUrl,
|
||||
runAsAdminTelephonyOperator,
|
||||
} from "~/services/admin/admin-telephony-connections.server";
|
||||
import { createAdminTelephonyOAuthState } from "~/services/admin/admin-telephony-oauth-state.server";
|
||||
|
||||
export async function loader({ request }: LoaderFunctionArgs) {
|
||||
return runAsAdminTelephonyOperator(
|
||||
request,
|
||||
"admin_sales.integrations.manage",
|
||||
async (context) => {
|
||||
const challenge = createAdminTelephonyOAuthState({
|
||||
adminUserId: context.adminUserId,
|
||||
});
|
||||
return new Response(null, {
|
||||
status: 302,
|
||||
headers: {
|
||||
Location: getAdminAircallAuthorizationUrl(challenge.state),
|
||||
"Set-Cookie": challenge.cookie,
|
||||
"Cache-Control": "no-store",
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user