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

Function useAuthForms

packages/shared/src/hooks/useAuthForms.ts:33–64  ·  view source on GitHub ↗
({ onDiscard }: UseAuthFormsProps = {})

Source from the content-addressed store, hash-verified

31};
32
33const useAuthForms = ({ onDiscard }: UseAuthFormsProps = {}): UseAuthForms => {
34 const [container, setContainer] = useState<HTMLDivElement>();
35 const { showPrompt } = usePrompt();
36 const formRef = useRef<HTMLFormElement>();
37
38 const openPrompt = async (
39 e: React.MouseEvent | React.KeyboardEvent | React.FormEvent,
40 ) => {
41 if (await showPrompt(promptOptions)) {
42 onDiscard(e);
43 }
44 };
45
46 const onDiscardAttempt: CloseAuthModalFunc = (e, forceClose = false) => {
47 if (forceClose || !formRef?.current) {
48 return onDiscard(e, forceClose);
49 }
50 return openPrompt(e);
51 };
52
53 return useMemo(
54 () => ({
55 onDiscardAttempt,
56 onContainerChange: setContainer,
57 container,
58 formRef,
59 }),
60 // @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM
61 // eslint-disable-next-line react-hooks/exhaustive-deps
62 [formRef?.current, container, onDiscard],
63 );
64};
65
66export default useAuthForms;

Callers 3

AuthModalFunction · 0.85
OrganizationLayoutFunction · 0.85
SettingsLayoutFunction · 0.85

Calls 1

usePromptFunction · 0.90

Tested by

no test coverage detected