feat: refactor UI to use coss + coupons UI (#27647)

* feat: refactor UI to use coss + coupons UI

* fix: use TRPCError and remove sensitive logging in createCoupon handler

- Replace plain Error with TRPCError for consistent tRPC error handling
- Use INTERNAL_SERVER_ERROR for missing env configuration
- Use UNAUTHORIZED for permission denied errors
- Use BAD_REQUEST for API failure errors
- Remove console.warn that logged username (sensitive info)

Co-Authored-By: unknown <>

* feat: add copy button and fix 0 on % off

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-02-05 10:05:57 +00:00
1 parent 1ad4ad6e4e
commit c652c61e0c
7 files changed
+787 -198

No files matched your search

+105 -6
View File
@@ -12,7 +12,7 @@ function Card({
}: useRender.ComponentProps<"div">) {
const defaultProps = {
className: cn(
"relative flex flex-col gap-6 rounded-2xl border bg-card not-dark:bg-clip-padding py-6 text-card-foreground shadow-xs/5 before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-2xl)-1px)] before:shadow-[0_1px_--theme(--color-black/6%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
"relative flex flex-col rounded-2xl border bg-card not-dark:bg-clip-padding text-card-foreground shadow-xs/5 before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-2xl)-1px)] before:shadow-[0_1px_--theme(--color-black/6%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
className,
),
"data-slot": "card",
@@ -25,6 +25,94 @@ function Card({
});
}
function CardFrame({
className,
render,
...props
}: useRender.ComponentProps<"div">) {
const defaultProps = {
className: cn(
"flex flex-col relative rounded-2xl border bg-background before:absolute before:inset-0 before:rounded-[inherit] before:bg-muted/72 before:pointer-events-none not-dark:bg-clip-padding text-card-foreground shadow-xs/5 before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-2xl)-1px)] before:shadow-[0_1px_--theme(--color-black/6%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)] *:data-[slot=card]:-m-px *:not-last:data-[slot=card]:rounded-b-lg *:not-last:data-[slot=card]:before:rounded-b-[calc(var(--radius-lg)-1px)] *:not-first:data-[slot=card]:rounded-t-lg *:not-first:data-[slot=card]:before:rounded-t-[calc(var(--radius-lg)-1px)] *:data-[slot=card]:[clip-path:inset(-1rem_1px)] *:data-[slot=card]:first:[clip-path:inset(1px_1px_-1rem_1px_round_calc(var(--radius-2xl)-1px))] *:data-[slot=card]:last:[clip-path:inset(-1rem_1px_1px_1px_round_calc(var(--radius-2xl)-1px))] *:data-[slot=card]:shadow-none *:data-[slot=card]:before:hidden *:data-[slot=card]:bg-clip-padding",
className,
),
"data-slot": "card-frame",
};
return useRender({
defaultTagName: "div",
props: mergeProps<"div">(defaultProps, props),
render,
});
}
function CardFrameHeader({
className,
render,
...props
}: useRender.ComponentProps<"div">) {
const defaultProps = {
className: cn("flex flex-col px-6 py-4", className),
"data-slot": "card-frame-header",
};
return useRender({
defaultTagName: "div",
props: mergeProps<"div">(defaultProps, props),
render,
});
}
function CardFrameTitle({
className,
render,
...props
}: useRender.ComponentProps<"div">) {
const defaultProps = {
className: cn("font-semibold text-sm", className),
"data-slot": "card-frame-title",
};
return useRender({
defaultTagName: "div",
props: mergeProps<"div">(defaultProps, props),
render,
});
}
function CardFrameDescription({
className,
render,
...props
}: useRender.ComponentProps<"div">) {
const defaultProps = {
className: cn("text-muted-foreground text-sm", className),
"data-slot": "card-frame-description",
};
return useRender({
defaultTagName: "div",
props: mergeProps<"div">(defaultProps, props),
render,
});
}
function CardFrameFooter({
className,
render,
...props
}: useRender.ComponentProps<"div">) {
const defaultProps = {
className: cn("px-6 py-4", className),
"data-slot": "card-frame-footer",
};
return useRender({
defaultTagName: "div",
props: mergeProps<"div">(defaultProps, props),
render,
});
}
function CardHeader({
className,
render,
@@ -32,7 +120,7 @@ function CardHeader({
}: useRender.ComponentProps<"div">) {
const defaultProps = {
className: cn(
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
"grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 p-6 in-[[data-slot=card]:has(>[data-slot=card-panel])]:pb-4 has-data-[slot=card-action]:grid-cols-[1fr_auto]",
className,
),
"data-slot": "card-header",
@@ -86,7 +174,7 @@ function CardAction({
}: useRender.ComponentProps<"div">) {
const defaultProps = {
className: cn(
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
"col-start-2 row-span-2 row-start-1 self-start justify-self-end inline-flex",
className,
),
"data-slot": "card-action",
@@ -105,8 +193,11 @@ function CardPanel({
...props
}: useRender.ComponentProps<"div">) {
const defaultProps = {
className: cn("px-6", className),
"data-slot": "card-content",
className: cn(
"flex-1 p-6 in-[[data-slot=card]:has(>[data-slot=card-header]:not(.border-b))]:pt-0 in-[[data-slot=card]:has(>[data-slot=card-footer]:not(.border-t))]:pb-0",
className,
),
"data-slot": "card-panel",
};
return useRender({
@@ -122,7 +213,10 @@ function CardFooter({
...props
}: useRender.ComponentProps<"div">) {
const defaultProps = {
className: cn("flex items-center px-6 [.border-t]:pt-6", className),
className: cn(
"flex items-center p-6 in-[[data-slot=card]:has(>[data-slot=card-panel])]:pt-4",
className,
),
"data-slot": "card-footer",
};
@@ -135,6 +229,11 @@ function CardFooter({
export {
Card,
CardFrame,
CardFrameHeader,
CardFrameTitle,
CardFrameDescription,
CardFrameFooter,
CardAction,
CardDescription,
CardFooter,
+1 -1
View File
@@ -167,7 +167,7 @@ function DialogPanel({
<ScrollArea scrollFade={scrollFade}>
<div
className={cn(
"px-6 in-[[data-slot=dialog-popup]:has([data-slot=dialog-header])]:pt-1 in-[[data-slot=dialog-popup]:not(:has([data-slot=dialog-header]))]:pt-6 in-[[data-slot=dialog-popup]:not(:has([data-slot=dialog-footer]))]:pb-6! in-[[data-slot=dialog-popup]:not(:has([data-slot=dialog-footer].border-t))]:pb-1 pb-6",
"p-6 in-[[data-slot=dialog-popup]:has([data-slot=dialog-header])]:pt-1 in-[[data-slot=dialog-popup]:has([data-slot=dialog-footer]:not(.border-t))]:pb-1",
className,
)}
data-slot="dialog-panel"
@@ -2,6 +2,7 @@ import { authedAdminProcedure } from "../../../procedures/authedProcedure";
import { router } from "../../../trpc";
import { ZAdminAssignFeatureToTeamSchema } from "./assignFeatureToTeam.schema";
import { ZBillingPortalLinkSchema } from "./billingPortalLink.schema";
import { ZCreateCouponSchema } from "./createCoupon.schema";
import { ZCreateSelfHostedLicenseSchema } from "./createSelfHostedLicenseKey.schema";
import { ZAdminGetTeamsForFeatureSchema } from "./getTeamsForFeature.schema";
import { ZListMembersSchema } from "./listPaginated.schema";
@@ -58,6 +59,10 @@ export const adminRouter = router({
const { default: handler } = await import("./createSelfHostedLicenseKey.handler");
return handler(opts);
}),
createCoupon: authedAdminProcedure.input(ZCreateCouponSchema).mutation(async (opts) => {
const { default: handler } = await import("./createCoupon.handler");
return handler(opts);
}),
resendPurchaseCompleteEmail: authedAdminProcedure
.input(ZResendPurchaseCompleteEmailSchema)
.mutation(async (opts) => {
@@ -0,0 +1,83 @@
import * as crypto from "node:crypto";
import { z } from "zod";
import { CALCOM_PRIVATE_API_ROUTE } from "@calcom/lib/constants";
import { TRPCError } from "@trpc/server";
import type { TrpcSessionUser } from "../../../types";
import type { TCreateCouponSchema } from "./createCoupon.schema";
type CreateCouponOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TCreateCouponSchema;
};
const generateNonce = (): string => {
return crypto.randomBytes(16).toString("hex");
};
const createSignature = (body: Record<string, unknown>, nonce: string, secretKey: string): string => {
return crypto
.createHmac("sha256", secretKey)
.update(JSON.stringify(body) + nonce)
.digest("hex");
};
const fetchWithSignature = async (
url: string,
body: Record<string, unknown>,
secretKey: string,
options: RequestInit = {}
): Promise<Response> => {
const nonce = generateNonce();
const signature = createSignature(body, nonce, secretKey);
const headers = {
...options.headers,
"Content-Type": "application/json",
nonce: nonce,
signature: signature,
};
return await fetch(url, {
...options,
method: "POST",
headers: headers,
body: JSON.stringify(body),
});
};
const createCoupon = async ({ input, ctx }: CreateCouponOptions) => {
const privateApiUrl = CALCOM_PRIVATE_API_ROUTE;
const signatureToken = process.env.CAL_SIGNATURE_TOKEN;
if (!privateApiUrl || !signatureToken) {
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: "Private API route is not configured" });
}
if (ctx.user.role !== "ADMIN") {
throw new TRPCError({ code: "UNAUTHORIZED", message: "You do not have permission to do this" });
}
const request = await fetchWithSignature(`${privateApiUrl}/v1/license/coupon`, input, signatureToken, {
method: "POST",
});
const data = await request.json();
if (!request.ok) {
throw new TRPCError({ code: "BAD_REQUEST", message: data.message ?? "Failed to create coupon" });
}
const schema = z.object({
promotionCode: z.string(),
couponId: z.string(),
});
return schema.parse(data);
};
export default createCoupon;
@@ -0,0 +1,32 @@
import { z } from "zod";
import { emailSchema } from "@calcom/lib/emailSchema";
const DiscountType = z.enum(["percent", "fixed"]);
const CouponDuration = z.enum(["once", "repeating", "forever"]);
export const ZCreateCouponSchema = z
.object({
billingEmail: emailSchema,
discountType: DiscountType,
discountAmount: z.number().int().min(1),
currency: z.string().optional().default("USD"),
duration: CouponDuration,
durationInMonths: z.number().int().min(1).max(36).optional(),
code: z.string().min(1),
couponName: z.string().optional(),
})
.refine(
(data) => {
if (data.duration === "repeating") {
return data.durationInMonths !== undefined;
}
return true;
},
{
message: "durationInMonths is required when duration is 'repeating'",
path: ["durationInMonths"],
}
);
export type TCreateCouponSchema = z.infer<typeof ZCreateCouponSchema>;