fixed the Duplicate Bin button in the bin actions by importing the BinDuplication react component from the old frontend
This commit is contained in:
parent
497e81fc4b
commit
441e02f65a
2 changed files with 76 additions and 3 deletions
|
|
@ -24,7 +24,7 @@ import RemoveSelfFromObject from "user/RemoveSelfFromObject";
|
||||||
import ShareObject from "user/ShareObject";
|
import ShareObject from "user/ShareObject";
|
||||||
import { isOffline } from "utils/environment";
|
import { isOffline } from "utils/environment";
|
||||||
import ObjectTeams from "teams/ObjectTeams";
|
import ObjectTeams from "teams/ObjectTeams";
|
||||||
// import BinDuplication from "./BinDuplication";
|
import BinDuplication from "./BinDuplication";
|
||||||
import BinsIcon from "products/Bindapt/BinsIcon";
|
import BinsIcon from "products/Bindapt/BinsIcon";
|
||||||
import HelpIcon from "@mui/icons-material/Help";
|
import HelpIcon from "@mui/icons-material/Help";
|
||||||
import BinSensors from "./BinSensors";
|
import BinSensors from "./BinSensors";
|
||||||
|
|
@ -166,6 +166,7 @@ export default function BinActions(props: Props) {
|
||||||
<MenuItem
|
<MenuItem
|
||||||
dense
|
dense
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
console.log("duplicate")
|
||||||
setOpenState({ ...openState, duplication: true });
|
setOpenState({ ...openState, duplication: true });
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
}}
|
}}
|
||||||
|
|
@ -269,14 +270,14 @@ export default function BinActions(props: Props) {
|
||||||
closeDialogCallback={() => setOpenState({ ...openState, users: false })}
|
closeDialogCallback={() => setOpenState({ ...openState, users: false })}
|
||||||
refreshCallback={refreshCallback}
|
refreshCallback={refreshCallback}
|
||||||
/>
|
/>
|
||||||
{/* <BinDuplication
|
<BinDuplication
|
||||||
open={openState.duplication}
|
open={openState.duplication}
|
||||||
closeDialog={() => {
|
closeDialog={() => {
|
||||||
setOpenState({ ...openState, duplication: false });
|
setOpenState({ ...openState, duplication: false });
|
||||||
}}
|
}}
|
||||||
bin={bin}
|
bin={bin}
|
||||||
refreshCallback={refreshCallback}
|
refreshCallback={refreshCallback}
|
||||||
/> */}
|
/>
|
||||||
<RemoveSelfFromObject
|
<RemoveSelfFromObject
|
||||||
scope={binScope(key)}
|
scope={binScope(key)}
|
||||||
label={label}
|
label={label}
|
||||||
|
|
|
||||||
72
src/bin/BinDuplication.tsx
Normal file
72
src/bin/BinDuplication.tsx
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
DialogActions,
|
||||||
|
DialogContent,
|
||||||
|
DialogTitle,
|
||||||
|
TextField,
|
||||||
|
Typography
|
||||||
|
} from "@mui/material";
|
||||||
|
import ResponsiveDialog from "common/ResponsiveDialog";
|
||||||
|
import { Bin } from "models";
|
||||||
|
import { useBinAPI, useSnackbar } from "providers";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
open: boolean;
|
||||||
|
bin: Bin;
|
||||||
|
closeDialog: () => void;
|
||||||
|
refreshCallback: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function BinDuplication(props: Props) {
|
||||||
|
const { open, bin, closeDialog, refreshCallback } = props;
|
||||||
|
const [binDupName, setBinDupName] = useState("(copy of) " + bin.name());
|
||||||
|
const binAPI = useBinAPI();
|
||||||
|
const { openSnack } = useSnackbar();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setBinDupName("(copy of) " + bin.name());
|
||||||
|
}, [bin]);
|
||||||
|
|
||||||
|
const duplicate = () => {
|
||||||
|
let settings = bin.settings;
|
||||||
|
settings.name = binDupName;
|
||||||
|
binAPI
|
||||||
|
.addBin(settings)
|
||||||
|
.then(resp => {
|
||||||
|
openSnack("Successfully duplicated bin");
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
openSnack("Failed to duplicate bin");
|
||||||
|
});
|
||||||
|
refreshCallback();
|
||||||
|
closeDialog();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ResponsiveDialog open={open} onClose={closeDialog}>
|
||||||
|
<DialogTitle>Create Duplicate Bin</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<Typography>
|
||||||
|
This will create a new bin with the same settings as {bin.name()}.
|
||||||
|
</Typography>
|
||||||
|
<TextField
|
||||||
|
id={"duplicateName"}
|
||||||
|
fullWidth
|
||||||
|
margin="normal"
|
||||||
|
label="Name of Copy"
|
||||||
|
value={binDupName}
|
||||||
|
onChange={e => setBinDupName(e.target.value)}
|
||||||
|
/>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<Button onClick={closeDialog} style={{ color: "red" }}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button onClick={duplicate} color="primary">
|
||||||
|
Confirm
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</ResponsiveDialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue