Files
calendar/apps/web/components/settings/platform/oauth-clients/OAuthClientCard.tsx
T
c2a07e221d feat: platform onboarding flow and dashboard (#14721)
* add endpoint to fetch managed user from client id

* update typings

* minor tweaks

* custom hook to fetch managed users from client id

* add translations for platform onboarding

* add isPlatformOrg boolean to figure out which is platform and which is not

* set isPlatform hook based on data obtained from org

* add limitWidth prop to control component width

* add props to shell to make sidebar display different tabs based on if the shell isPlattform or not

* platform related pages

* fix merge conflicts

* fix merge conflicts

* platform oauth client form and card

* remove everything related to platform from organization

* update oauth client card and form

* fixup

* fix imports and remove logs

* fixup

* update redirect url

* split oauth client form into separate update and create forms

* separate forms for create and edit oauth clients

* fixup

* fixup

* dynamic routes for oauth client edit page

* fixup fixup

* fix to not show error when redirect uri is empty

* refactor create handler for org

* cleaup comments

* add custom hook to check user billing

* export managed user type

* refactor platform index page

* refactor edit and create pages

* dashboard component containing oauth client list and managed user

* common oauth client form used for create and edit form

* platform pricing helper

* platform pricing component

* fix typing and data response for billing

* use custom hook to check team billing info

* fix type checks

* upgrade conditional rendering for upgrade to org banner

* add isLoading prop to check button loading state

* pass in button handler

* add custom hook to subscribe to stripe and typings

* update typings

* fix incorrect endpoint

* pass in team id as prop

* fix type check

* update stripe success and cancel redirect url

* add and pass redirect url param to custom hook

* custom hooks for platform

* cleanup

* update imports

* fix merge conflicts

* fixup

* fixup fixup

* fixup

* merge conflicts fixup

* merge conlficts battle :(

* minor fixes

* skip admin checks for a platform client

* fix typo

* append slug with _platform for a platform user

* PR feedback

* dashboard refactor

* bring back org form to its orginal state

* add platform folder to ee

* update typings

* use new create platform form

* fixup

* fix typo and update plans

* simplifying rendering

* remove managed users endpoint since it already exists

* url for endpoint

* rename tabs

* pr feedback

* managed users endpoint

* update endpoint

* remove form

---------

Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
Co-authored-by: exception <erik@erosemberg.com>
Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
2024-05-09 13:01:10 -04:00

162 lines
5.3 KiB
TypeScript

import { useRouter } from "next/navigation";
import React from "react";
import { classNames } from "@calcom/lib";
import { PERMISSIONS_GROUPED_MAP } from "@calcom/platform-constants";
import type { Avatar } from "@calcom/prisma/client";
import { Button, Icon, showToast } from "@calcom/ui";
import { hasPermission } from "../../../../../../packages/platform/utils/permissions";
type OAuthClientCardProps = {
name: string;
logo?: Avatar;
redirectUris: string[];
bookingRedirectUri: string | null;
bookingCancelRedirectUri: string | null;
bookingRescheduleRedirectUri: string | null;
areEmailsEnabled: boolean;
permissions: number;
lastItem: boolean;
id: string;
secret: string;
onDelete: (id: string) => Promise<void>;
isLoading: boolean;
};
export const OAuthClientCard = ({
name,
logo,
redirectUris,
bookingRedirectUri,
bookingCancelRedirectUri,
bookingRescheduleRedirectUri,
permissions,
id,
secret,
lastItem,
onDelete,
isLoading,
areEmailsEnabled,
}: OAuthClientCardProps) => {
const router = useRouter();
const clientPermissions = Object.values(PERMISSIONS_GROUPED_MAP).map((value, index) => {
let permissionsMessage = "";
const hasReadPermission = hasPermission(permissions, value.read);
const hasWritePermission = hasPermission(permissions, value.write);
if (hasReadPermission || hasWritePermission) {
permissionsMessage = hasReadPermission ? "read" : "write";
}
if (hasReadPermission && hasWritePermission) {
permissionsMessage = "read/write";
}
return (
!!permissionsMessage && (
<div key={value.read} className="relative text-sm">
&nbsp;{permissionsMessage} {`${value.label}s`.toLocaleLowerCase()}
{Object.values(PERMISSIONS_GROUPED_MAP).length === index + 1 ? " " : ", "}
</div>
)
);
});
return (
<div
className={classNames(
"flex w-full justify-between px-4 py-4 sm:px-6",
lastItem ? "" : "border-subtle border-b"
)}>
<div className="flex flex-col gap-2">
<div className="flex gap-1">
<p className="font-semibold">
Client name: <span className="font-normal">{name}</span>
</p>
</div>
{!!logo && (
<div>
<>{logo}</>
</div>
)}
<div className="flex flex-col gap-2">
<div className="flex flex-row items-center gap-2">
<div className="font-semibold">Client Id:</div>
<div>{id}</div>
<Icon
name="clipboard"
type="button"
className="h-4 w-4 cursor-pointer"
onClick={() => {
navigator.clipboard.writeText(id);
showToast("Client id copied to clipboard.", "success");
}}
/>
</div>
</div>
<div className="flex items-center gap-2">
<div className="font-semibold">Client Secret:</div>
<div className="flex items-center justify-center rounded-md">
{[...new Array(20)].map((_, index) => (
<Icon name="asterisk" key={`${index}asterisk`} className="h-2 w-2" />
))}
<Icon
name="clipboard"
type="button"
className="ml-2 h-4 w-4 cursor-pointer"
onClick={() => {
navigator.clipboard.writeText(secret);
showToast("Client secret copied to clipboard.", "success");
}}
/>
</div>
</div>
<div className="border-subtle flex text-sm">
<span className="font-semibold">Permissions: </span>
{permissions ? <div className="flex">{clientPermissions}</div> : <>&nbsp;Disabled</>}
</div>
<div className="flex gap-1 text-sm">
<span className="font-semibold">Redirect uris: </span>
{redirectUris.map((item, index) => (redirectUris.length === index + 1 ? `${item}` : `${item}, `))}
</div>
{bookingRedirectUri && (
<div className="flex gap-1 text-sm">
<span className="font-semibold">Booking redirect uri: </span> {bookingRedirectUri}
</div>
)}
{bookingRescheduleRedirectUri && (
<div className="flex gap-1 text-sm">
<span className="font-semibold">Booking reschedule uri: </span> {bookingRescheduleRedirectUri}
</div>
)}
{bookingCancelRedirectUri && (
<div className="flex gap-1 text-sm">
<span className="font-semibold">Booking cancel uri: </span> {bookingCancelRedirectUri}
</div>
)}
<div className="flex gap-1 text-sm">
<span className="text-sm font-semibold">Emails enabled:</span> {areEmailsEnabled ? "Yes" : "No"}
</div>
</div>
<div className="flex items-start gap-4">
<Button
className="bg-subtle hover:bg-emphasis text-white"
loading={isLoading}
disabled={isLoading}
onClick={() => router.push(`/settings/platform/oauth-clients/${id}/edit`)}>
Edit
</Button>
<Button
className="bg-red-500 text-white hover:bg-red-600"
loading={isLoading}
disabled={isLoading}
onClick={() => onDelete(id)}>
Delete
</Button>
</div>
</div>
);
};