Files
calendar/packages/ui/components/form/switch/SettingsToggle.tsx
T
3c723d6f5b feat: Managed Events V2 (#12320)
* init

* Fix event limit interlinked switches

* wip

* WIP

* fix bugs

* lock hashed link until further notice

* lock private url for managed type to stop confusion

* fix recurring

* prettier fix

* early review fixes ...

* --WIP to send only changed form fields in updateMutation

* WIP with some type fixes

* Revert "WIP with some type fixes"

This reverts commit 00f10b772d6d08af17e7c9bd2d3601d93035d9b3.

* post merge conflict resolution fixes

* further type fix

* fixed test

* fixing e2e tests

* fix test --WIP

* attempt fix test & type --WIP

* fix duplicate locale en entry

* fix locked state persistence

* adds private URL locked/unlocked functionality

* fix tests

* Fix issue where locked labels showed up in non-managed events

* adds e2e test step

* update new test

* minor fixes

* fix test

* address changes request Part 1

fixed width on the lock badge
members default location as default selection
bugfix for offset toggle duplicate within itself

* fixes locked/unlocked label for child event types

* enable choice of destination calendar for children

* Fixes width for simple lock badge

* fix type

* fixes workflows list and apps for managed event type

* restricts creation of managed event types to EE only

* further fixes --WIP

* fix unit test for handleChildrenEventTypes

* fix test --WIP

* fix type err --WIP

* fix type err in test

* fix childevent payload

* fixes hashedLink bug

* fix test step title

* lock workflow create button when workflow is locked

* fix workflow detail

* Don't rely on parameter ordering, use object instead

* Removed console.log

* Missed one

---------

Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
2024-03-12 00:10:08 +00:00

122 lines
3.7 KiB
TypeScript

import { useAutoAnimate } from "@formkit/auto-animate/react";
import type { ReactNode } from "react";
import { classNames } from "@calcom/lib";
import { Label } from "..";
import Switch from "./Switch";
type Props = {
children?: ReactNode;
title: string;
description?: string | React.ReactNode;
checked: boolean;
disabled?: boolean;
LockedIcon?: React.ReactNode;
Badge?: React.ReactNode;
onCheckedChange?: (checked: boolean) => void;
"data-testid"?: string;
tooltip?: string;
toggleSwitchAtTheEnd?: boolean;
childrenClassName?: string;
switchContainerClassName?: string;
labelClassName?: string;
descriptionClassName?: string;
};
function SettingsToggle({
checked,
onCheckedChange,
description,
LockedIcon,
Badge,
title,
children,
disabled,
tooltip,
toggleSwitchAtTheEnd = false,
childrenClassName,
switchContainerClassName,
labelClassName,
descriptionClassName,
...rest
}: Props) {
const [animateRef] = useAutoAnimate<HTMLDivElement>();
return (
<>
<div className="flex w-full flex-col space-y-4 lg:flex-row lg:space-x-4 lg:space-y-0">
<fieldset className="block w-full flex-col sm:flex">
{toggleSwitchAtTheEnd ? (
<div
className={classNames(
"border-subtle flex justify-between space-x-3 rounded-lg border px-4 py-6 sm:px-6",
checked && children && "rounded-b-none",
switchContainerClassName
)}>
<div>
<div className="flex items-center gap-x-2" data-testid={`${rest["data-testid"]}-title`}>
<Label
className={classNames("mt-0.5 text-base font-semibold leading-none", labelClassName)}
htmlFor="">
{title}
{LockedIcon}
</Label>
{Badge && <div className="mb-2">{Badge}</div>}
</div>
{description && (
<p
className={classNames(
"text-default -mt-1.5 text-sm leading-normal",
descriptionClassName
)}
data-testid={`${rest["data-testid"]}-description`}>
{description}
</p>
)}
</div>
<div className="my-auto h-full">
<Switch
data-testid={rest["data-testid"]}
fitToHeight={true}
checked={checked}
onCheckedChange={onCheckedChange}
disabled={disabled}
tooltip={tooltip}
/>
</div>
</div>
) : (
<div className="flex space-x-3">
<Switch
data-testid={rest["data-testid"]}
fitToHeight={true}
checked={checked}
onCheckedChange={onCheckedChange}
disabled={disabled}
tooltip={tooltip}
/>
<div>
<Label
className={classNames("text-emphasis text-sm font-semibold leading-none", labelClassName)}>
{title}
{LockedIcon}
</Label>
{description && <p className="text-default -mt-1.5 text-sm leading-normal">{description}</p>}
</div>
</div>
)}
{children && (
<div className={classNames("lg:ml-14", childrenClassName)} ref={animateRef}>
{checked && <div className={classNames(!toggleSwitchAtTheEnd && "mt-4")}>{children}</div>}
</div>
)}
</fieldset>
</div>
</>
);
}
export default SettingsToggle;