@confidencesystemsinc/sdk 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -51
- package/dist/components/playbook/confidence-playbook.d.ts +11 -9
- package/dist/components/playbook/playbook-header.d.ts +2 -2
- package/dist/hooks/usePlaybookExpandedTasks.d.ts +3 -1
- package/dist/index.cjs +15 -15
- package/dist/index.js +1542 -1508
- package/package.json +2 -3
- package/src/components/badge.tsx +0 -116
- package/src/components/initiate-playbook-modal/InitiatePlaybookModal.tsx +0 -53
- package/src/components/playbook/confidence-playbook.tsx +0 -351
- package/src/components/playbook/playbook-header.tsx +0 -32
- package/src/components/playbook-button/ConfidencePlaybookButton.tsx +0 -79
- package/src/components/task/confidence-task.tsx +0 -297
- package/src/components/task/task-buttons.tsx +0 -35
- package/src/components/task/task-dropdown-badge.tsx +0 -118
- package/src/components/task/task-expanded-content.tsx +0 -46
- package/src/components/task/task-left-panel.tsx +0 -60
- package/src/components/task/task-status-badge.tsx +0 -23
- package/src/components/ui/button.tsx +0 -272
- package/src/components/ui/input.tsx +0 -39
- package/src/components/ui/modal.tsx +0 -88
- package/src/components/ui/ui-wrapper.tsx +0 -7
- package/src/constants/settings.constants.ts +0 -4
- package/src/context/confidence-context.tsx +0 -25
- package/src/hooks/task/useCompleteTask.ts +0 -32
- package/src/hooks/task/useStartTask.ts +0 -35
- package/src/hooks/task/useTaskDetails.ts +0 -42
- package/src/hooks/usePlaybook.ts +0 -54
- package/src/hooks/usePlaybookActions.ts +0 -69
- package/src/hooks/usePlaybookExpandedTasks.ts +0 -35
- package/src/hooks/useTaskButtons.ts +0 -47
- package/src/index.ts +0 -7
- package/src/services/complete-task.service.ts +0 -25
- package/src/services/initiate-playbook.service.ts +0 -26
- package/src/services/start-task.services.ts +0 -27
- package/src/services/task-details.service.ts +0 -17
- package/src/stories/confidence-playbook.stories.tsx +0 -125
- package/src/stories/confidence-task.stories.tsx +0 -63
- package/src/stories/initiate-playbook-modal.stories.tsx +0 -31
- package/src/stories/modal.stories.tsx +0 -50
- package/src/task-description.css +0 -629
- package/src/theme.css +0 -11
- package/src/types/playbook.types.ts +0 -22
- package/src/types/task.types.ts +0 -20
- package/src/utils/cn.ts +0 -6
- package/src/vite-env.d.ts +0 -1
package/package.json
CHANGED
package/src/components/badge.tsx
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { type ComponentPropsWithoutRef, useMemo } from "react";
|
|
2
|
-
import { twMerge } from "tailwind-merge";
|
|
3
|
-
|
|
4
|
-
export const BadgeSolid = {
|
|
5
|
-
white: "bg-white text-dark-300 border border-gray-300",
|
|
6
|
-
primary: "bg-primary-600",
|
|
7
|
-
secondary: "bg-secondary-500",
|
|
8
|
-
success: "bg-success-600",
|
|
9
|
-
info: "bg-info-500",
|
|
10
|
-
warning: "bg-warning-500 text-gray-800",
|
|
11
|
-
danger: "bg-danger-500",
|
|
12
|
-
steel: "bg-steel-500",
|
|
13
|
-
orange: "bg-orange-500",
|
|
14
|
-
purple: "bg-purple-500",
|
|
15
|
-
grayDark: "bg-gray-900",
|
|
16
|
-
grayLight: "bg-gray-100 text-gray-800",
|
|
17
|
-
} as const;
|
|
18
|
-
|
|
19
|
-
export const BadgeOutline = {
|
|
20
|
-
white: "text-white border border-white",
|
|
21
|
-
primary: "text-primary-600 border border-primary-600",
|
|
22
|
-
secondary: "text-secondary-500 border border-secondary-500",
|
|
23
|
-
success: "text-success-600 border border-success-600",
|
|
24
|
-
info: "text-info-500 border border-info-500",
|
|
25
|
-
warning: "text-warning-500 border border-warning-500",
|
|
26
|
-
danger: "text-danger-500 border border-danger-500",
|
|
27
|
-
steel: "text-steel-500 border border-steel-500",
|
|
28
|
-
orange: "text-orange-500 border border-orange-500",
|
|
29
|
-
purple: "text-purple-500 border border-purple-500",
|
|
30
|
-
grayDark: "text-gray-700 border border-gray-700",
|
|
31
|
-
grayLight: "text-gray-500 border border-gray-100",
|
|
32
|
-
} as const;
|
|
33
|
-
|
|
34
|
-
const BadgeFontColor = {
|
|
35
|
-
white: "text-dark-300",
|
|
36
|
-
primary: "text-white",
|
|
37
|
-
secondary: "text-white",
|
|
38
|
-
success: "text-white",
|
|
39
|
-
info: "text-black",
|
|
40
|
-
warning: "text-gray-800",
|
|
41
|
-
danger: "text-white",
|
|
42
|
-
steel: "text-white",
|
|
43
|
-
orange: "text-black",
|
|
44
|
-
purple: "text-white",
|
|
45
|
-
grayDark: "text-white",
|
|
46
|
-
grayLight: "text-gray-800",
|
|
47
|
-
} as const;
|
|
48
|
-
|
|
49
|
-
export const BadgeRoundness = {
|
|
50
|
-
normal: "rounded",
|
|
51
|
-
pill: "rounded-pill",
|
|
52
|
-
} as const;
|
|
53
|
-
|
|
54
|
-
const BadgeSize = {
|
|
55
|
-
big: "h-[24px] leading-[24px] text-md px-1",
|
|
56
|
-
medium: "h-[22px] leading-[22px] text-sm px-[2px]",
|
|
57
|
-
small: "h-[18px] leading-[18px] text-xs px-[2px]",
|
|
58
|
-
} as const;
|
|
59
|
-
|
|
60
|
-
export interface BadgeProps extends ComponentPropsWithoutRef<"div"> {
|
|
61
|
-
category?: "solid" | "outline";
|
|
62
|
-
color?: keyof typeof BadgeSolid;
|
|
63
|
-
roundness?: keyof typeof BadgeRoundness;
|
|
64
|
-
size?: keyof typeof BadgeSize;
|
|
65
|
-
textClassName?: string;
|
|
66
|
-
children: React.ReactNode;
|
|
67
|
-
onClose?: () => void;
|
|
68
|
-
onArrowClick?: () => void;
|
|
69
|
-
className?: string;
|
|
70
|
-
onCustomIconClick?: () => void;
|
|
71
|
-
arrowTitle?: string;
|
|
72
|
-
closeTitle?: string;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const Badge = ({
|
|
76
|
-
category = "solid",
|
|
77
|
-
color = "primary",
|
|
78
|
-
roundness = "normal",
|
|
79
|
-
size = "medium",
|
|
80
|
-
textClassName = "uppercase",
|
|
81
|
-
children,
|
|
82
|
-
className,
|
|
83
|
-
...rest
|
|
84
|
-
}: BadgeProps) => {
|
|
85
|
-
const fontColor = useMemo(
|
|
86
|
-
() => BadgeFontColor[color] ?? "text-white",
|
|
87
|
-
[color],
|
|
88
|
-
);
|
|
89
|
-
const BadgeClasses = useMemo(
|
|
90
|
-
() =>
|
|
91
|
-
twMerge(
|
|
92
|
-
fontColor,
|
|
93
|
-
category === "outline" ? BadgeOutline[color] : BadgeSolid[color],
|
|
94
|
-
BadgeRoundness[roundness],
|
|
95
|
-
BadgeSize[size],
|
|
96
|
-
),
|
|
97
|
-
[fontColor, category, color, size, roundness],
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
<div
|
|
102
|
-
className={twMerge(
|
|
103
|
-
"ui-badge flex items-center font-bold",
|
|
104
|
-
BadgeClasses,
|
|
105
|
-
className,
|
|
106
|
-
)}
|
|
107
|
-
style={rest?.style}
|
|
108
|
-
data-testid={`badge`}
|
|
109
|
-
data-category={category}
|
|
110
|
-
data-color={color}
|
|
111
|
-
{...rest}
|
|
112
|
-
>
|
|
113
|
-
<p className={twMerge("mx-1", textClassName)}>{children}</p>
|
|
114
|
-
</div>
|
|
115
|
-
);
|
|
116
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
import { Modal } from "../ui/modal";
|
|
3
|
-
import { InputField } from "../ui/input";
|
|
4
|
-
|
|
5
|
-
export const InitiatePlaybookModal = ({
|
|
6
|
-
onConfirm,
|
|
7
|
-
onClose,
|
|
8
|
-
isOpen,
|
|
9
|
-
title,
|
|
10
|
-
}: {
|
|
11
|
-
onConfirm: (email: string) => void | Promise<void>;
|
|
12
|
-
onClose: () => void;
|
|
13
|
-
isOpen: boolean;
|
|
14
|
-
title?: string;
|
|
15
|
-
}) => {
|
|
16
|
-
const [email, setEmail] = useState("");
|
|
17
|
-
const [isConfirming, setIsConfirming] = useState(false);
|
|
18
|
-
const handleConfirm = async () => {
|
|
19
|
-
if (email) {
|
|
20
|
-
try {
|
|
21
|
-
setIsConfirming(true);
|
|
22
|
-
await onConfirm(email);
|
|
23
|
-
setEmail(""); // Reset email after confirmation
|
|
24
|
-
} finally {
|
|
25
|
-
setIsConfirming(false);
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
alert("Please enter a valid email address.");
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
return (
|
|
32
|
-
<Modal
|
|
33
|
-
title={title || "Initiate Confidence Playbook"}
|
|
34
|
-
isOpen={isOpen}
|
|
35
|
-
close={onClose}
|
|
36
|
-
dismissOptions={{ label: "Cancel", onClick: onClose }}
|
|
37
|
-
confirmOptions={{
|
|
38
|
-
label: "Initiate",
|
|
39
|
-
onClick: handleConfirm,
|
|
40
|
-
disabled: isConfirming || !email,
|
|
41
|
-
}}
|
|
42
|
-
>
|
|
43
|
-
<>
|
|
44
|
-
<InputField
|
|
45
|
-
label="Email"
|
|
46
|
-
disabled={isConfirming}
|
|
47
|
-
description="Enter the email address to initiate the playbook."
|
|
48
|
-
onChange={(e) => setEmail(e.target.value)}
|
|
49
|
-
/>
|
|
50
|
-
</>
|
|
51
|
-
</Modal>
|
|
52
|
-
);
|
|
53
|
-
};
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
import { ConfidenceContext } from "../../context/confidence-context";
|
|
3
|
-
import { usePlaybook } from "../../hooks/usePlaybook";
|
|
4
|
-
import { TASK_BUTTONS, TaskButton } from "../../hooks/useTaskButtons";
|
|
5
|
-
import { initiatePlaybook } from "../../services/initiate-playbook.service";
|
|
6
|
-
import { Playbook } from "../../types/playbook.types";
|
|
7
|
-
import { TASK_STATUS } from "../../types/task.types";
|
|
8
|
-
import { cn } from "../../utils/cn";
|
|
9
|
-
import { ConfidencePlaybookButton } from "../playbook-button/ConfidencePlaybookButton";
|
|
10
|
-
import { ConfidenceTask } from "../task/confidence-task";
|
|
11
|
-
import { PlaybookHeader } from "./playbook-header";
|
|
12
|
-
import ConfidenceLogo from "../../../public/confidence_logo.png";
|
|
13
|
-
import { usePlaybookExpandedTasks } from "../../hooks/usePlaybookExpandedTasks";
|
|
14
|
-
export interface ConfidencePlaybookStyleConfiguration {
|
|
15
|
-
overlay?: {
|
|
16
|
-
position?: "left" | "right";
|
|
17
|
-
size?: {
|
|
18
|
-
width?: number | string;
|
|
19
|
-
height?: number | string;
|
|
20
|
-
};
|
|
21
|
-
offset?: {
|
|
22
|
-
top?: number | string;
|
|
23
|
-
right?: number | string;
|
|
24
|
-
left?: number | string;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
whiteLabel?: {
|
|
28
|
-
titleBackgroundColor?: string;
|
|
29
|
-
titleTextColor?: string;
|
|
30
|
-
primaryColor?: string;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const ConfidencePlaybookInternal = ({
|
|
35
|
-
playbookInstanceId,
|
|
36
|
-
playbookMode,
|
|
37
|
-
playbookStyle,
|
|
38
|
-
}: {
|
|
39
|
-
playbookInstanceId: string | number;
|
|
40
|
-
playbookMode: "list" | "card";
|
|
41
|
-
playbookStyle?: ConfidencePlaybookStyleConfiguration;
|
|
42
|
-
}) => {
|
|
43
|
-
const { playbook, actions: playbookActions } =
|
|
44
|
-
usePlaybook(playbookInstanceId);
|
|
45
|
-
|
|
46
|
-
if (!playbook) {
|
|
47
|
-
return <div></div>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const handleButtonClick = async (buttonType: TaskButton, taskId: number) => {
|
|
51
|
-
if (buttonType === TASK_BUTTONS.COMPLETE) {
|
|
52
|
-
const sequenceOrder = playbook.tasks.find(
|
|
53
|
-
(task) => task.taskInstanceId === taskId,
|
|
54
|
-
)?.sequenceOrder;
|
|
55
|
-
if (sequenceOrder === undefined) {
|
|
56
|
-
console.error("Task not found in playbook");
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return playbookActions.completeTask(taskId, sequenceOrder);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (buttonType === TASK_BUTTONS.START) {
|
|
64
|
-
return playbookActions.startTask(taskId);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<PlaybookView
|
|
70
|
-
playbook={playbook}
|
|
71
|
-
playbookMode={playbookMode}
|
|
72
|
-
onTaskButtonClick={handleButtonClick}
|
|
73
|
-
playbookStyle={playbookStyle}
|
|
74
|
-
/>
|
|
75
|
-
);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const TasksContainer = ({
|
|
79
|
-
className,
|
|
80
|
-
children,
|
|
81
|
-
numberOfTasks,
|
|
82
|
-
playbookMode,
|
|
83
|
-
}: {
|
|
84
|
-
className?: string;
|
|
85
|
-
children: React.ReactNode;
|
|
86
|
-
numberOfTasks?: number; // Default to 3 if not provided
|
|
87
|
-
playbookMode: "list" | "card";
|
|
88
|
-
}) => {
|
|
89
|
-
return (
|
|
90
|
-
<div className={cn("w-full p-4", className)}>
|
|
91
|
-
{numberOfTasks && (
|
|
92
|
-
<div className={cn(playbookMode === "card" && "mb-4")}>
|
|
93
|
-
<span className="font-medium">Tasks</span> (3)
|
|
94
|
-
</div>
|
|
95
|
-
)}
|
|
96
|
-
<div className={cn(playbookMode === "card" && "space-y-4")}>
|
|
97
|
-
{children}
|
|
98
|
-
</div>
|
|
99
|
-
</div>
|
|
100
|
-
);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const PlaybookView = ({
|
|
104
|
-
playbook,
|
|
105
|
-
playbookMode,
|
|
106
|
-
onTaskButtonClick,
|
|
107
|
-
playbookStyle,
|
|
108
|
-
}: {
|
|
109
|
-
playbookMode: "list" | "card";
|
|
110
|
-
playbook: Playbook;
|
|
111
|
-
onTaskButtonClick: (btn: TaskButton, taskId: number) => Promise<void>;
|
|
112
|
-
playbookStyle?: ConfidencePlaybookStyleConfiguration;
|
|
113
|
-
}) => {
|
|
114
|
-
const { playbookInstanceName, tasks } = playbook;
|
|
115
|
-
const playbookHeaderRef = useRef<HTMLDivElement>(null);
|
|
116
|
-
const [playbookHeaderHeight, setPlaybookHeaderHeight] = useState(0);
|
|
117
|
-
const { isTaskExpanded, toggleTaskExpanded } = usePlaybookExpandedTasks(
|
|
118
|
-
playbook.playbookInstanceId,
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
useEffect(() => {
|
|
122
|
-
if (playbookHeaderRef.current) {
|
|
123
|
-
/** Setup a resize observer */
|
|
124
|
-
const resizeObserver = new ResizeObserver((entries) => {
|
|
125
|
-
for (const entry of entries) {
|
|
126
|
-
console.log("ResizeObserver entry:", entry);
|
|
127
|
-
if (entry.contentRect) {
|
|
128
|
-
setPlaybookHeaderHeight(
|
|
129
|
-
playbookHeaderRef.current?.offsetHeight || 0,
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
resizeObserver.observe(playbookHeaderRef.current);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return () => {
|
|
138
|
-
if (playbookHeaderRef.current) {
|
|
139
|
-
/** Cleanup the resize observer */
|
|
140
|
-
const resizeObserver = new ResizeObserver(() => {});
|
|
141
|
-
resizeObserver.unobserve(playbookHeaderRef.current);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
}, [playbookHeaderRef]);
|
|
145
|
-
const sequenceOrderToStart = useMemo(() => {
|
|
146
|
-
const lastCompletedTask = tasks.find(
|
|
147
|
-
(task) => task.workflowStatus === TASK_STATUS.COMPLETED,
|
|
148
|
-
);
|
|
149
|
-
if (!lastCompletedTask) {
|
|
150
|
-
return 0;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return lastCompletedTask.sequenceOrder + 1;
|
|
154
|
-
}, [tasks]);
|
|
155
|
-
|
|
156
|
-
return (
|
|
157
|
-
<div
|
|
158
|
-
className={cn(
|
|
159
|
-
!playbookStyle?.overlay && "min-h-screen",
|
|
160
|
-
playbookStyle?.overlay && "fixed bottom-0 z-[99999999999999] flex",
|
|
161
|
-
)}
|
|
162
|
-
{...(playbookStyle?.overlay && {
|
|
163
|
-
style: {
|
|
164
|
-
width: playbookStyle.overlay.size?.width || 450,
|
|
165
|
-
height: playbookStyle.overlay.size?.height || "calc(100vh - 4rem)",
|
|
166
|
-
maxHeight: "calc(100vh - 4rem)",
|
|
167
|
-
right:
|
|
168
|
-
playbookStyle.overlay.offset?.right !== undefined
|
|
169
|
-
? playbookStyle.overlay.offset.right
|
|
170
|
-
: playbookStyle.overlay.position === "right"
|
|
171
|
-
? 32
|
|
172
|
-
: undefined,
|
|
173
|
-
left:
|
|
174
|
-
playbookStyle.overlay.offset?.left !== undefined
|
|
175
|
-
? playbookStyle.overlay.offset.left
|
|
176
|
-
: playbookStyle.overlay.position === "left"
|
|
177
|
-
? 32
|
|
178
|
-
: undefined,
|
|
179
|
-
},
|
|
180
|
-
})}
|
|
181
|
-
>
|
|
182
|
-
{playbookStyle?.overlay && (
|
|
183
|
-
<div
|
|
184
|
-
className={cn(
|
|
185
|
-
"size-9 relative p-1 top-3 z-[99999999999999] border-none rounded-l-sm ",
|
|
186
|
-
)}
|
|
187
|
-
style={{
|
|
188
|
-
backgroundColor:
|
|
189
|
-
playbookStyle?.whiteLabel?.primaryColor || "#007BFF",
|
|
190
|
-
boxShadow: "0px 3px 3px 0px #00000040",
|
|
191
|
-
}}
|
|
192
|
-
>
|
|
193
|
-
<img
|
|
194
|
-
src={ConfidenceLogo}
|
|
195
|
-
alt="Confidence Logo"
|
|
196
|
-
className="w-full h-full object-contain"
|
|
197
|
-
/>
|
|
198
|
-
</div>
|
|
199
|
-
)}
|
|
200
|
-
<div
|
|
201
|
-
className={cn(
|
|
202
|
-
"flex flex-col flex-1 bg-gray-50",
|
|
203
|
-
playbookStyle?.overlay &&
|
|
204
|
-
"border border-gray-200 shadow-2xl rounded-t-sm overflow-y-auto",
|
|
205
|
-
)}
|
|
206
|
-
>
|
|
207
|
-
<PlaybookHeader
|
|
208
|
-
title={playbookInstanceName}
|
|
209
|
-
className={cn("top-0 sticky z-2")}
|
|
210
|
-
playbookStyle={playbookStyle}
|
|
211
|
-
ref={playbookHeaderRef}
|
|
212
|
-
/>
|
|
213
|
-
|
|
214
|
-
<TasksContainer
|
|
215
|
-
playbookMode={playbookMode}
|
|
216
|
-
numberOfTasks={playbook.numberofTasks}
|
|
217
|
-
>
|
|
218
|
-
{tasks.map((task, index) => {
|
|
219
|
-
return (
|
|
220
|
-
<ConfidenceTask
|
|
221
|
-
key={index}
|
|
222
|
-
task={task}
|
|
223
|
-
step={index + 1}
|
|
224
|
-
viewMode={playbookMode}
|
|
225
|
-
playbookId={playbook.playbookId}
|
|
226
|
-
canStart={task.sequenceOrder === sequenceOrderToStart}
|
|
227
|
-
onButtonClick={(btn) => {
|
|
228
|
-
return onTaskButtonClick(btn, task.taskInstanceId);
|
|
229
|
-
}}
|
|
230
|
-
playbookType={"Non-Sequential"}
|
|
231
|
-
taskStyle={{
|
|
232
|
-
titleColor: playbookStyle?.whiteLabel?.primaryColor,
|
|
233
|
-
}}
|
|
234
|
-
isExpanded={isTaskExpanded(task.taskInstanceId)}
|
|
235
|
-
toggleExpanded={() => toggleTaskExpanded(task.taskInstanceId)}
|
|
236
|
-
listStickyTopBase={playbookHeaderHeight || 104} // Adjust this value based on your header height
|
|
237
|
-
/>
|
|
238
|
-
);
|
|
239
|
-
})}
|
|
240
|
-
</TasksContainer>
|
|
241
|
-
</div>
|
|
242
|
-
</div>
|
|
243
|
-
);
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
const AutoInstantiated = ({
|
|
247
|
-
email,
|
|
248
|
-
playbookId,
|
|
249
|
-
playbookMode,
|
|
250
|
-
}: {
|
|
251
|
-
email: string;
|
|
252
|
-
playbookId: string;
|
|
253
|
-
playbookMode: "list" | "card";
|
|
254
|
-
}) => {
|
|
255
|
-
const [playbookInstanceId, setPlaybookInstanceId] = useState<number | null>(
|
|
256
|
-
null,
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
useEffect(() => {
|
|
260
|
-
(async () => {
|
|
261
|
-
const { playbookInstanceId, errorCode, details, message } =
|
|
262
|
-
(await initiatePlaybook({
|
|
263
|
-
bank: "public-sdk",
|
|
264
|
-
email,
|
|
265
|
-
timezone:
|
|
266
|
-
Intl.DateTimeFormat().resolvedOptions().timeZone ||
|
|
267
|
-
"America/Los_Angeles",
|
|
268
|
-
playbookUid: playbookId,
|
|
269
|
-
})) || {};
|
|
270
|
-
|
|
271
|
-
if (errorCode) {
|
|
272
|
-
throw new Error(
|
|
273
|
-
`Error initiating playbook: ${message} (Code: ${errorCode}) - Details: ${details}`,
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
setPlaybookInstanceId(playbookInstanceId);
|
|
278
|
-
})();
|
|
279
|
-
}, []);
|
|
280
|
-
|
|
281
|
-
if (!playbookInstanceId) {
|
|
282
|
-
return <div>Loading...</div>;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return (
|
|
286
|
-
<ConfidencePlaybook
|
|
287
|
-
playbookInstanceId={playbookInstanceId}
|
|
288
|
-
playbookMode={playbookMode}
|
|
289
|
-
/>
|
|
290
|
-
);
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
const WithInstantiateButton = ({
|
|
294
|
-
playbookId,
|
|
295
|
-
playbookMode = "list",
|
|
296
|
-
playbookStyle,
|
|
297
|
-
btnLabel = "Start Playbook",
|
|
298
|
-
}: {
|
|
299
|
-
playbookId: string;
|
|
300
|
-
playbookMode?: "list" | "card";
|
|
301
|
-
playbookStyle?: ConfidencePlaybookStyleConfiguration;
|
|
302
|
-
btnLabel?: string;
|
|
303
|
-
}) => {
|
|
304
|
-
const [playbookInstanceId, setPlaybookInstanceId] = useState<number | null>(
|
|
305
|
-
null,
|
|
306
|
-
);
|
|
307
|
-
|
|
308
|
-
return (
|
|
309
|
-
<>
|
|
310
|
-
<ConfidencePlaybookButton
|
|
311
|
-
playbookId={playbookId}
|
|
312
|
-
disabled={!!playbookInstanceId}
|
|
313
|
-
onInitiated={setPlaybookInstanceId}
|
|
314
|
-
btnLabel={btnLabel}
|
|
315
|
-
/>
|
|
316
|
-
|
|
317
|
-
{playbookInstanceId && (
|
|
318
|
-
<ConfidencePlaybook
|
|
319
|
-
playbookInstanceId={playbookInstanceId}
|
|
320
|
-
playbookMode={playbookMode}
|
|
321
|
-
playbookStyle={playbookStyle}
|
|
322
|
-
/>
|
|
323
|
-
)}
|
|
324
|
-
</>
|
|
325
|
-
);
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
export const ConfidencePlaybook = ({
|
|
329
|
-
playbookInstanceId,
|
|
330
|
-
playbookMode,
|
|
331
|
-
playbookStyle,
|
|
332
|
-
}: {
|
|
333
|
-
playbookInstanceId: string | number;
|
|
334
|
-
playbookMode: "list" | "card";
|
|
335
|
-
playbookStyle?: ConfidencePlaybookStyleConfiguration;
|
|
336
|
-
}) => {
|
|
337
|
-
return (
|
|
338
|
-
<ConfidenceContext>
|
|
339
|
-
<ConfidencePlaybookInternal
|
|
340
|
-
playbookInstanceId={playbookInstanceId}
|
|
341
|
-
playbookMode={playbookMode}
|
|
342
|
-
playbookStyle={playbookStyle}
|
|
343
|
-
/>
|
|
344
|
-
</ConfidenceContext>
|
|
345
|
-
);
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
ConfidencePlaybook.Context = ConfidenceContext;
|
|
349
|
-
ConfidencePlaybook.View = PlaybookView;
|
|
350
|
-
ConfidencePlaybook.AutoInstantiated = AutoInstantiated;
|
|
351
|
-
ConfidencePlaybook.WithInstantiateButton = WithInstantiateButton;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { cn } from "../../utils/cn";
|
|
2
|
-
import { type ConfidencePlaybookStyleConfiguration } from "./confidence-playbook";
|
|
3
|
-
|
|
4
|
-
export const PlaybookHeader = ({
|
|
5
|
-
title,
|
|
6
|
-
className,
|
|
7
|
-
playbookStyle,
|
|
8
|
-
...props
|
|
9
|
-
}: React.ComponentProps<"div"> & {
|
|
10
|
-
title: string;
|
|
11
|
-
playbookStyle?: ConfidencePlaybookStyleConfiguration;
|
|
12
|
-
}) => {
|
|
13
|
-
return (
|
|
14
|
-
<div
|
|
15
|
-
className={cn("border-b border-gray-200 flex items-center", className)}
|
|
16
|
-
style={{
|
|
17
|
-
backgroundColor:
|
|
18
|
-
playbookStyle?.whiteLabel?.titleBackgroundColor || "#f8f9fa",
|
|
19
|
-
}}
|
|
20
|
-
{...props}
|
|
21
|
-
>
|
|
22
|
-
<div
|
|
23
|
-
className="text-xl min-h-16 p-4"
|
|
24
|
-
style={{
|
|
25
|
-
color: playbookStyle?.whiteLabel?.titleTextColor,
|
|
26
|
-
}}
|
|
27
|
-
>
|
|
28
|
-
{title}
|
|
29
|
-
</div>
|
|
30
|
-
</div>
|
|
31
|
-
);
|
|
32
|
-
};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
import { initiatePlaybook } from "../../services/initiate-playbook.service";
|
|
3
|
-
import { InitiatePlaybookModal } from "../initiate-playbook-modal/InitiatePlaybookModal";
|
|
4
|
-
import Button, { ButtonSizeType } from "../ui/button";
|
|
5
|
-
|
|
6
|
-
export const ConfidencePlaybookButton = ({
|
|
7
|
-
btnClassName,
|
|
8
|
-
buttonNode,
|
|
9
|
-
size,
|
|
10
|
-
playbookId,
|
|
11
|
-
onInitiated,
|
|
12
|
-
disabled,
|
|
13
|
-
btnLabel = "Run Playbook",
|
|
14
|
-
}: {
|
|
15
|
-
btnClassName?: string;
|
|
16
|
-
buttonNode?: React.ReactNode;
|
|
17
|
-
size?: ButtonSizeType;
|
|
18
|
-
playbookId: string;
|
|
19
|
-
disabled?: boolean;
|
|
20
|
-
btnLabel?: string;
|
|
21
|
-
onInitiated: (playbookInstanceId: number) => void;
|
|
22
|
-
}) => {
|
|
23
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
24
|
-
|
|
25
|
-
function open() {
|
|
26
|
-
setIsOpen(true);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function close() {
|
|
30
|
-
setIsOpen(false);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const onInitiatePlaybook = async (email: string) => {
|
|
34
|
-
const { playbookInstanceId, errorCode, details, message } =
|
|
35
|
-
(await initiatePlaybook({
|
|
36
|
-
bank: "public-sdk",
|
|
37
|
-
email,
|
|
38
|
-
timezone:
|
|
39
|
-
Intl.DateTimeFormat().resolvedOptions().timeZone ||
|
|
40
|
-
"America/Los_Angeles",
|
|
41
|
-
playbookUid: playbookId,
|
|
42
|
-
})) || {};
|
|
43
|
-
|
|
44
|
-
if (errorCode) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
`Error initiating playbook: ${message} (Code: ${errorCode}) - Details: ${details}`,
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
onInitiated(playbookInstanceId);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<>
|
|
55
|
-
{buttonNode ? (
|
|
56
|
-
{ buttonNode }
|
|
57
|
-
) : (
|
|
58
|
-
<Button
|
|
59
|
-
onClick={open}
|
|
60
|
-
className={btnClassName}
|
|
61
|
-
color="primary"
|
|
62
|
-
size={size}
|
|
63
|
-
disabled={disabled}
|
|
64
|
-
>
|
|
65
|
-
{btnLabel}
|
|
66
|
-
</Button>
|
|
67
|
-
)}
|
|
68
|
-
|
|
69
|
-
<InitiatePlaybookModal
|
|
70
|
-
isOpen={isOpen}
|
|
71
|
-
onClose={close}
|
|
72
|
-
onConfirm={async (email) => {
|
|
73
|
-
await onInitiatePlaybook(email);
|
|
74
|
-
close();
|
|
75
|
-
}}
|
|
76
|
-
/>
|
|
77
|
-
</>
|
|
78
|
-
);
|
|
79
|
-
};
|