fix: Routing Form - Small Improvements (#17538)

Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
Hariom BalharaandUdit Takkar authored and GitHub committed 2024-11-11 14:14:39 +05:30
1 parent aaf630f01f
commit 62aaba32cf
8 files changed
+62 -21

No files matched your search

+39 -8
View File
@@ -1,16 +1,22 @@
"use client";
import Link from "next/link";
import { useState } from "react";
import { classNames } from "@calcom/lib";
import type { BadgeProps } from "../badge";
import { Badge } from "../badge";
import { Divider } from "../divider";
import { Input } from "../form/inputs/TextField";
import { Icon } from "../icon";
type Action = { check: () => boolean; fn: () => void };
export default function FormCard({
children,
label,
isLabelEditable,
onLabelChange,
deleteField,
moveUp,
moveDown,
@@ -19,7 +25,9 @@ export default function FormCard({
...restProps
}: {
children: React.ReactNode;
label?: React.ReactNode;
label: string;
isLabelEditable?: boolean;
onLabelChange?: (label: string) => void;
deleteField?: Action | null;
moveUp?: Action | null;
moveDown?: Action | null;
@@ -31,6 +39,12 @@ export default function FormCard({
"flex items-center group relative w-full rounded-md p-4 border border-subtle"
);
const [isCollapsed, setIsCollapsed] = useState(false);
const toggleFormCard = () => {
setIsCollapsed((prev) => !prev);
};
return (
<div className={className} {...restProps}>
<div>
@@ -54,26 +68,43 @@ export default function FormCard({
<div className="w-full">
<div className="flex items-center justify-between">
<div>
<span className="text-emphasis text-sm font-semibold">{label}</span>
{isLabelEditable ? (
<Input type="text" value={label} onChange={(e) => onLabelChange?.(e.target.value)} />
) : (
<span className="text-emphasis text-sm font-semibold">{label}</span>
)}
{badge && (
<Badge className="ml-2" variant={badge.variant}>
{badge.href ? <Link href={badge.href}>{badge.text}</Link> : badge.text}
</Badge>
)}
</div>
{deleteField?.check() ? (
<div>
<button
type="button"
onClick={() => {
deleteField?.fn();
toggleFormCard();
}}
color="secondary">
<Icon name="trash-2" className="text-default h-4 w-4" />
<Icon name="chevrons-down-up" className="text-default h-4 w-4" />
</button>
) : null}
{deleteField?.check() ? (
<button
type="button"
className="ml-2"
onClick={() => {
deleteField?.fn();
}}
color="secondary">
<Icon name="trash-2" className="text-default h-4 w-4" />
</button>
) : null}
</div>
</div>
<div className={isCollapsed ? "hidden" : ""}>
<Divider className="mb-6 mt-3" />
{children}
</div>
<Divider className="mb-6 mt-3" />
{children}
</div>
</div>
);
+2 -1
View File
@@ -135,5 +135,6 @@ export const lucideIconList = new Set([
"webhook",
"x",
"zap",
"waypoints"
"waypoints",
"chevrons-down-up",
]);
@@ -33,6 +33,7 @@ export type IconName =
| "chevron-left"
| "chevron-right"
| "chevron-up"
| "chevrons-down-up"
| "chevrons-left"
| "chevrons-right"
| "circle-alert"