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

Function handleSave

packages/shared/src/components/modals/DirtyFormModal.tsx:27–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25 const [isSaving, setIsSaving] = useState(false);
26
27 const handleSave = async () => {
28 if (isSaving) {
29 return;
30 }
31
32 let result: void | Promise<void>;
33 try {
34 result = onSave();
35 } catch {
36 closeModal();
37 return;
38 }
39
40 // Callers that save synchronously keep the original fire-and-forget close.
41 if (!result || typeof result.then !== 'function') {
42 closeModal();
43 return;
44 }
45
46 setIsSaving(true);
47
48 try {
49 await result;
50 } catch {
51 // The caller owns surfacing the failure; the modal closes either way so
52 // the user lands back on their still-unsaved form.
53 } finally {
54 setIsSaving(false);
55 closeModal();
56 }
57 };
58
59 const handleDiscard = () => {
60 onDiscard();

Callers 1

PreparePageContentFunction · 0.85

Calls 1

onSaveFunction · 0.50

Tested by

no test coverage detected