-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
169 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
ui2/src/features/document/components/TransferPagesModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import Error from "@/components/Error" | ||
import PanelContext from "@/contexts/PanelContext" | ||
import {useMovePagesMutation} from "@/features/document/apiSlice" | ||
import {Button, ComboboxItem, Group, Loader, Modal, Select} from "@mantine/core" | ||
import {useContext, useState} from "react" | ||
|
||
import type {DocumentType, PanelMode, TransferStrategyType} from "@/types" | ||
|
||
interface Args { | ||
sourceDocID?: string | ||
targetDoc?: DocumentType | ||
sourcePageIDs?: string[] | ||
targetPageID: string | ||
opened: boolean | ||
onCancel: () => void | ||
onSubmit: () => void | ||
} | ||
|
||
export default function TransferPagesModal({ | ||
opened, | ||
onCancel, | ||
onSubmit, | ||
sourceDocID, | ||
targetDoc, | ||
targetPageID, | ||
sourcePageIDs | ||
}: Args) { | ||
const [value, setValue] = useState<ComboboxItem | null>(null) | ||
const [error, setError] = useState("") | ||
const mode: PanelMode = useContext(PanelContext) | ||
const [movePages, {isLoading}] = useMovePagesMutation() | ||
|
||
if (!sourceDocID) { | ||
return <></> | ||
} | ||
|
||
if (!targetDoc) { | ||
return <></> | ||
} | ||
|
||
if (!sourcePageIDs || sourcePageIDs.length == 0) { | ||
console.warn("Missing source page IDs") | ||
return <></> | ||
} | ||
|
||
const onTransferPages = async () => { | ||
const transferStrategy = (value?.value || "mix") as TransferStrategyType | ||
debugger | ||
const data = { | ||
body: { | ||
source_pages_ids: sourcePageIDs, | ||
target_page_id: targetPageID, | ||
move_strategy: transferStrategy | ||
}, | ||
sourceDocID: sourceDocID, | ||
targetDocID: targetDoc.id | ||
} | ||
try { | ||
await movePages(data) | ||
onSubmit() | ||
reset() | ||
} catch (error: unknown) { | ||
// @ts-ignore | ||
setError(err.data.detail) | ||
} | ||
} | ||
|
||
const reset = () => { | ||
setError("") | ||
} | ||
|
||
return ( | ||
<Modal title={"Transfer Selected Pages"} opened={opened} onClose={onCancel}> | ||
Do you want to transfer selected pages to | ||
{targetDoc.title}? | ||
<Select | ||
data={[ | ||
{value: "mix", label: "Mix"}, | ||
{value: "replace", label: "Replace"} | ||
]} | ||
label="Strategy" | ||
value={value ? value.value : "mix"} | ||
onChange={(_value, option) => setValue(option)} | ||
/> | ||
{error && <Error message={error} />} | ||
<Group justify="space-between" mt="md"> | ||
<Button variant="default" onClick={onCancel}> | ||
Cancel | ||
</Button> | ||
<Group> | ||
{isLoading && <Loader size="sm" />} | ||
<Button disabled={isLoading} onClick={onTransferPages}> | ||
Yes, transfer | ||
</Button> | ||
</Group> | ||
</Group> | ||
</Modal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -356,3 +356,5 @@ export type Coord = { | |
x: number | ||
y: number | ||
} | ||
|
||
export type TransferStrategyType = "mix" | "replace" |