No more modules folder 🔥 (#6158)

Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
sean-brydonandPeer Richelsen authored and GitHub committed 2022-12-22 19:06:26 +00:00
1 parent 2fe9c782d4
commit 9d0cf6be0b
26 files changed
+29 -44

No files matched your search

@@ -0,0 +1,62 @@
import { useAutoAnimate } from "@formkit/auto-animate/react";
import { Props } from "react-select";
import { classNames } from "@calcom/lib";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Avatar, Icon, Select } from "@calcom/ui";
type CheckedSelectOption = {
avatar: string;
label: string;
value: string;
disabled?: boolean;
};
export const CheckedTeamSelect = ({
options = [],
value = [],
...props
}: Omit<Props<CheckedSelectOption, true>, "value" | "onChange"> & {
value?: readonly CheckedSelectOption[];
onChange: (value: readonly CheckedSelectOption[]) => void;
}) => {
const { t } = useLocale();
const [animationRef] = useAutoAnimate<HTMLUListElement>();
return (
<>
<Select
styles={{
option: (styles, { isDisabled }) => ({
...styles,
backgroundColor: isDisabled ? "#F5F5F5" : "inherit",
}),
}}
name={props.name}
placeholder={props.placeholder || t("select")}
isSearchable={false}
options={options}
value={value}
isMulti
{...props}
/>
{/* This class name conditional looks a bit odd but it allows a seemless transition when using autoanimate
- Slides down from the top instead of just teleporting in from nowhere*/}
<ul className={classNames("mt-3 rounded-md", value.length >= 1 && "border")} ref={animationRef}>
{value.map((option, index) => (
<li key={option.value} className={`flex py-2 px-3 ${index === value.length - 1 ? "" : "border-b"}`}>
<Avatar size="sm" imageSrc={option.avatar} alt={option.label} />
<p className="my-auto ml-3 text-sm text-gray-900">{option.label}</p>
<Icon.FiX
onClick={() => props.onChange(value.filter((item) => item.value !== option.value))}
className="my-auto ml-auto"
/>
</li>
))}
</ul>
</>
);
};
export default CheckedTeamSelect;
@@ -0,0 +1,41 @@
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Badge, Button, ButtonGroup, Icon } from "@calcom/ui";
type Props = {
required?: boolean;
question?: string;
type?: string;
editOnClick: () => void;
deleteOnClick: () => void;
};
function CustomInputItem({ required, deleteOnClick, editOnClick, type, question }: Props) {
const { t } = useLocale();
return (
<li className="flex rounded-b-md border-t border-gray-200 bg-white px-6 py-4 first:rounded-t-md first:border-0">
<div className="flex flex-col">
<div className="flex items-center">
<span className="pr-2 text-sm font-semibold leading-none text-black">{question}</span>
<Badge variant="default" color="gray" withDot={false}>
{required ? t("required") : t("optional")}
</Badge>
</div>
<p className="text-sm leading-normal text-gray-600">{type}</p>
</div>
<ButtonGroup containerProps={{ className: "ml-auto" }}>
<Button color="secondary" onClick={editOnClick}>
{t("edit")}
</Button>
<Button
StartIcon={Icon.FiTrash}
size="icon"
color="destructive"
onClick={deleteOnClick}
className="h-[36px] border border-gray-200"
/>
</ButtonGroup>
</li>
);
}
export default CustomInputItem;
@@ -0,0 +1,119 @@
import { Prisma, SchedulingType } from "@prisma/client";
import { useMemo } from "react";
import { FormattedNumber, IntlProvider } from "react-intl";
import { z } from "zod";
import { classNames, parseRecurringEvent } from "@calcom/lib";
import getStripeAppData from "@calcom/lib/getStripeAppData";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { baseEventTypeSelect } from "@calcom/prisma";
import { EventTypeModel } from "@calcom/prisma/zod";
import { Badge, Icon } from "@calcom/ui";
export type EventTypeDescriptionProps = {
eventType: Pick<
z.infer<typeof EventTypeModel>,
Exclude<keyof typeof baseEventTypeSelect, "recurringEvent"> | "metadata"
> & {
recurringEvent: Prisma.JsonValue;
};
className?: string;
};
export const EventTypeDescription = ({ eventType, className }: EventTypeDescriptionProps) => {
const { t } = useLocale();
const recurringEvent = useMemo(
() => parseRecurringEvent(eventType.recurringEvent),
[eventType.recurringEvent]
);
const stripeAppData = getStripeAppData(eventType);
return (
<>
<div className={classNames("dark:text-darkgray-800 text-neutral-500", className)}>
{eventType.description && (
<p className="dark:text-darkgray-800 max-w-[280px] break-words py-1 text-sm text-gray-500 sm:max-w-[500px]">
{eventType.description.substring(0, 300)}
{eventType.description.length > 300 && "..."}
</p>
)}
<ul className="mt-2 flex flex-wrap space-x-2 sm:flex-nowrap">
{eventType.metadata?.multipleDuration ? (
eventType.metadata.multipleDuration.map((dur, idx) => (
<li key={idx}>
<Badge variant="gray" size="lg" StartIcon={Icon.FiClock}>
{dur}m
</Badge>
</li>
))
) : (
<li>
<Badge variant="gray" size="lg" StartIcon={Icon.FiClock}>
{eventType.length}m
</Badge>
</li>
)}
{eventType.schedulingType ? (
<li>
<Badge variant="gray" size="lg" StartIcon={Icon.FiUser}>
{eventType.schedulingType === SchedulingType.ROUND_ROBIN && t("round_robin")}
{eventType.schedulingType === SchedulingType.COLLECTIVE && t("collective")}
</Badge>
</li>
) : (
<li>
<Badge variant="gray" size="lg" StartIcon={Icon.FiUser}>
{t("1_on_1")}
</Badge>
</li>
)}
{recurringEvent?.count && recurringEvent.count > 0 && (
<li className="hidden xl:block">
<Badge variant="gray" size="lg" StartIcon={Icon.FiRefreshCw}>
{t("repeats_up_to", {
count: recurringEvent.count,
})}
</Badge>
</li>
)}
{stripeAppData.price > 0 && (
<li>
<Badge variant="gray" size="lg" StartIcon={Icon.FiCreditCard}>
<IntlProvider locale="en">
<FormattedNumber
value={stripeAppData.price / 100.0}
style="currency"
currency={stripeAppData.currency.toUpperCase()}
/>
</IntlProvider>
</Badge>
</li>
)}
{eventType.requiresConfirmation && (
<li className="hidden xl:block">
<Badge variant="gray" size="lg" StartIcon={Icon.FiClipboard}>
{eventType.metadata?.requiresConfirmationThreshold
? t("may_require_confirmation")
: t("requires_confirmation")}
</Badge>
</li>
)}
{/* TODO: Maybe add a tool tip to this? */}
{eventType.requiresConfirmation || (recurringEvent?.count && recurringEvent.count) ? (
<li className="block xl:hidden">
<Badge variant="gray" size="lg" StartIcon={Icon.FiPlus}>
<p>{[eventType.requiresConfirmation, recurringEvent?.count].filter(Boolean).length}</p>
</Badge>
</li>
) : (
<></>
)}
</ul>
</div>
</>
);
};
export default EventTypeDescription;
@@ -0,0 +1,103 @@
import { components, GroupBase, Props, ValueContainerProps } from "react-select";
import { Icon, Select } from "../../..";
const LimitedChipsContainer = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>({
children,
...props
}: ValueContainerProps<Option, IsMulti, Group>) => {
if (!props.hasValue) {
return <components.ValueContainer {...props}>{children as React.ReactNode[]}</components.ValueContainer>;
}
const CHIPS_LIMIT = 2;
// TODO:: fix the following ts error
// @ts-expect-error: @see children is an array but identified as object resulting in the error
const [chips, other] = children;
const overflowCounter = chips.slice(CHIPS_LIMIT).length;
const displayChips = chips.slice(overflowCounter, overflowCounter + CHIPS_LIMIT);
return (
<components.ValueContainer {...props}>
{displayChips}
{overflowCounter > 0 && (
<span className="flex items-center justify-center rounded-md bg-gray-100 py-[5px] px-2 text-[14px] font-medium leading-4 text-gray-700">
<>
<Icon.FiPlus className="mr-1 inline h-3 w-3 stroke-[3px]" /> <span>{overflowCounter} more</span>
</>
</span>
)}
{other}
</components.ValueContainer>
);
};
export const MultiDropdownSelect = ({ options = [], value = [], ...props }: Props) => {
// const { t } = useLocale();
return (
<Select
styles={{
multiValue: (styles) => {
return {
...styles,
backgroundColor: "#F3F4F6",
color: "#374151",
borderRadius: "6px",
padding: "5px 8px",
gap: "8px",
fontSize: "14px",
fontWeight: "500",
margin: "0px",
lineHeight: "16px",
};
},
multiValueLabel: (styles) => ({
...styles,
paddingLeft: "0px",
fontSize: "14px",
padding: "0",
}),
multiValueRemove: (base) => ({
...base,
color: "#4B5563",
padding: "0",
":hover": {
background: "transparent",
},
"> svg": {
width: "16px",
height: "17px",
},
}),
control: (base) => ({
...base,
// Brute force to remove focus outline of input
"& .cal-multiselect__input": {
borderWidth: 0,
boxShadow: "none",
caretColor: "transparent",
},
}),
valueContainer: (base) => ({
...base,
display: "flex",
gap: "4px",
paddingLeft: "5px",
padding: "0px",
height: "36px",
}),
}}
className="cal-multiselect"
classNamePrefix="cal-multiselect"
placeholder="Select"
defaultValue={value}
options={options}
hideSelectedOptions={false}
isMulti
components={{ ValueContainer: LimitedChipsContainer }}
{...props}
/>
);
};
export default MultiDropdownSelect;
@@ -0,0 +1,7 @@
import dynamic from "next/dynamic";
export { default as CheckedTeamSelect } from "./CheckedTeamSelect";
export { default as CustomInputItem } from "./CustomInputItem";
export { default as CreateEventTypeButton } from "./CreateEventTypeButton";
export { default as EventTypeDescription } from "./EventTypeDescription";
export const EventTypeDescriptionLazy = dynamic(() => import("./EventTypeDescription"));