MCPcopy Create free account
hub / github.com/dailydotdev/apps / PromptElement

Function PromptElement

packages/shared/src/components/modals/Prompt.tsx:21–127  ·  view source on GitHub ↗
(props: Partial<ModalProps>)

Source from the content-addressed store, hash-verified

19);
20
21export function PromptElement(props: Partial<ModalProps>): ReactElement | null {
22 const { prompt } = usePrompt();
23 const confirmingPrompt = useRef<typeof prompt>(null);
24 const [isConfirming, setIsConfirming] = useState(false);
25
26 if (!prompt || !prompt.options) {
27 return null;
28 }
29 const { onError, onFail, onSuccess } = prompt;
30 const { options } = prompt;
31 const {
32 title,
33 description,
34 icon,
35 content,
36 onConfirm,
37 promptSize = Modal.Size.Small,
38 cancelButton = {},
39 okButton = {},
40 className = {},
41 shouldCloseOnOverlayClick,
42 } = options;
43 const isPending = isConfirming && confirmingPrompt.current === prompt;
44 const handleFail = () => {
45 confirmingPrompt.current = null;
46 setIsConfirming(false);
47 onFail();
48 };
49 const handleSuccess = () => {
50 if (isPending) {
51 return;
52 }
53
54 if (!onConfirm) {
55 onSuccess();
56 return;
57 }
58
59 const settle = (callback: () => void) => {
60 if (confirmingPrompt.current !== prompt) {
61 return;
62 }
63
64 confirmingPrompt.current = null;
65 setIsConfirming(false);
66 callback();
67 };
68
69 confirmingPrompt.current = prompt;
70 setIsConfirming(true);
71 Promise.resolve(onConfirm())
72 .then(() => settle(onSuccess))
73 .catch(() => settle(onError));
74 };
75
76 const cancelButtonProps = cancelButton ?? {};
77 const cancelActionButtonProps = {
78 variant: ButtonVariant.Secondary,

Callers

nothing calls this directly

Calls 1

usePromptFunction · 0.90

Tested by

no test coverage detected