Admin Wizard Choose License (#6574)
* Implementation * i18n * More i18n * extracted i18n, needs api to get most recent price, added hint: update later * Fixing i18n var * Fix booking filters not working for admin (#6576) * fix: react-select overflow issue in some modals. (#6587) * feat: add a disable overflow prop * feat: use the disable overflow prop * Tailwind Merge (#6596) * Tailwind Merge * Fix merge classNames * [CAL-808] /availability/single - UI issue on buttons beside time inputs (#6561) * [CAL-808] /availability/single - UI issue on buttons beside time inputs * Update apps/web/public/static/locales/en/common.json * Update packages/features/schedules/components/Schedule.tsx * create new translation for tooltip Co-authored-by: gitstart-calcom <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: CarinaWolli <[email protected]> * Bye bye submodules (#6585) * WIP * Uses ssh instead * Update .gitignore * Update .gitignore * Update Makefile * Update git-setup.sh * Update git-setup.sh * Replaced Makefile with bash script * Update package.json * fix: show button on empty string (#6601) Signed-off-by: Udit Takkar <[email protected]> Signed-off-by: Udit Takkar <[email protected]> * fix: add delete in dropdown (#6599) Signed-off-by: Udit Takkar <[email protected]> Signed-off-by: Udit Takkar <[email protected]> * Update README.md * Update README.md * Changed a neutral- classes to gray (#6603) * Changed a neutral- classes to gray * Changed all border-1 to border * Update package.json * Test fixes * Yarn lock fixes * Fix string equality check in git-setup.sh * [CAL-811] Avatar icon not redirecting user back to the main page (#6586) * Remove cursor-pointer, remove old Avatar* files * Fixed styling for checkedSelect + some cleanup Co-authored-by: gitstart-calcom <[email protected]> Co-authored-by: Alex van Andel <[email protected]> * Harsh/add member invite (#6598) Co-authored-by: Guest <[email protected]> Co-authored-by: root <[email protected]> * Regenerated lockfile without upgrade (#6610) * fix: remove annoying outline when <Button /> clicked (#6537) * fix: remove annoying outline when <Button /> clicked * Delete yarn.lock * remove 1 on 1 icon (#6609) * removed 1-on-1 badge * changed user to users for group events * fix: case-sensitivity in apps path (#6552) * fix: lowercase slug * fix: make fallback blocking * Fix FAB (#6611) * feat: add LocationSelect component (#6571) * feat: add LocationSelect component Signed-off-by: Udit Takkar <[email protected]> * fix: type error Signed-off-by: Udit Takkar <[email protected]> * chore: type error Signed-off-by: Udit Takkar <[email protected]> Signed-off-by: Udit Takkar <[email protected]> * Update booking filters design (#6543) * Update booking filters * Add filter on YOUR bookings * Fix pending members showing up in list * Reduce the avatar size to 'sm' for now * Bugfix/dropdown menu trigger as child remove class names (#6614) * Fix UsernameTextfield to take right height * Remove className side-effect * Incorrect resolution version fixed * Converted mobile DropdownMenuTrigger styles into Button * v2.5.3 * fix: use items-center (#6618) * fix tooltip and modal stacking issues (#6491) * fix tooltip and modal stacking issues * use z-index in larger screens and less Co-authored-by: Alex van Andel <[email protected]> * Temporary fix (#6626) * Fix Ga4 tracking (#6630) * generic <UpgradeScreen> component (#6594) * first attempt of <UpgradeScreen> * changes to icons * reverted changes back to initial state, needs fix: teams not showing * WIP * Fix weird reactnode error * Fix loading text * added upgradeTip to routing forms * icon colors * create and use hook to check if user has team plan * use useTeamPlan for upgradeTeamsBadge * replace huge svg with compressed jpeg * responsive fixes * Update packages/ui/components/badge/UpgradeTeamsBadge.tsx Co-authored-by: sean-brydon <[email protected]> * Give team plan features to E2E tests * Allow option to make a user part of team int ests * Remove flash of paywall for team user * Add team user for typeform tests as well Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Hariom Balhara <[email protected]> * Removing env var to rely on db * Restoring i18n keys, set loading moved * Fixing tailwind-preset glob * Wizard width fix for md+ screens * Converting licenses options to radix radio * Applying feedback + other tweaks * Reverting this, not this PR related * Unneeded code removal * Reverting unneeded style change * Applying feedback * Removing licenseType * Upgrades typescript * Update yarn lock * Typings * Hotfix: ping,riverside,whereby and around not showing up in list (#6712) * Hotfix: ping,riverside,whereby and around not showing up in list (#6712) (#6713) * Adds deployment settings to DB (#6706) * WIP * Adds DeploymentTheme * Add missing migrations * Adds client extensions for deployment * Cleanup * Delete migration.sql * Relying on both, env var and new model * Restoring env example doc for backward compat * Maximum call stack size exceeded fix? * Revert upgrade * Update index.ts * Delete index.ts * Not exposing license key, fixed radio behavior * Covering undefined env var * Self contained checkLicense * Feedback * Moar feedback * Feedback * Feedback * Feedback * Cleanup --------- Signed-off-by: Udit Takkar <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: sean-brydon <[email protected]> Co-authored-by: Nafees Nazik <[email protected]> Co-authored-by: GitStart-Cal.com <[email protected]> Co-authored-by: gitstart-calcom <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Omar López <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Harsh Singh <[email protected]> Co-authored-by: Guest <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: Luis Cadillo <[email protected]> Co-authored-by: Mohammed Cherfaoui <[email protected]> Co-authored-by: Hariom Balhara <[email protected]> Co-authored-by: Carina Wollendorfer <[email protected]>
This commit is contained in:
28 files changed
+584
-136
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { classNames as cs } from "@calcom/lib";
|
||||
import { HorizontalTabs, VerticalTabs } from "@calcom/ui";
|
||||
|
||||
import getAppCategories from "../_utils/getAppCategories";
|
||||
@@ -11,33 +11,39 @@ const AppCategoryNavigation = ({
|
||||
children,
|
||||
containerClassname,
|
||||
className,
|
||||
fromAdmin,
|
||||
classNames,
|
||||
useQueryParam = false,
|
||||
}: {
|
||||
baseURL: string;
|
||||
children: React.ReactNode;
|
||||
containerClassname: string;
|
||||
/** @deprecated use classNames instead */
|
||||
containerClassname?: string;
|
||||
/** @deprecated use classNames instead */
|
||||
className?: string;
|
||||
fromAdmin?: boolean;
|
||||
classNames?: {
|
||||
root?: string;
|
||||
container?: string;
|
||||
verticalTabsItem?: string;
|
||||
};
|
||||
useQueryParam?: boolean;
|
||||
}) => {
|
||||
const [animationRef] = useAutoAnimate<HTMLDivElement>();
|
||||
const appCategories = useMemo(() => getAppCategories(baseURL, useQueryParam), [baseURL, useQueryParam]);
|
||||
|
||||
return (
|
||||
<div className={classNames("flex flex-col gap-x-6 p-2 md:p-0 xl:flex-row", className)}>
|
||||
<div className={cs("flex flex-col gap-x-6 p-2 md:p-0 xl:flex-row", classNames?.root ?? className)}>
|
||||
<div className="hidden xl:block">
|
||||
<VerticalTabs
|
||||
tabs={appCategories}
|
||||
sticky
|
||||
linkProps={{ shallow: true }}
|
||||
itemClassname={classNames(fromAdmin && "w-60")}
|
||||
itemClassname={classNames?.verticalTabsItem}
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-4 block overflow-x-scroll xl:hidden">
|
||||
<HorizontalTabs tabs={appCategories} linkProps={{ shallow: true }} />
|
||||
</div>
|
||||
<main className={containerClassname} ref={animationRef}>
|
||||
<main className={classNames?.container ?? containerClassname} ref={animationRef}>
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@ module.exports = {
|
||||
content: [
|
||||
"./pages/**/*.{js,ts,jsx,tsx}",
|
||||
"./components/**/*.{js,ts,jsx,tsx}",
|
||||
"../../packages/app-store/**/{components,pages}/**/*.{js,ts,jsx,tsx}",
|
||||
"../../packages/app-store/**/*{components,pages}/**/*.{js,ts,jsx,tsx}",
|
||||
"../../packages/features/**/*.{js,ts,jsx,tsx}",
|
||||
"../../packages/ui/**/*.{js,ts,jsx,tsx}",
|
||||
],
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { AppCategories } from "@prisma/client";
|
||||
import { noop } from "lodash";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState, useReducer, FC } from "react";
|
||||
import { FC, useReducer, useState } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import AppCategoryNavigation from "@calcom/app-store/_components/AppCategoryNavigation";
|
||||
import { appKeysSchemas } from "@calcom/app-store/apps.keys-schemas.generated";
|
||||
import { classNames as cs } from "@calcom/lib";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { RouterOutputs, trpc } from "@calcom/trpc/react";
|
||||
import {
|
||||
@@ -32,9 +34,9 @@ import {
|
||||
} from "@calcom/ui";
|
||||
import {
|
||||
FiAlertCircle,
|
||||
FiCheckCircle,
|
||||
FiEdit,
|
||||
FiMoreHorizontal,
|
||||
FiCheckCircle,
|
||||
FiXCircle,
|
||||
} from "@calcom/ui/components/icon";
|
||||
|
||||
@@ -148,26 +150,39 @@ const AdminAppsList = ({
|
||||
baseURL,
|
||||
className,
|
||||
useQueryParam = false,
|
||||
classNames,
|
||||
onSubmit = noop,
|
||||
...rest
|
||||
}: {
|
||||
baseURL: string;
|
||||
classNames?: {
|
||||
form?: string;
|
||||
appCategoryNavigationRoot?: string;
|
||||
appCategoryNavigationContainer?: string;
|
||||
verticalTabsItem?: string;
|
||||
};
|
||||
className?: string;
|
||||
useQueryParam?: boolean;
|
||||
}) => {
|
||||
const router = useRouter();
|
||||
onSubmit?: () => void;
|
||||
} & Omit<JSX.IntrinsicElements["form"], "onSubmit">) => {
|
||||
return (
|
||||
<form
|
||||
id="wizard-step-2"
|
||||
name="wizard-step-2"
|
||||
{...rest}
|
||||
className={
|
||||
classNames?.form ?? "max-w-80 mb-4 rounded-md bg-white px-0 pt-0 md:max-w-full md:px-8 md:pt-10"
|
||||
}
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
router.replace("/");
|
||||
onSubmit();
|
||||
}}>
|
||||
<AppCategoryNavigation
|
||||
baseURL={baseURL}
|
||||
fromAdmin
|
||||
useQueryParam={useQueryParam}
|
||||
containerClassname="min-w-0 w-full"
|
||||
className={className}>
|
||||
classNames={{
|
||||
root: className,
|
||||
verticalTabsItem: classNames?.verticalTabsItem,
|
||||
container: cs("min-w-0 w-full", classNames?.appCategoryNavigationContainer ?? "max-w-[500px]"),
|
||||
}}>
|
||||
<AdminAppsListContainer />
|
||||
</AppCategoryNavigation>
|
||||
</form>
|
||||
|
||||
@@ -43,16 +43,8 @@ const ApiKeyListItem = ({
|
||||
<div>
|
||||
<p className="font-medium"> {apiKey?.note ? apiKey.note : t("api_key_no_note")}</p>
|
||||
<div className="flex items-center space-x-3.5">
|
||||
{!neverExpires && isExpired && (
|
||||
<Badge className="-p-2" variant="red">
|
||||
{t("expired")}
|
||||
</Badge>
|
||||
)}
|
||||
{!isExpired && (
|
||||
<Badge className="-p-2" variant="green">
|
||||
{t("active")}
|
||||
</Badge>
|
||||
)}
|
||||
{!neverExpires && isExpired && <Badge variant="red">{t("expired")}</Badge>}
|
||||
{!isExpired && <Badge variant="green">{t("active")}</Badge>}
|
||||
<p className="text-xs text-gray-600">
|
||||
{" "}
|
||||
{neverExpires ? (
|
||||
|
||||
@@ -7,7 +7,7 @@ import DOMPurify from "dompurify";
|
||||
import { useSession } from "next-auth/react";
|
||||
import React, { AriaRole, ComponentType, Fragment } from "react";
|
||||
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
import { APP_NAME, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { EmptyScreen } from "@calcom/ui";
|
||||
import { FiAlertTriangle } from "@calcom/ui/components/icon";
|
||||
@@ -46,6 +46,7 @@ const LicenseRequired = ({ children, as = "", ...rest }: LicenseRequiredProps) =
|
||||
consoleUrl: `<a href="https://go.cal.com/console" target="_blank" class="underline">
|
||||
${APP_NAME}
|
||||
</a>`,
|
||||
setupUrl: `<a href="${WEBAPP_URL}/auth/setup">/auth/setup</a>`,
|
||||
supportMail: `<a href="mailto:[email protected]" class="underline">
|
||||
[email protected]
|
||||
</a>`,
|
||||
|
||||
@@ -2,7 +2,7 @@ import DOMPurify from "dompurify";
|
||||
import { useSession } from "next-auth/react";
|
||||
import React, { AriaRole, ComponentType, Fragment } from "react";
|
||||
|
||||
import { APP_NAME, CONSOLE_URL, SUPPORT_MAIL_ADDRESS } from "@calcom/lib/constants";
|
||||
import { APP_NAME, CONSOLE_URL, SUPPORT_MAIL_ADDRESS, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { EmptyScreen } from "@calcom/ui";
|
||||
import { FiAlertTriangle } from "@calcom/ui/components/icon";
|
||||
@@ -36,9 +36,9 @@ const LicenseRequired = ({ children, as = "", ...rest }: LicenseRequiredProps) =
|
||||
consoleUrl: `<a href="${CONSOLE_URL}" target="_blank" rel="noopener noreferrer" class="underline">
|
||||
${APP_NAME}
|
||||
</a>`,
|
||||
setupUrl: `<a href="${WEBAPP_URL}/auth/setup" class="underline">/auth/setup</a>`,
|
||||
supportMail: `<a href="mailto:${SUPPORT_MAIL_ADDRESS}" class="underline">
|
||||
${SUPPORT_MAIL_ADDRESS}
|
||||
</a>`,
|
||||
${SUPPORT_MAIL_ADDRESS}</a>`,
|
||||
})
|
||||
),
|
||||
}}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { PrismaClient } from "@prisma/client";
|
||||
import cache from "memory-cache";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -18,10 +19,21 @@ const schemaLicenseKey = z
|
||||
: v;
|
||||
});
|
||||
|
||||
async function checkLicense(license: string): Promise<boolean> {
|
||||
async function checkLicense(
|
||||
/** The prisma client to use (necessary for public API to handle custom prisma instances) */
|
||||
prisma: PrismaClient
|
||||
): Promise<boolean> {
|
||||
/** We skip for E2E testing */
|
||||
if (!!process.env.NEXT_PUBLIC_IS_E2E) return true;
|
||||
if (!license) return false;
|
||||
const url = `${CONSOLE_URL}/api/license?key=${schemaLicenseKey.parse(license)}`;
|
||||
/** We check first on env */
|
||||
let licenseKey = process.env.CALCOM_LICENSE_KEY;
|
||||
if (!licenseKey) {
|
||||
/** We try to check on DB only if env is undefined */
|
||||
const deployment = await prisma.deployment.findFirst({ where: { id: 1 } });
|
||||
licenseKey = deployment?.licenseKey ?? undefined;
|
||||
}
|
||||
if (!licenseKey) return false;
|
||||
const url = `${CONSOLE_URL}/api/license?key=${schemaLicenseKey.parse(licenseKey)}`;
|
||||
const cachedResponse = cache.get(url);
|
||||
if (cachedResponse) {
|
||||
return cachedResponse;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { PrismaClient } from "@prisma/client";
|
||||
|
||||
export async function getDeploymentKey(prisma: PrismaClient) {
|
||||
const deployment = await prisma.deployment.findUnique({
|
||||
where: { id: 1 },
|
||||
select: { licenseKey: true },
|
||||
});
|
||||
return deployment?.licenseKey || process.env.CALCOM_LICENSE_KEY || "";
|
||||
}
|
||||
@@ -209,6 +209,14 @@ export const KBarRoot = ({ children }: { children: React.ReactNode }) => {
|
||||
keywords: "user impersonation",
|
||||
perform: () => router.push("/settings/security/impersonation"),
|
||||
},
|
||||
{
|
||||
id: "license",
|
||||
name: "choose_a_license",
|
||||
section: "admin",
|
||||
shortcut: ["u", "l"],
|
||||
keywords: "license",
|
||||
perform: () => router.push("/auth/setup?step=1"),
|
||||
},
|
||||
{
|
||||
id: "webhooks",
|
||||
name: "Webhooks",
|
||||
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
FiChevronRight,
|
||||
FiPlus,
|
||||
FiMenu,
|
||||
FiExternalLink,
|
||||
} from "@calcom/ui/components/icon";
|
||||
|
||||
const tabs: VerticalTabItemProps[] = [
|
||||
@@ -89,6 +90,7 @@ const tabs: VerticalTabItemProps[] = [
|
||||
icon: FiLock,
|
||||
children: [
|
||||
//
|
||||
{ name: "license", href: "/auth/setup?step=1" },
|
||||
{ name: "impersonation", href: "/settings/admin/impersonation" },
|
||||
{ name: "apps", href: "/settings/admin/apps/calendar" },
|
||||
{ name: "users", href: "https://console.cal.com" },
|
||||
|
||||
@@ -41,6 +41,7 @@ import { appsRouter } from "./viewer/apps";
|
||||
import { authRouter } from "./viewer/auth";
|
||||
import { availabilityRouter } from "./viewer/availability";
|
||||
import { bookingsRouter } from "./viewer/bookings";
|
||||
import { deploymentSetupRouter } from "./viewer/deploymentSetup";
|
||||
import { eventTypesRouter } from "./viewer/eventTypes";
|
||||
import { slotsRouter } from "./viewer/slots";
|
||||
import { ssoRouter } from "./viewer/sso";
|
||||
@@ -1150,6 +1151,7 @@ export const viewerRouter = mergeRouters(
|
||||
loggedInViewerRouter,
|
||||
public: publicViewerRouter,
|
||||
auth: authRouter,
|
||||
deploymentSetup: deploymentSetupRouter,
|
||||
bookings: bookingsRouter,
|
||||
eventTypes: eventTypesRouter,
|
||||
availability: availabilityRouter,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { router, authedAdminProcedure } from "../../trpc";
|
||||
|
||||
export const deploymentSetupRouter = router({
|
||||
update: authedAdminProcedure
|
||||
.input(
|
||||
z.object({
|
||||
licenseKey: z.string().optional(),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
const data = {
|
||||
agreedLicenseAt: new Date(),
|
||||
licenseKey: input.licenseKey,
|
||||
};
|
||||
|
||||
await prisma.deployment.upsert({ where: { id: 1 }, create: data, update: data });
|
||||
|
||||
return;
|
||||
}),
|
||||
});
|
||||
Vendored
-2
@@ -1,7 +1,5 @@
|
||||
declare namespace NodeJS {
|
||||
interface ProcessEnv {
|
||||
/** Needed to enable enterprise-only features */
|
||||
readonly CALCOM_LICENSE_KEY: string | undefined;
|
||||
readonly CALCOM_TELEMETRY_DISABLED: string | undefined;
|
||||
readonly CALENDSO_ENCRYPTION_KEY: string | undefined;
|
||||
readonly DATABASE_URL: string | undefined;
|
||||
|
||||
@@ -211,7 +211,7 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
|
||||
<StartIcon
|
||||
className={classNames(
|
||||
variant === "icon" && "h-4 w-4",
|
||||
variant === "button" && "h-4 w-4 stroke-[1.5px] ltr:mr-2 rtl:ml-2"
|
||||
variant === "button" && "h-4 w-4 stroke-[1.5px] ltr:ml-2 rtl:mr-2"
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -117,7 +117,7 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function
|
||||
</Skeleton>
|
||||
)}
|
||||
{addOnLeading || addOnSuffix ? (
|
||||
<div className="relative mb-1 flex items-center rounded-md focus-within:outline-none focus-within:ring-2 focus-within:ring-neutral-800 focus-within:ring-offset-1">
|
||||
<div className="group relative mb-1 flex items-center rounded-md focus-within:outline-none focus-within:ring-2 focus-within:ring-neutral-800 focus-within:ring-offset-1">
|
||||
{addOnLeading && (
|
||||
<Addon
|
||||
isFilled={addOnFilled}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
||||
import Link from "next/link";
|
||||
|
||||
type DefaultStep = {
|
||||
@@ -16,12 +17,13 @@ function Stepper<T extends DefaultStep>(props: {
|
||||
steps,
|
||||
stepLabel = (currentStep, totalSteps) => `Step ${currentStep} of ${totalSteps}`,
|
||||
} = props;
|
||||
const [stepperRef] = useAutoAnimate<HTMLOListElement>();
|
||||
return (
|
||||
<>
|
||||
{steps.length > 1 && (
|
||||
<nav className="flex items-center justify-center" aria-label="Progress">
|
||||
<p className="text-sm font-medium">{stepLabel(props.step, steps.length)}</p>
|
||||
<ol role="list" className="ml-8 flex items-center space-x-5">
|
||||
<ol role="list" className="ml-8 flex items-center space-x-5" ref={stepperRef}>
|
||||
{steps.map((mapStep, index) => (
|
||||
<li key={mapStep.title}>
|
||||
<Link
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
interface ISteps {
|
||||
maxSteps: number;
|
||||
currentStep: number;
|
||||
navigateToStep: (step: number) => void;
|
||||
stepLabel?: (currentStep: number, maxSteps: number) => string;
|
||||
}
|
||||
|
||||
const Steps = (props: ISteps) => {
|
||||
const { maxSteps, currentStep, navigateToStep } = props;
|
||||
const { t } = useLocale();
|
||||
const {
|
||||
maxSteps,
|
||||
currentStep,
|
||||
navigateToStep,
|
||||
stepLabel = (currentStep, totalSteps) => `Step ${currentStep} of ${totalSteps}`,
|
||||
} = props;
|
||||
return (
|
||||
<div className="mt-6 space-y-2">
|
||||
<p className="text-xs font-medium text-gray-500 dark:text-white">
|
||||
{t("current_step_of_total", { currentStep: currentStep + 1, maxSteps })}
|
||||
</p>
|
||||
<p className="text-xs font-medium text-gray-500 dark:text-white">{stepLabel(currentStep, maxSteps)}</p>
|
||||
<div className="flex w-full space-x-2 rtl:space-x-reverse">
|
||||
{new Array(maxSteps).fill(0).map((_s, index) => {
|
||||
return index <= currentStep ? (
|
||||
return index <= currentStep - 1 ? (
|
||||
<div
|
||||
key={`step-${index}`}
|
||||
onClick={() => navigateToStep(index)}
|
||||
className={classNames(
|
||||
"h-1 w-full rounded-[1px] bg-black dark:bg-white",
|
||||
index < currentStep ? "cursor-pointer" : ""
|
||||
index < currentStep - 1 ? "cursor-pointer" : ""
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { noop } from "lodash";
|
||||
import { useRouter } from "next/router";
|
||||
import { ComponentProps } from "react";
|
||||
import { Dispatch, SetStateAction, useEffect, useState } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
import { Button, Stepper } from "../../..";
|
||||
import { Button, Steps } from "../../..";
|
||||
|
||||
type DefaultStep = {
|
||||
title: string;
|
||||
containerClassname?: string;
|
||||
contentClassname?: string;
|
||||
description: string;
|
||||
content: JSX.Element;
|
||||
enabled?: boolean;
|
||||
isLoading: boolean;
|
||||
content?: ((setIsLoading: Dispatch<SetStateAction<boolean>>) => JSX.Element) | JSX.Element;
|
||||
isEnabled?: boolean;
|
||||
isLoading?: boolean;
|
||||
};
|
||||
|
||||
function WizardForm<T extends DefaultStep>(props: {
|
||||
@@ -21,7 +24,7 @@ function WizardForm<T extends DefaultStep>(props: {
|
||||
prevLabel?: string;
|
||||
nextLabel?: string;
|
||||
finishLabel?: string;
|
||||
stepLabel?: ComponentProps<typeof Stepper>["stepLabel"];
|
||||
stepLabel?: React.ComponentProps<typeof Steps>["stepLabel"];
|
||||
}) {
|
||||
const { href, steps, nextLabel = "Next", finishLabel = "Finish", prevLabel = "Back", stepLabel } = props;
|
||||
const router = useRouter();
|
||||
@@ -30,55 +33,54 @@ function WizardForm<T extends DefaultStep>(props: {
|
||||
const setStep = (newStep: number) => {
|
||||
router.replace(`${href}?step=${newStep || 1}`, undefined, { shallow: true });
|
||||
};
|
||||
const [currentStepIsLoading, setCurrentStepIsLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setCurrentStepIsLoading(false);
|
||||
}, [currentStep]);
|
||||
|
||||
return (
|
||||
<div className="mx-auto mt-4 print:w-full">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img className="mx-auto mb-8 h-8" src="https://cal.com/logo.svg" alt="Cal.com Logo" />
|
||||
<div
|
||||
className={classNames(
|
||||
"mb-8 divide-y divide-gray-200 overflow-hidden rounded-lg bg-white shadow print:divide-transparent print:shadow-transparent",
|
||||
props.containerClassname
|
||||
)}>
|
||||
<div className="px-4 py-5 sm:px-6">
|
||||
<div className={classNames("overflow-hidden md:mb-2 md:w-[700px]", props.containerClassname)}>
|
||||
<div className="px-6 py-5 sm:px-14">
|
||||
<h1 className="font-cal text-2xl text-gray-900">{currentStep.title}</h1>
|
||||
<p className="text-sm text-gray-500">{currentStep.description}</p>
|
||||
{!props.disableNavigation && (
|
||||
<Steps maxSteps={steps.length} currentStep={step} navigateToStep={noop} stepLabel={stepLabel} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className={classNames("mb-8 overflow-hidden md:w-[700px]", props.containerClassname)}>
|
||||
<div className={classNames("print:p-none max-w-3xl px-8 py-5 sm:p-6", currentStep.contentClassname)}>
|
||||
{typeof currentStep.content === "function"
|
||||
? currentStep.content(setCurrentStepIsLoading)
|
||||
: currentStep.content}
|
||||
</div>
|
||||
|
||||
<div className="print:p-none max-w-3xl px-4 py-5 sm:p-6">{currentStep.content}</div>
|
||||
{!props.disableNavigation && (
|
||||
<>
|
||||
{currentStep.enabled !== false && (
|
||||
<div className="flex justify-end px-4 py-4 print:hidden sm:px-6">
|
||||
{step > 1 && (
|
||||
<Button
|
||||
color="secondary"
|
||||
onClick={() => {
|
||||
setStep(step - 1);
|
||||
}}>
|
||||
{prevLabel}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<Button
|
||||
tabIndex={0}
|
||||
loading={currentStep.isLoading}
|
||||
type="submit"
|
||||
color="primary"
|
||||
form={`wizard-step-${step}`}
|
||||
className="relative ml-2">
|
||||
{step < steps.length ? nextLabel : finishLabel}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex justify-end px-4 py-4 print:hidden sm:px-6">
|
||||
{step > 1 && (
|
||||
<Button
|
||||
color="secondary"
|
||||
onClick={() => {
|
||||
setStep(step - 1);
|
||||
}}>
|
||||
{prevLabel}
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
|
||||
<Button
|
||||
tabIndex={0}
|
||||
loading={currentStepIsLoading}
|
||||
type="submit"
|
||||
color="primary"
|
||||
form={`wizard-step-${step}`}
|
||||
disabled={currentStep.isEnabled === false}
|
||||
className="relative ml-2">
|
||||
{step < steps.length ? nextLabel : finishLabel}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{!props.disableNavigation && (
|
||||
<div className="print:hidden">
|
||||
<Stepper href={href} step={step} steps={steps} disableSteps stepLabel={stepLabel} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface NavTabProps {
|
||||
itemClassname?: string;
|
||||
}
|
||||
|
||||
const NavTabs = function ({ tabs, className = "", sticky, linkProps, ...props }: NavTabProps) {
|
||||
const NavTabs = function ({ tabs, className = "", sticky, linkProps, itemClassname, ...props }: NavTabProps) {
|
||||
return (
|
||||
<nav
|
||||
className={classNames(
|
||||
@@ -26,7 +26,7 @@ const NavTabs = function ({ tabs, className = "", sticky, linkProps, ...props }:
|
||||
{sticky && <div className="pt-6" />}
|
||||
{props.children}
|
||||
{tabs.map((tab, idx) => (
|
||||
<VerticalTabItem {...tab} key={idx} linkProps={linkProps} className={props.itemClassname} />
|
||||
<VerticalTabItem {...tab} key={idx} linkProps={linkProps} className={itemClassname} />
|
||||
))}
|
||||
</nav>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user