Skip to content

Commit 915bc44

Browse files
committed
Use dialog
1 parent fb3d6d5 commit 915bc44

File tree

1 file changed

+37
-50
lines changed

1 file changed

+37
-50
lines changed

app/src/components/details/scraps/ScrapContextProvider.tsx

+37-50
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useMemo, useState } from "react";
22
import { IScrapEntry, ScrapType } from "../../../serverApi/IScrapEntry";
33
import { useAppContext } from "../../../AppContext";
4-
import { Button } from "@mui/material";
4+
import { Button, Typography } from "@mui/material";
55
import { IUpsertScrapsEntryCommand } from "../../../serverApi/commands/IUpsertScrapsEntryCommand";
66
import { useUpsertEntryMutation } from "../../../serverApi/reactQuery/mutations/useUpsertEntryMutation";
77
import { JournalType } from "../../../serverApi/JournalType";
@@ -18,6 +18,7 @@ import { useDialogContext } from "../../layout/dialogs/DialogContext";
1818
import { IJournal } from "../../../serverApi/IJournal";
1919
import { AddNewScrapStorage } from "./AddNewScrapStorage";
2020
import { IScrapListItem } from "./list/IScrapListItem";
21+
import { DialogFormButtonContainer } from "../../common/FormButtonContainer";
2122

2223
export const ScrapContextProvider: React.FC<{
2324
children: React.ReactNode;
@@ -161,59 +162,45 @@ export const ScrapContextProvider: React.FC<{
161162
genericNotes: string[],
162163
targetType: ScrapType,
163164
) {
164-
setAppAlert({
165-
message: (
166-
<>
167-
<div>
168-
Would you like to change the type? Certain formatting might be lost.
169-
</div>
170-
<div style={{ margin: "8px 0" }}>
171-
<Button
172-
sx={{
173-
color: "common.white",
174-
border: "1px solid white;",
175-
marginRight: "10px",
176-
}}
177-
variant={"outlined"}
178-
onClick={() => {
179-
const newNotes = convertNotesToTargetType(
180-
targetType,
181-
genericNotes,
182-
);
165+
renderDialog({
166+
title: "Are you sure?",
167+
render: (closeDialog) => {
168+
return (
169+
<>
170+
<Typography>
171+
Do you really want to change the type to {targetType}? Certain
172+
formatting might be lost.
173+
</Typography>
183174

184-
setNotes(newNotes);
175+
<DialogFormButtonContainer>
176+
<Button variant={"contained"} onClick={closeDialog}>
177+
No
178+
</Button>
179+
<Button
180+
variant={"outlined"}
181+
onClick={() => {
182+
const newNotes = convertNotesToTargetType(
183+
targetType,
184+
genericNotes,
185+
);
185186

186-
setScrapToRender({
187-
...scrapToRender,
188-
notes: newNotes,
189-
scrapType: targetType,
190-
});
187+
setNotes(newNotes);
191188

192-
setAppAlert(null);
193-
}}
194-
>
195-
YES
196-
</Button>
189+
setScrapToRender({
190+
...scrapToRender,
191+
notes: newNotes,
192+
scrapType: targetType,
193+
});
197194

198-
<Button
199-
sx={{
200-
color: "common.white",
201-
border: "1px solid white;",
202-
paddingRight: "10px",
203-
}}
204-
variant={"outlined"}
205-
onClick={() => {
206-
setAppAlert(null);
207-
}}
208-
>
209-
NO
210-
</Button>
211-
</div>
212-
</>
213-
),
214-
type: "info",
215-
hideDurationSec: 2,
216-
title: "Change scrap type to " + targetType,
195+
closeDialog();
196+
}}
197+
>
198+
Yes, convert to {targetType.toLowerCase()}
199+
</Button>
200+
</DialogFormButtonContainer>
201+
</>
202+
);
203+
},
217204
});
218205
}
219206

0 commit comments

Comments
 (0)